Darude - Sandstorm

Replaces all videos with "Darude - Sandstorm"

This script is marked as "broken" and is likely not working
Details: A change on YT broke this and there is no intention to update the script anymore.
This script is marked as "external"
This script was commisioned by someone else, and I will not check if it works. If it breaks, contact me
Click here to install Browse More Scripts
// ==UserScript==
// @name         Darude - Sandstorm
// @namespace    1baa38fdc31738811f9f4217bff905cd17f718ff
// @version      0.2
// @description  Replaces all videos with "Darude - Sandstorm"
// @author       AyrA
// @match        https://*.youtube.com/*
// @grant        none
// @run-at       document-start
// @external     true
// @expired      true
// @broken       A change on YT broke this and there is no intention to update the script anymore.
// ==/UserScript==

// Changelog
// 0.2 - change "run-at" directive
// 0.1 - Initial version


(function () {
	//links to the sandstorm video and overlay
	var url = "https://master.ayra.ch/yt/sandstorm.mp4";
	var img = "https://master.ayra.ch/yt/sandstorm.png";

	//If you set this to true, it will replace most text content with "Darude - Sandstorm"
	var replaceText = !!localStorage.getItem("darudeText");
	//If you set this to true, it will replace most images with the Video thumbnail
	var replaceImg = !!localStorage.getItem("darudeImg");

	//Overwrite how the "createObjectURL" function works
	var origCreate = URL.createObjectURL;
	URL.createObjectURL = function (a) {
		//If a media stream blob URL is requested, return sandstorm.mp4 instead
		if (a instanceof MediaSource) {
			return url;
		}
		//Return original requested item.
		return origCreate(a);
	};

	//override setAttribute
	var set = Element.prototype.setAttribute;
	Element.prototype.setAttribute = function (a, b) {
		//check if video element for sandstorm.mp4
		if (this.nodeName == "VIDEO" && a.toLowerCase() == "src" && b != url && this.src != url) {
			//set sandstorm url
			console.info("SANDSTORM!");
			this.src = url;
			this.currentTime = 0;
			//prevent any changes to src in the future and just reset the time instead.
			this.__defineSetter__("src", function () {
				this.currentTime = 0;
			});
		} else {
			set.bind(this)(a, b);
		}
	};

	if (replaceText) {
		//Text in these nodes is replaced
		var nodes = ["DIV", "P", "SPAN", "B", "I", "A", "H1", "H2", "H3", "H4", "H5", "H6"];
		var updateNode = function (n, force) {
			if (typeof(n) == typeof("")) {
				return;
			}
			//make sure the node does not contains additional HTML content
			if (n && n.nodeName && n.innerHTML && n.innerHTML.indexOf("<") < 0 &&
				(n.innerText.length > 5 || force) &&
				nodes.indexOf(n.nodeName) >= 0) {
				n.innerText = "Darude - Sandstorm";
			}
		};

		window.addEventListener("DOMContentLoaded", function () {
			var qq = document.getElementsByTagName("*");
			for (var i = 0; i < qq.length; i++) {
				updateNode(qq[i], false);
			}
			document.addEventListener("DOMNodeInserted", function (e) {
				updateNode(e.target, true);
			}, false);
		});
	}
	//Search for img tags, replace the image and lock them by disabling the "src" setter.
	if (replaceImg) {
		var updateImg = function (n) {
			if (n && n.nodeName && n.nodeName == "IMG" && n.src != img) {
				n.src = img;
				n.__defineSetter__("src", function () { /*VOID*/
				});

			}
		};
		var procAllImg = function () {
			var qq = document.getElementsByTagName("img");
			for (var i = 0; i < qq.length; i++) {
				updateImg(qq[i]);
			}
		};
		window.addEventListener("DOMContentLoaded", function () {
			procAllImg();
			document.addEventListener("DOMNodeInserted", function (e) {
				updateImg(e.target);
			}, false);
			document.addEventListener("DOMAttrModified", function (e) {
				updateImg(e.target);
			});
		});
		window.setInterval(procAllImg, 1000);
	}
})();

/*
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 98.80.143.34