Skip to content

Instantly share code, notes, and snippets.

@ipid
Created October 17, 2022 04:41
Show Gist options
  • Save ipid/31b579361fb4f53adc39c10fd45c69d6 to your computer and use it in GitHub Desktop.
Save ipid/31b579361fb4f53adc39c10fd45c69d6 to your computer and use it in GitHub Desktop.
用于绕过复制限制的用户脚本。
// ==UserScript==
// @name 反防复制 + 反监控页面切换
// @namespace https://ipidkun.com
// @version 0.1
// @description 用于绕过复制限制的用户脚本。
// @author ipid
// @include *
// @grant none
// @run-at document-start
// ==/UserScript==
(function () {
'use strict'
const banned = new Set([
'copy', 'cut', 'select', 'selectstart', 'selectionchange', 'unload', 'beforeunload',
'keypress', 'keyup', 'keydown', 'pagehide', 'blur',
])
const once = new Set([
'visibilitychange'
])
const originalAddEventListener = EventTarget.prototype.addEventListener
EventTarget.prototype.addEventListener = function (type, handler, arg3) {
if (banned.has(type)) {
return
}
if (once.has(type)) {
let first = true
const newHandler = function (...args) {
if (first) {
first = false
return handler.apply(this, args)
}
}
return originalAddEventListener.call(this, type, newHandler, arg3)
}
return originalAddEventListener.call(this, type, handler, arg3)
}
Object.defineProperty(document, 'visibilityState', {
get() {
return 'visible'
},
configurable: false,
enumerable: false,
})
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment