reddit: sabotage event tracker

Blocks the reddit event collector

目前为 2018-04-29 提交的版本。查看 最新版本

// ==UserScript==
// @name         reddit: sabotage event tracker
// @namespace    mz1js5x0yt0zxq1kf22z1wdn6zq2ij2g
// @version      1.1
// @description  Blocks the reddit event collector
// @license      MIT
// @match        *://*.reddit.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
	"use strict";

	var realSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader;
	var realSend             = XMLHttpRequest.prototype.send;

	var defineProp = Reflect.defineProperty.bind(Reflect);

	var sigHeaderDetected = Symbol();


	// Hook this function to see if the suspect header is being set
	XMLHttpRequest.prototype.setRequestHeader = function setRequestHeader(header, value) {
		// If not already tagged, check the header.
		if (!(sigHeaderDetected in this)) {
			var foundHeader = false;
			header = String(header).toLowerCase();

			if (header.startsWith("x-signature")) {
				foundHeader = true;
			} else if (window.r && r.config) {
				if ((r.config.signature_header    && String(r.config.signature_header).toLowerCase()    === header) ||
					(r.config.signature_header_v2 && String(r.config.signature_header_v2).toLowerCase() === header)
				) {
					foundHeader = true;
				}
			}

			// Tag this object so we can block the send() call later
			if (foundHeader) {
				defineProp(this, sigHeaderDetected, {
					enumerable: false,
					configurable: false,
					writable: false,
					value: true
				});
			}
		}

		return realSetRequestHeader.apply(this, arguments);
	};


	// Only allow sending if we did not detect the signature header
	XMLHttpRequest.prototype.send = function send(body) {
		if (sigHeaderDetected in this) {
			// nope
			this.abort();
		} else {
			return realSend.apply(this, arguments);
		}
	};
})();

QingJ © 2025

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