_Replace evil Javascript

remove evil script

目前為 2015-11-29 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name _Replace evil Javascript
  3. // @include *rcs-rds.ro*
  4. // @description remove evil script
  5. // @version 1.0
  6. // @run-at document-start
  7. // @namespace https://gf.qytechs.cn/users/10606
  8. // ==/UserScript==
  9.  
  10. /****** New "init" function that we will use
  11. instead of the old, bad "init" function.
  12. */
  13.  
  14. /*--- Check for bad scripts to intercept and specify any actions to take.
  15. */
  16. function init () {
  17. }
  18.  
  19. checkForBadJavascripts ( [
  20. [false, /4g/, function () {addJS_Node (init);} ],
  21. [true, /4g/i, null ]
  22. ] );
  23.  
  24. function checkForBadJavascripts (controlArray) {
  25. /*--- Note that this is a self-initializing function. The controlArray
  26. parameter is only active for the FIRST call. After that, it is an
  27. event listener.
  28.  
  29. The control array row is defines like so:
  30. [bSearchSrcAttr, identifyingRegex, callbackFunction]
  31. Where:
  32. bSearchSrcAttr True to search the SRC attribute of a script tag
  33. false to search the TEXT content of a script tag.
  34. identifyingRegex A valid regular expression that should be unique
  35. to that particular script tag.
  36. callbackFunction An optional function to execute when the script is
  37. found. Use null if not needed.
  38. */
  39. if ( ! controlArray.length) return null;
  40.  
  41. checkForBadJavascripts = function (zEvent) {
  42.  
  43. for (var J = controlArray.length - 1; J >= 0; --J) {
  44. var bSearchSrcAttr = controlArray[J][0];
  45. var identifyingRegex = controlArray[J][1];
  46.  
  47. if (bSearchSrcAttr) {
  48. if (identifyingRegex.test (zEvent.target.src) ) {
  49. stopBadJavascript (J);
  50. return false;
  51. }
  52. }
  53. else {
  54. if (identifyingRegex.test (zEvent.target.textContent) ) {
  55. stopBadJavascript (J);
  56. return false;
  57. }
  58. }
  59. }
  60.  
  61. function stopBadJavascript (controlIndex) {
  62. zEvent.stopPropagation ();
  63. zEvent.preventDefault ();
  64.  
  65. var callbackFunction = controlArray[J][2];
  66. if (typeof callbackFunction == "function")
  67. callbackFunction ();
  68.  
  69. //--- Remove the node just to clear clutter from Firebug inspection.
  70. zEvent.target.parentNode.removeChild (zEvent.target);
  71.  
  72. //--- Script is intercepted, remove it from the list.
  73. controlArray.splice (J, 1);
  74. if ( ! controlArray.length) {
  75. //--- All done, remove the listener.
  76. window.removeEventListener (
  77. 'beforescriptexecute', checkForBadJavascripts, true
  78. );
  79. }
  80. }
  81. }
  82.  
  83. /*--- Use the "beforescriptexecute" event to monitor scipts as they are loaded.
  84. See https://developer.mozilla.org/en/DOM/element.onbeforescriptexecute
  85. Note that it does not work on acripts that are dynamically created.
  86. */
  87. window.addEventListener ('beforescriptexecute', checkForBadJavascripts, true);
  88.  
  89. return checkForBadJavascripts;
  90. }
  91.  
  92. function addJS_Node (text, s_URL, funcToRun) {
  93. var D = document;
  94. var scriptNode = D.createElement ('script');
  95. scriptNode.type = "text/javascript";
  96. if (text) scriptNode.textContent = text;
  97. if (s_URL) scriptNode.src = s_URL;
  98. if (funcToRun) scriptNode.textContent = '(' + funcToRun.toString() + ')()';
  99.  
  100. var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
  101. //--- Don't error check here. if DOM not available, should throw error.
  102. targ.appendChild (scriptNode);
  103. }

QingJ © 2025

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