Skip to content

Instantly share code, notes, and snippets.

@ramesaliyev
Last active October 28, 2020 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramesaliyev/13a710f602cfb922d05bef940be3ac31 to your computer and use it in GitHub Desktop.
Save ramesaliyev/13a710f602cfb922d05bef940be3ac31 to your computer and use it in GitHub Desktop.
[YETER] When everything starts bothering you, yeter is yeter.
// When everything starts bothering you, yeter is yeter.
// to contribute
// https://gist.github.com/ramesaliyev/13a710f602cfb922d05bef940be3ac31
// to use
// https://kes.im/yeterjs
// in html:
// <script src="https://kes.im/yeterjs"></script>
// injection code:
// ((d, s)=>{d.head.appendChild(s = d.createElement('script'), s.src=`https://kes.im/yeterjs?v=${Date.now()}`, s)})(document);
// add to bookmarks (load only);
// javascript:((d, s)=>{d.head.appendChild(s = d.createElement('script'), s.src=`https://kes.im/yeterjs?v=${Date.now()}`, s)})(document);
// add to bookmarks (auto-fix everything)
// javascript:((d, s)=>{d.head.appendChild(s = d.createElement('script'), s.onload = ()=>yeter.fixEverything(), s.src=`https://kes.im/yeterjs?v=${Date.now()}`, s)})(document);
{
const build = 10;
function log (text) {
console.log(`[YETER] ${text}`);
}
function load(url) {
return new Promise((resolve, reject) => {
const script = document.createElement('script');
script.onload = resolve;
script.onerror = err => reject(err);
script.src = url;
document.head.appendChild(script);
});
}
function style(CSS) {
const styl = document.createElement('style');
styl.innerText = CSS;
document.head.appendChild(styl);
}
function fixUserSelection() {
style(`
::selection {
color: black !important;
background: yellow !important;
}`
);
}
function fixRightClick(aggressive=false) {
enableContextMenu(aggressive);
}
function fixEverything() {
fixUserSelection();
fixRightClick();
}
window.yeter = {
load,
build,
style,
fixUserSelection,
fixRightClick,
fixEverything,
};
log(`Yeter.js is here to help you. [v${build}]`);
// third party
function enableContextMenu(aggressive = false) { void(document.ondragstart=null); void(document.onselectstart=null); void(document.onclick=null); void(document.onmousedown=null); void(document.onmouseup=null); void(document.body.oncontextmenu=null); enableRightClickLight(document); if (aggressive) { enableRightClick(document); removeContextMenuOnAll("body"); removeContextMenuOnAll("img"); removeContextMenuOnAll("td"); } } function removeContextMenuOnAll(tagName) { var elements = document.getElementsByTagName(tagName); for (var i = 0; i < elements.length; i++) { enableRightClick(elements[i]); } } function enableRightClickLight(el) { el || (el = document); el.addEventListener("contextmenu", bringBackDefault, true); } function enableRightClick(el) { el || (el = document); el.addEventListener("contextmenu", bringBackDefault, true); el.addEventListener("dragstart", bringBackDefault, true); el.addEventListener("selectstart", bringBackDefault, true); el.addEventListener("click", bringBackDefault, true); el.addEventListener("mousedown", bringBackDefault, true); el.addEventListener("mouseup", bringBackDefault, true); } function restoreRightClick(el) { el || (el = document); el.removeEventListener("contextmenu", bringBackDefault, true); el.removeEventListener("dragstart", bringBackDefault, true); el.removeEventListener("selectstart", bringBackDefault, true); el.removeEventListener("click", bringBackDefault, true); el.removeEventListener("mousedown", bringBackDefault, true); el.removeEventListener("mouseup", bringBackDefault, true); } function bringBackDefault(event) { event.returnValue = true; (typeof event.stopPropagation === 'function') && event.stopPropagation(); (typeof event.cancelBubble === 'function') && event.cancelBubble(); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment