Universal Select-click-copy Enabler

Enables select, right-click, copy and drag on pages that disable them.

目前为 2021-06-06 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Universal Select-click-copy Enabler
  3. // @version 1.2.1
  4. // @description Enables select, right-click, copy and drag on pages that disable them.
  5. // @include /^https?\:\/\//
  6. // @grant none
  7. // @run-at document-start
  8. // @namespace https://gf.qytechs.cn/users/371179
  9. // ==/UserScript==
  10.  
  11. "use strict";
  12. (function() {
  13. var mKey = 'dqzadwpujtct';
  14. var enabledSCC = 'enabledSCC_' + mKey;
  15. var nonFalseFunc = 'nff_' + mKey;
  16. var wasRun = false;
  17.  
  18. var cssStyle = '*, body *, div, span, body *::before, body *::after, *:hover, *:link, *:visited, *:active {' +
  19. '-webkit-touch-callout: text !important; -webkit-user-select: text !important; ' +
  20. '-khtml-user-select: text !important; -moz-user-select: text !important; ' +
  21. '-ms-user-select: text !important; user-select: text !important;}';
  22.  
  23. function enableSelectClickCopy() {
  24.  
  25. if (window[enabledSCC]) return;
  26. window[enabledSCC] = true;
  27.  
  28. Event.prototype.preventDefault = (function(f) {
  29. var eys = ['copy', 'contextmenu', 'select', 'selectstart', 'dragstart', 'onbeforecopy'];
  30. return function() {
  31. if (eys.indexOf(this.type) >= 0) return;
  32. return f.apply(this);
  33. }
  34. })(Event.prototype.preventDefault);
  35.  
  36. var ezs = ['copy', 'contextmenu', 'select', 'selectstart', 'dragstart', 'beforecopy'];
  37. var eventsCount = ezs.length;
  38.  
  39. function universaler(originalFunc) {
  40. return function wrapFunction(ev) {
  41. var pName = 'on' + ev.type;
  42. var func = this[pName];
  43. if (typeof func == 'function' && func.name == 'wrapFunction') {
  44. var res = originalFunc.apply(this, arguments);
  45. if (res !== false) {
  46. originalFunc[nonFalseFunc] = true;
  47. this[pName] = originalFunc;
  48. return res;
  49. }
  50. }
  51. }
  52. }
  53.  
  54. function disableAll(event) {
  55. var elmNode = event.target
  56. while (elmNode && elmNode.nodeType > 0) {
  57. var pName = 'on' + event.type
  58. var f = elmNode[pName];
  59. if (f && f[nonFalseFunc] !== true) {
  60. var nf = universaler(f);
  61. nf[nonFalseFunc] = true;
  62. elmNode[pName] = nf;
  63. }
  64. elmNode = elmNode.parentNode;
  65. }
  66. }
  67.  
  68.  
  69. for (var i = 0; i < eventsCount; i++) {
  70. var event = ezs[i];
  71. document.addEventListener(event, disableAll, true);
  72. }
  73.  
  74.  
  75. }
  76.  
  77. function loadedHandler() {
  78. if (wasRun) return;
  79. wasRun = true;
  80. console.log("Select-click-copy Enabler");
  81. try {
  82. document.removeEventListener('beforescriptexecute', loadedHandler, true);
  83. document.removeEventListener('beforeload', loadedHandler, true);
  84. document.removeEventListener('DOMContentLoaded', loadedHandler, true);
  85. } catch (e) {} finally {
  86. appendScript(document);
  87. }
  88. }
  89.  
  90. function isDocumentObj(x) {
  91. return x && x.nodeType == 9
  92. }
  93.  
  94.  
  95. function isHTMLElementObj(x) {
  96. return x && x.nodeType == 1
  97. }
  98.  
  99. function makeScriptElm(documentObject) {
  100. if (!isDocumentObj(documentObject)) return null;
  101. var s = documentObject.createElement('script');
  102. s.type = 'text/javascript';
  103. s.innerHTML = '(' + enableSelectClickCopy.toString() + ')()';
  104. return s
  105. }
  106.  
  107. function appendScript(documentObject) {
  108. try {
  109. if (!isDocumentObj(documentObject)) return;
  110. var container = documentObject.head || documentObject.body;
  111. if (container) container.appendChild(makeScriptElm(documentObject));
  112. } catch (e) {}
  113. }
  114.  
  115.  
  116. function appendCssEnabler(container) {
  117. if (!isHTMLElementObj(container)) return;
  118. try {
  119. var css = document.createElement('style');
  120. css.type = 'text/css';
  121. css.innerHTML = cssStyle;
  122. container.appendChild(css);
  123. } catch (e) {}
  124. }
  125.  
  126. wasRun = false;
  127.  
  128. if (document != null) {
  129.  
  130. enableSelectClickCopy(); //try direct call
  131.  
  132. try {
  133. if ('onbeforescriptexecute' in document) {
  134. //for firefox
  135. document.addEventListener('beforescriptexecute', loadedHandler, true);
  136. } else {
  137. //for chrome and opera
  138. document.addEventListener('beforeload', loadedHandler, true);
  139. }
  140.  
  141. } catch (e) {}
  142.  
  143. document.addEventListener('DOMContentLoaded', function() {
  144. //in case all previous efforts fail
  145. loadedHandler();
  146. appendCssEnabler(document.documentElement || document.body);
  147. }, true);
  148. }
  149. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址