From 01a64c00c34a8853898fa7bfa53ac1073e6be2e5 Mon Sep 17 00:00:00 2001 From: Play_it <38607319+Playit3110@users.noreply.github.com> Date: Mon, 24 Jul 2023 21:50:23 +0200 Subject: [PATCH 1/2] Rewrite interval loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add better compatibility with cache in Firefox (See Discord place-tech-support - Zinnsoldat stürzt ab (Firefox)) --- src/scripts/placeDE-overlay.user.js | 69 +++++++++++++++-------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/src/scripts/placeDE-overlay.user.js b/src/scripts/placeDE-overlay.user.js index 873f737..624cc38 100644 --- a/src/scripts/placeDE-overlay.user.js +++ b/src/scripts/placeDE-overlay.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name r/placeDE Template // @namespace http://tampermonkey.net/ -// @version 8.7 +// @version 8.8 // @description try to take over the canvas! // @author placeDE Devs // @match https://garlic-bread.reddit.com/embed* @@ -16,41 +16,42 @@ const src = "https://place.army/overlay_target.png"; const style = "position: absolute;left: 0;top: 0;image-rendering: pixelated;width: 1000px;height: 1000px;"; -let overlayImage = null; -if (window.top !== window.self) { - window.addEventListener( - "load", - () => { - const canvasContainer = document - .querySelector("garlic-bread-embed") - .shadowRoot.querySelector("garlic-bread-canvas") - .shadowRoot.querySelector(".container"); - const canvas = canvasContainer.querySelector("canvas"); +var overlayImage = null; +if(window.top !== window.self) { + window.addEventListener("load", () => { + const canvasContainer = document + .querySelector("garlic-bread-embed") + .shadowRoot.querySelector("div.layout").querySelector("garlic-bread-canvas") + .shadowRoot.querySelector("div.container"); + const canvas = canvasContainer.querySelector("canvas"); + overlayImage = document.createElement("img"); + overlayImage.src = src; + overlayImage.style = style; + canvasContainer.appendChild(overlayImage); - overlayImage = document.createElement("img"); - overlayImage.style = style; - - const updateImage = () => (overlayImage.src = src + "?" + Date.now()); - - updateImage(); - setInterval(updateImage, updateEvery); - canvasContainer.appendChild(overlayImage); - - const canvasObserver = new MutationObserver((mutations) => { - mutations.forEach((mutation) => { - if (mutation.type === "attributes") { - overlayImage.style.width = - mutation.target.getAttribute("width") + "px"; - overlayImage.style.height = - mutation.target.getAttribute("height") + "px"; - } - }); + const canvasObserver = new MutationObserver((mutations) => { + mutations.forEach((mutation) => { + if(mutation.type === "attributes") { + overlayImage.style.width = + mutation.target.getAttribute("width") + "px"; + overlayImage.style.height = + mutation.target.getAttribute("height") + "px"; + } }); + }); - canvasObserver.observe(canvas, { - attributes: true, + canvasObserver.observe(canvas, { + attributes: true + }); + + setInterval(() => { + fetch(src) + .then(res => res.blob()) + .then(blob => { + if(overlayImage.src.startsWith("blob")) + URL.revokeObjectURL(overlayImage.src); + overlayImage.src = URL.createObjectURL(blob); }); - }, - false - ); + }, updateEvery); + }, false); } From ec35dd9d3947c367d192f2c20fe68bc6e0dd8a8b Mon Sep 17 00:00:00 2001 From: Play_it <38607319+Playit3110@users.noreply.github.com> Date: Mon, 24 Jul 2023 21:55:50 +0200 Subject: [PATCH 2/2] adjust placeDE-overlay.user.js --- src/scripts/placeDE-overlay.user.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/scripts/placeDE-overlay.user.js b/src/scripts/placeDE-overlay.user.js index 624cc38..e93edc6 100644 --- a/src/scripts/placeDE-overlay.user.js +++ b/src/scripts/placeDE-overlay.user.js @@ -21,9 +21,10 @@ if(window.top !== window.self) { window.addEventListener("load", () => { const canvasContainer = document .querySelector("garlic-bread-embed") - .shadowRoot.querySelector("div.layout").querySelector("garlic-bread-canvas") - .shadowRoot.querySelector("div.container"); + .shadowRoot.querySelector("garlic-bread-canvas") + .shadowRoot.querySelector(".container"); const canvas = canvasContainer.querySelector("canvas"); + overlayImage = document.createElement("img"); overlayImage.src = src; overlayImage.style = style;