您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Enables select, right-click, copy and drag on pages that disable them.
当前为
- // ==UserScript==
- // @name Universal Select-click-copy Enabler
- // @version 1.0
- // @description Enables select, right-click, copy and drag on pages that disable them.
- // @include /^https?\:\/\//
- // @grant none
- // @run-at document-start
- // @namespace https://greasyfork.org/users/371179
- // ==/UserScript==
- "use strict";
- (function() {
- var wasRun = false;
- var cssStyle = '*, body *, div, span, body *::before, body *::after, *:hover, *:link, *:visited, *:active {' +
- '-webkit-touch-callout: text !important; -webkit-user-select: text !important; ' +
- '-khtml-user-select: text !important; -moz-user-select: text !important; ' +
- '-ms-user-select: text !important; user-select: text !important;}';
- function enableSelectClickCopy() {
- if (window.enabledSCC367) return;
- window.enabledSCC367 = true;
- Event.prototype.preventDefault = (function(f) {
- var eys = ['copy', 'contextmenu', 'select', 'selectstart', 'dragstart'];
- return function() {
- if (eys.indexOf(this.type) >= 0) return;
- return f.apply(this);
- }
- })(Event.prototype.preventDefault);
- var ezs = ['copy', 'contextmenu', 'select', 'selectstart', 'dragstart'];
- var eventsCount = ezs.length;
- function universaler(originalFunc) {
- return function wrapFunction(ev) {
- var pName = 'on' + ev.type;
- var func = this[pName];
- if (typeof func == 'function' && func.name == 'wrapFunction') {
- var res = originalFunc.apply(this, arguments);
- if (res !== false) {
- originalFunc.scc = true;
- this[pName] = originalFunc;
- return res;
- }
- }
- }
- }
- function disableAll(event) {
- var elmNode = event.target
- while (elmNode && elmNode.nodeType > 0) {
- var pName = 'on' + event.type
- var f = elmNode[pName];
- if (f && f.scc !== true) {
- var nf = universaler(f);
- nf.scc = true;
- elmNode[pName] = nf;
- }
- elmNode = elmNode.parentNode;
- }
- }
- for (var i = 0; i < eventsCount; i++) {
- var event = ezs[i];
- document.addEventListener(event, disableAll, true);
- }
- }
- function loadedHandler() {
- if (wasRun) return;
- wasRun = true;
- console.log("Select-click-copy Enabler");
- try {
- document.removeEventListener('beforescriptexecute', loadedHandler, true);
- document.removeEventListener('beforeload', loadedHandler, true);
- document.removeEventListener('DOMContentLoaded', loadedHandler, true);
- } catch (e) {} finally {
- appendScript(document);
- }
- }
- function isDocumentObj(x) {
- return x && x.nodeType == 9
- }
- function isHTMLElementObj(x) {
- return x && x.nodeType == 1
- }
- function makeScriptElm(documentObject) {
- if (!isDocumentObj(documentObject)) return null;
- var s = documentObject.createElement('script');
- s.type = 'text/javascript';
- s.innerHTML = '(' + enableSelectClickCopy.toString() + ')()';
- return s
- }
- function appendScript(documentObject) {
- try {
- if (!isDocumentObj(documentObject)) return;
- var container = documentObject.head || documentObject.body;
- if (container) container.appendChild(makeScriptElm(documentObject));
- } catch (e) {}
- }
- function appendCssEnabler(container) {
- if (!isHTMLElementObj(container)) return;
- try {
- var css = document.createElement('style');
- css.type = 'text/css';
- css.innerHTML = cssStyle;
- container.appendChild(css);
- } catch (e) {}
- }
- wasRun = false;
- if (document != null) {
- enableSelectClickCopy(); //try direct call
- try {
- if ('onbeforescriptexecute' in document) {
- //for firefox
- document.addEventListener('beforescriptexecute', loadedHandler, true);
- } else {
- //for chrome and opera
- document.addEventListener('beforeload', loadedHandler, true);
- }
- } catch (e) {}
- document.addEventListener('DOMContentLoaded', function() {
- //in case all previous efforts fail
- loadedHandler();
- appendCssEnabler(document.documentElement||document.body);
- }, true);
- }
- })();