Guest User

Untitled

a guest
Apr 29th, 2018
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         reddit: sabotage event tracker
  3. // @namespace    mz1js5x0yt0zxq1kf22z1wdn6zq2ij2g
  4. // @version      1.2
  5. // @description  Blocks the reddit event collector
  6. // @match        *://*.reddit.com/*
  7. // @match        *://reddit.com/*
  8. // @grant        none
  9. // @run-at       document-start
  10. // ==/UserScript==
  11. (function(){
  12.   "use strict";
  13.   var script = function() {
  14.     "use strict";
  15.  
  16.     var realSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader;
  17.     var realSend             = XMLHttpRequest.prototype.send;
  18.  
  19.     var defineProp = Reflect.defineProperty.bind(Reflect);
  20.  
  21.     var sigHeaderDetected = Symbol();
  22.  
  23.  
  24.     // Hook this function to see if the suspect header is being set
  25.     XMLHttpRequest.prototype.setRequestHeader = function setRequestHeader(header, value) {
  26.       // If not already tagged, check the header.
  27.       if (!(sigHeaderDetected in this)) {
  28.         var foundHeader = false;
  29.         header = String(header).toLowerCase();
  30.  
  31.         if (header.startsWith("x-signature")) {
  32.           foundHeader = true;
  33.         } else if (window.r && r.config) {
  34.           if ((r.config.signature_header    && String(r.config.signature_header).toLowerCase()    === header) ||
  35.             (r.config.signature_header_v2 && String(r.config.signature_header_v2).toLowerCase() === header)
  36.           ) {
  37.             foundHeader = true;
  38.           }
  39.         }
  40.  
  41.         // Tag this object so we can block the send() call later
  42.         if (foundHeader) {
  43.           defineProp(this, sigHeaderDetected, {
  44.             enumerable: false,
  45.             configurable: false,
  46.             writable: false,
  47.             value: true
  48.           });
  49.         }
  50.       }
  51.  
  52.       return realSetRequestHeader.apply(this, arguments);
  53.     };
  54.  
  55.  
  56.     // Only allow sending if we did not detect the signature header
  57.     XMLHttpRequest.prototype.send = function send(body) {
  58.       if (sigHeaderDetected in this) {
  59.         // nope
  60.         this.abort();
  61.       } else {
  62.         return realSend.apply(this, arguments);
  63.       }
  64.     };
  65.   };
  66.  
  67.   function injectAndRunFunction(functionRef) {
  68.     var scr = document.createElement('script');
  69.     scr.type="text/javascript";
  70.     scr.innerHTML='(' + functionRef.toString() + ')();';
  71.     document.getElementsByTagName('head')[0].appendChild(scr);
  72.   }
  73.  
  74.     injectAndRunFunction(script);
  75. })();
Advertisement
Add Comment
Please, Sign In to add comment