Lightsaber Escape QR Code Display

Adds a QR Code of the "lightsaber URL" to the front page of Lightsaber Escape

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name          Lightsaber Escape QR Code Display
// @namespace     DoomTay
// @description   Adds a QR Code of the "lightsaber URL" to the front page of Lightsaber Escape
// @version       1.2.0
// @include       https://lightsaber.withgoogle.com/
// @grant         GM_xmlhttpRequest

// ==/UserScript==

var observer = new MutationObserver(function(mutations) {
	mutations.forEach(function(mutation) {
		var lightsaberURL = "";
		if(mutation.type == "characterData" && mutation.target.parentNode.id == "url") lightsaberURL = mutation.target.textContent;
		else if(mutation.type == "childList" && mutation.target.id == "url" && Array.prototype.some.call(mutation.addedNodes,node => node.textContent.includes("g.co"))) lightsaberURL = Array.prototype.find.call(mutation.addedNodes,node => node.textContent.includes("g.co")).textContent;
		if(lightsaberURL)
		{
			observer.disconnect();
			//Using GM_xmlhttpRequest because this site doesn't like off-domain images
			GM_xmlhttpRequest({
				method: "GET",
				url: "https://chart.googleapis.com/chart?chs=120x120&cht=qr&chl=" + lightsaberURL + "&chld=L|1&choe=UTF-8",
				overrideMimeType: "text/plain; charset=x-user-defined",
				onload: function(response) {
					var QRCode = new Image();
					QRCode.id = "LSCode";
					
					var arr = Uint8Array.from(response.responseText,thing => thing.charCodeAt(0) & 0xFF);
					var imageData = new Blob([arr.buffer],{type:"image/png"});
					QRCode.src = window.URL.createObjectURL(imageData);
					document.getElementsByClassName("centered")[0].insertBefore(QRCode,document.getElementsByClassName("connection-url-wrapper style-scope sw-page-landing")[0]);
					QRCode.style.position = "absolute";
					if(innerHeight >= 1024)
					{
						QRCode.style.left = "45%";
						QRCode.style.bottom = "-35px";
					}
					else
					{
						QRCode.style.left = "75%";
						QRCode.style.bottom = "150px";
					}
				}
			});
		}
	});
});
var config = { attributes: true, childList: true, characterData: true, subtree: true };
observer.observe(document.getElementById("app"), config);