Forked from elliotberry/no-clipboard-fuckery.user.js
Created
November 27, 2022 17:57
-
-
Save usmanakram232/a1bc1267dff5768c1b5f73d9ca5c2bb8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Fuck with my native clipboard, and find out | |
// @namespace no-clipbiard-fuckery | |
// @description Who cares if password managers are more secure? Making users hate your app is the real security. | |
// @shortcutKeys [Ctrl + `] Activate Absolute Right Click Mode To Force Remove Any Type Of Protection | |
// @author this is stolen | |
// @version 2.0.0 | |
// @include *://* | |
// @grant GM_registerMenuCommand | |
// @updateURL https://get-my-gists.daddy.workers.dev/?gistId=05facb6827406b5a04b5645724b237d4&filename=no-clipboard-fuckery.user.js | |
// @license Unlicense | |
// ==/UserScript== | |
(() => { | |
const css = document.createElement('style'); | |
const head = document.head; | |
css.type = 'text/css'; | |
css.innerText = `* { | |
-webkit-user-select: text !important; | |
-moz-user-select: text !important; | |
-ms-user-select: text !important; | |
user-select: text !important; | |
}`; | |
function main() { | |
const doc = document; | |
const body = document.body; | |
const docEvents = [ | |
doc.oncontextmenu = null, | |
doc.onselectstart = null, | |
doc.ondragstart = null, | |
doc.onmousedown = null | |
]; | |
const bodyEvents = [ | |
body.oncontextmenu = null, | |
body.onselectstart = null, | |
body.ondragstart = null, | |
body.onmousedown = null, | |
body.oncut = null, | |
body.oncopy = null, | |
body.onpaste = null | |
]; | |
[].forEach.call( | |
['copy', 'cut', 'paste', 'select', 'selectstart'], | |
event => { | |
document.addEventListener(event, e => { e.stopPropagation(); }, true); | |
} | |
); | |
alwaysAbsoluteMode(); | |
enableCommandMenu(); | |
head.appendChild(css); | |
document.addEventListener('keydown', keyPress); | |
} | |
function keyPress({ctrlKey, keyCode}) { | |
if (ctrlKey && keyCode == 192) { | |
return confirm('Activate Absolute Right Click Mode!') == true ? absoluteMode() : null; | |
} | |
} | |
function absoluteMode() { | |
[].forEach.call( | |
['contextmenu', 'copy', 'cut', 'paste', 'mouseup', 'mousedown', 'keyup', 'keydown', 'drag', 'dragstart', 'select', 'selectstart'], | |
event => { | |
document.addEventListener(event, e => { e.stopPropagation(); }, true); | |
} | |
); | |
} | |
function alwaysAbsoluteMode() { | |
let sites = ['example.com','www.example.com']; | |
const list = RegExp(sites.join('|')).exec(location.hostname); | |
return list ? absoluteMode() : null; | |
} | |
function enableCommandMenu() { | |
const commandMenu = true; | |
try { | |
if (typeof(GM_registerMenuCommand) == undefined) { | |
return; | |
} else { | |
if (commandMenu == true ) { | |
GM_registerMenuCommand('Enable Right Click', () => { | |
return confirm('Activate Absolute Right Click Mode!') == true ? absoluteMode() : null; | |
}); | |
} | |
} | |
} | |
catch(err) { | |
console.log(err); | |
} | |
} | |
const blackList = [ | |
'youtube.com','.google.','.google.com','greasyfork.org','twitter.com','instagram.com','facebook.com','translate.google.com','.amazon.','.ebay.','github.','stackoverflow.com', | |
'bing.com','live.com','.microsoft.com','dropbox.com','pcloud.com','box.com','sync.com','onedrive.com','mail.ru','deviantart.com','pastebin.com', | |
'dailymotion.com','twitch.tv','spotify.com','steam.com','steampowered.com','gitlab.com','.reddit.com' | |
]; | |
let enabled = false; | |
const url = window.location.hostname; | |
const match = RegExp(blackList.join('|')).exec(url); | |
if (window && typeof window != undefined && head != undefined) { | |
if (!match && enabled != true) { | |
main(); | |
enabled = true | |
window.addEventListener('contextmenu', function contextmenu(event) { | |
event.stopPropagation(); | |
event.stopImmediatePropagation(); | |
const handler = new eventHandler(event); | |
window.removeEventListener(event.type, contextmenu, true); | |
const eventsCallBack = new eventsCall(() => {}); | |
handler.fire(); | |
window.addEventListener(event.type, contextmenu, true); | |
if (handler.isCanceled && (eventsCallBack.isCalled)) { | |
event.preventDefault(); | |
} | |
}, true); | |
} | |
class eventsCall { | |
constructor() { | |
this.events = ['DOMAttrModified', 'DOMNodeInserted', 'DOMNodeRemoved', 'DOMCharacterDataModified', 'DOMSubtreeModified']; | |
this.bind(); | |
} | |
bind() { | |
this.events.forEach(event => { | |
document.addEventListener(event, this, true); | |
}); | |
} | |
handleEvent() { | |
this.isCalled = true; | |
} | |
unbind() { | |
this.events.forEach(event => {}); | |
} | |
} | |
class eventHandler { | |
constructor(event) { | |
this.event = event; | |
this.contextmenuEvent = this.createEvent(this.event.type); | |
} | |
createEvent(type) { | |
const target = this.event.target; | |
const event = target.ownerDocument.createEvent('MouseEvents'); | |
event.initMouseEvent( | |
type, this.event.bubbles, this.event.cancelable, | |
target.ownerDocument.defaultView, this.event.detail, | |
this.event.screenX, this.event.screenY, this.event.clientX, this.event.clientY, | |
this.event.ctrlKey, this.event.altKey, this.event.shiftKey, this.event.metaKey, | |
this.event.button, this.event.relatedTarget | |
); | |
return event; | |
} | |
fire() { | |
const target = this.event.target; | |
const contextmenuHandler = event => { | |
event.preventDefault(); | |
}; | |
target.dispatchEvent(this.contextmenuEvent); | |
this.isCanceled = this.contextmenuEvent.defaultPrevented; | |
} | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment