Last active
January 10, 2023 04:00
-
-
Save Nekoyue/7d4c05cc1573623cdf460e009303b141 to your computer and use it in GitHub Desktop.
This file contains 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 Disable Page Visibility API and Copy-Paste detection | |
// @version 1 | |
// @grant none | |
// @match *://*/* | |
// ==/UserScript== | |
/* Disable Page Visibility API */ | |
/* https://github.com/IceWreck/Page-Visibility-User-Script */ | |
let events_to_block = [ | |
"visibilitychange", | |
"webkitvisibilitychange", | |
"mozvisibilitychange", | |
"hasFocus", | |
"blur", | |
"focus" | |
] | |
for (let event_name of events_to_block) { | |
document.addEventListener(event_name, function (event) { | |
event.preventDefault(); | |
event.stopPropagation(); | |
event.stopImmediatePropagation(); | |
}, true); | |
} | |
for (let event_name of events_to_block) { | |
window.addEventListener(event_name, function (event) { | |
event.preventDefault(); | |
event.stopPropagation(); | |
event.stopImmediatePropagation(); | |
}, true); | |
} | |
document.hasFocus = function () { | |
return true; | |
}; | |
document.onvisibilitychange = null; | |
Object.defineProperty(document, "visibilityState", { value: "visible" }); | |
Object.defineProperty(document, "hidden", { value: false }); | |
Object.defineProperty(document, "mozHidden", { value: false }); | |
Object.defineProperty(document, "webkitHidden", { value: false }); | |
Object.defineProperty(document, "webkitVisibilityState", { value: "visible" }); | |
/* End */ | |
/* Absolute Enable Right Click & Copy */ | |
/* https://greasyfork.org/en/scripts/23772-absolute-enable-right-click-copy/code */ | |
(function () { | |
'use strict'; | |
var css = document.createElement('style'); | |
var 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() { | |
var doc = document; | |
var body = document.body; | |
var docEvents = [ | |
doc.oncontextmenu = null, | |
doc.onselectstart = null, | |
doc.ondragstart = null, | |
doc.onmousedown = null | |
]; | |
var 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'], | |
function (event) { | |
document.addEventListener(event, function (e) { e.stopPropagation(); }, true); | |
} | |
); | |
alwaysAbsoluteMode(); | |
enableCommandMenu(); | |
head.appendChild(css); | |
document.addEventListener('keydown', keyPress); | |
} | |
function keyPress(event) { | |
if (event.ctrlKey && event.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'], | |
function (event) { | |
document.addEventListener(event, function (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() { | |
} | |
var 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' | |
] | |
var enabled = false; | |
var url = window.location.hostname; | |
var match = RegExp(blackList.join('|')).exec(url); | |
if (window && typeof window != undefined && head != undefined) { | |
if (!match && enabled != true) { | |
main(); | |
enabled = true | |
//console.log(location.hostname); | |
window.addEventListener('contextmenu', function contextmenu(event) { | |
event.stopPropagation(); | |
event.stopImmediatePropagation(); | |
var handler = new eventHandler(event); | |
window.removeEventListener(event.type, contextmenu, true); | |
var eventsCallBack = new eventsCall(function () { }); | |
handler.fire(); | |
window.addEventListener(event.type, contextmenu, true); | |
if (handler.isCanceled && (eventsCallBack.isCalled)) { | |
event.preventDefault(); | |
} | |
}, true); | |
} | |
function eventsCall() { | |
this.events = ['DOMAttrModified', 'DOMNodeInserted', 'DOMNodeRemoved', 'DOMCharacterDataModified', 'DOMSubtreeModified']; | |
this.bind(); | |
} | |
eventsCall.prototype.bind = function () { | |
this.events.forEach(function (event) { | |
document.addEventListener(event, this, true); | |
}.bind(this)); | |
}; | |
eventsCall.prototype.handleEvent = function () { | |
this.isCalled = true; | |
}; | |
eventsCall.prototype.unbind = function () { | |
this.events.forEach(function (event) { }.bind(this)); | |
}; | |
function eventHandler(event) { | |
this.event = event; | |
this.contextmenuEvent = this.createEvent(this.event.type); | |
} | |
eventHandler.prototype.createEvent = function (type) { | |
var target = this.event.target; | |
var 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; | |
}; | |
eventHandler.prototype.fire = function () { | |
var target = this.event.target; | |
var contextmenuHandler = function (event) { | |
event.preventDefault(); | |
}.bind(this); | |
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