Menghilangkan Web Limit

Menghilangkan limit pada website yang tidak bisa copy, cut, select the text, right-click menu.

  1. // ==UserScript==
  2. // @namespace http://www.fornesia.com
  3. // @name Menghilangkan Web Limit
  4. // @description Menghilangkan limit pada website yang tidak bisa copy, cut, select the text, right-click menu.
  5. // @homepageURL http://www.fornesia.com
  6. // @supportURL http://www.fornesia.com
  7.  
  8. // @author fornesiafreak
  9. // @version 1.0
  10. // @license LGPLv3
  11. // @compatible chrome Chrome_46.0.2490.86 + TamperMonkey
  12. // @compatible firefox Firefox_42.0 + GreaseMonkey
  13. // @compatible opera Opera_33.0.1990.115 + TamperMonkey
  14. // @compatible safari
  15. // @match *://*/*
  16. // @grant none
  17. // @run-at document-start
  18. // ==/UserScript==
  19. 'use strict';
  20.  
  21. var rules = {
  22. black_rule: {
  23. name: "black",
  24. hook_eventNames: "",
  25. unhook_eventNames: ""
  26. },
  27. default_rule: {
  28. name: "default",
  29. hook_eventNames: "contextmenu|select|selectstart|copy|cut|dragstart",
  30. unhook_eventNames: "mousedown|mouseup|keydown|keyup",
  31. dom0: true,
  32. hook_addEventListener: true,
  33. hook_preventDefault: true,
  34. hook_set_returnValue: true,
  35. add_css: true
  36. }
  37. };
  38.  
  39. var lists = {
  40.  
  41. black_list: [
  42. /.*\.youtube\.com.*/,
  43. /translate\.google\..*/
  44. ]
  45. };
  46.  
  47. var hook_eventNames, unhook_eventNames, eventNames;
  48.  
  49. var storageName = getRandStr('qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM', parseInt(Math.random() * 12 + 8));
  50.  
  51. var EventTarget_addEventListener = EventTarget.prototype.addEventListener;
  52. var document_addEventListener = document.addEventListener;
  53. var Event_preventDefault = Event.prototype.preventDefault;
  54.  
  55. // Hook addEventListener proc
  56. function addEventListener(type, func, useCapture) {
  57. var _addEventListener = this === document ? document_addEventListener : EventTarget_addEventListener;
  58. if(hook_eventNames.indexOf(type) >= 0) {
  59. _addEventListener.apply(this, [type, returnTrue, useCapture]);
  60. } else if(unhook_eventNames.indexOf(type) >= 0) {
  61. var funcsName = storageName + type + (useCapture ? 't' : 'f');
  62.  
  63. if(this[funcsName] === undefined) {
  64. this[funcsName] = [];
  65. _addEventListener.apply(this, [type, useCapture ? unhook_t : unhook_f, useCapture]);
  66. }
  67.  
  68. this[funcsName].push(func)
  69. } else {
  70. _addEventListener.apply(this, arguments);
  71. }
  72. }
  73.  
  74. function clearLoop() {
  75. var elements = getElements();
  76.  
  77. for(var i in elements) {
  78. for(var j in eventNames) {
  79. var name = 'on' + eventNames[j];
  80. if(elements[i][name] != null && elements[i][name] != onxxx) {
  81. if(unhook_eventNames.indexOf(eventNames[j]) >= 0) {
  82. elements[i][storageName + name] = elements[i][name];
  83. elements[i][name] = onxxx;
  84. } else {
  85. elements[i][name] = null;
  86. }
  87. }
  88. }
  89. }
  90. }
  91.  
  92. function returnTrue(e) {
  93. return true;
  94. }
  95. function unhook_t(e) {
  96. return unhook(e, this, storageName + e.type + 't');
  97. }
  98. function unhook_f(e) {
  99. return unhook(e, this, storageName + e.type + 'f');
  100. }
  101. function unhook(e, self, funcsName) {
  102. var list = self[funcsName];
  103. for(var i in list) {
  104. list[i](e);
  105. }
  106.  
  107. e.returnValue = true;
  108. return true;
  109. }
  110. function onxxx(e) {
  111. var name = storageName + 'on' + e.type;
  112. this[name](e);
  113.  
  114. e.returnValue = true;
  115. return true;
  116. }
  117.  
  118. function getRandStr(chs, len) {
  119. var str = '';
  120.  
  121. while(len--) {
  122. str += chs[parseInt(Math.random() * chs.length)];
  123. }
  124.  
  125. return str;
  126. }
  127.  
  128.  
  129. function getElements() {
  130. var elements = Array.prototype.slice.call(document.getElementsByTagName('*'));
  131. elements.push(document);
  132.  
  133. return elements;
  134. }
  135.  
  136. function addStyle(css) {
  137. var style = document.createElement('style');
  138. style.innerHTML = css;
  139. document.head.appendChild(style);
  140. }
  141.  
  142. function getRule(url) {
  143. function testUrl(list, url) {
  144. for(var i in list) {
  145. if(list[i].test(url)) {
  146. return true;
  147. }
  148. }
  149.  
  150. return false;
  151. }
  152.  
  153. if(testUrl(lists.black_list, url)) {
  154. return rules.black_rule;
  155. }
  156.  
  157. return rules.default_rule;
  158. }
  159.  
  160.  
  161. function init() {
  162.  
  163. var url = window.location.host + window.location.pathname;
  164. var rule = getRule(url);
  165.  
  166. hook_eventNames = rule.hook_eventNames.split("|");
  167. // TODO Allowed to return value
  168. unhook_eventNames = rule.unhook_eventNames.split("|");
  169. eventNames = hook_eventNames.concat(unhook_eventNames);
  170.  
  171. if(rule.dom0) {
  172. setInterval(clearLoop, 30 * 1000);
  173. setTimeout(clearLoop, 2500);
  174. window.addEventListener('load', clearLoop, true);
  175. clearLoop();
  176. }
  177.  
  178. // hook addEventListener
  179. if(rule.hook_addEventListener) {
  180. EventTarget.prototype.addEventListener = addEventListener;
  181. document.addEventListener = addEventListener;
  182. }
  183.  
  184. // hook preventDefault
  185. if(rule.hook_preventDefault) {
  186. Event.prototype.preventDefault = function() {
  187. if(eventNames.indexOf(this.type) < 0) {
  188. Event_preventDefault.apply(this, arguments);
  189. }
  190. };
  191. }
  192.  
  193. // Hook set returnValue
  194. if(rule.hook_set_returnValue) {
  195. Event.prototype.__defineSetter__('returnValue', function() {
  196. if(this.returnValue != true && eventNames.indexOf(this.type) >= 0) {
  197. this.returnValue = true;
  198. }
  199. });
  200. }
  201.  
  202. console.debug('url: ' + url, 'storageName:' + storageName, 'rule: ' + rule.name);
  203.  
  204. if(rule.add_css) {
  205. addStyle('html, * {-webkit-user-select:text!important; -moz-user-select:text!important;}');
  206. }
  207. }
  208.  
  209. init();

QingJ © 2025

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