Unworker

Disables background workers

This script is marked as "expired"
Expired scripts may still work but they will not be fixed once they break.
Click here to install Browse More Scripts
// ==UserScript==
// @name         Unworker
// @namespace    fd8995aae39a1de8640e34a63a0ee7790d69f8f5
// @version      0.3
// @description  Disables background workers
// @author       /u/AyrA_ch
// @match        http://*/*
// @match        https://*/*
// @grant        none
// @run-at       document-start
// @expired      true
// ==/UserScript==

// Changelog
// 0.3 - Fix workaround found by my imposter
// 0.2 - Block all 3 types of workers
// 0.1 - Basic version for Workers

(function () {
	'use strict';

	//Prevent restoring of workers
	var origAppend = Node.prototype.appendChild;
	var appender = function (e) {
		//Append element so the contentWindow gets populated
		origAppend.call(this, e);
		if (e && e.tagName === "IFRAME") {
			//Replace workers on iFrame
			replaceWorkers(e.contentWindow);
			//Propagate appender function into iFrame
			e.contentWindow.Node.appendChild = appender;
			console.log("Hijacked workers for iframe");
		}
	};

	Node.prototype.appendChild = appender;

	//Function to replace workers
	var replaceWorkers = function (workerHolder) {

		var nope = function (e) {
			console.error("Prevented running of background script:", e);
			var err = new Error("Failed to load script (nsresult = 0x805303f4)");
			var obj = {
				postMessage: function () {
					if (obj.onerror) {
						obj.onerror({
							error: err,
							preventDefault: function () {}
						});
					} else {
						throw err;
					}
				},
				addEventListener: function (name, func) {
					obj["on" + name] = func;
				}
			};
			window.setInterval(function () {
				if (obj.onerror) {
					obj.onerror({
						error: err,
						preventDefault: function () {}
					});
				}
			}, 50);
			return obj;
		};

		//bind over two levels to restore native function behavior
		workerHolder.Worker = nope.bind(workerHolder).bind(document);
		workerHolder.ServiceWorker = nope.bind(workerHolder).bind(document);
		workerHolder.SharedWorker = nope.bind(workerHolder).bind(document);

		//Prevent scripts from attempting to modify this
		var ua = navigator.userAgent;

		//Firefox adds line breaks. This filters that
		var getRepl = function (x) {
			return ua.indexOf("Firefox/") >= 0 ?
			"function " + x + "() {\n    [native code]\n}" :
			"function " + x + "() { [native Code] }";
		};

		//Prevent primitive detection methods of redirected function
		workerHolder.Worker.toString = (function () {
			return getRepl("Worker");
		}).bind(workerHolder.Worker);
		workerHolder.ServiceWorker.toString = (function () {
			return getRepl("ServiceWorker");
		}).bind(workerHolder.ServiceWorker);
		workerHolder.SharedWorker.toString = (function () {
			return getRepl("SharedWorker");
		}).bind(workerHolder.SharedWorker);

	};

	replaceWorkers(window);
	console.info("Web workers hijacked");
})();

/*
LICENSE:
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
The full license text can be found here: http://creativecommons.org/licenses/by-nc-sa/4.0/
The link has an easy to understand version of the license and the full license text.

DISCLAIMER:
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
*/

Copyright © 2018 by Kevin Gut 📧 | More services | Generated for 3.138.105.31