photopea.js
· 1.5 KiB · JavaScript
Orginalformat
// ==UserScript==
// @name photopea
// @namespace http://tampermonkey.net/
// @version 0.1
// @author You
// @match https://www.photopea.com/
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @description photopea adblock
// @grant none
// @license MIT
// ==/UserScript==
(function () {
"use strict";
const style = document.createElement("style");
style.textContent = ".app > div:not(:first-child) { visibility: hidden; }";
document.head.appendChild(style);
function addCustomEvent() {
const ADS_WIDTH = 320;
document.addEventListener("resizecanvas", (e) => {
// push the ads container outside of the viewport
window.innerWidth = document.documentElement.clientWidth + ADS_WIDTH;
});
}
// inject our custom event listener into the "main world"
document.documentElement.setAttribute("onreset", `(${addCustomEvent})()`);
document.documentElement.dispatchEvent(new CustomEvent("reset"));
document.documentElement.removeAttribute("onreset");
function resize(event = {}) {
if (!event.skip) {
document.dispatchEvent(new CustomEvent("resizecanvas"));
// trigger another resize event to update any listeners with the new window.innerWidth
const resizeEvent = new Event("resize");
resizeEvent.skip = true;
window.dispatchEvent(resizeEvent);
}
}
let debounce;
window.addEventListener("resize", (event) => {
clearTimeout(debounce);
debounce = setTimeout(() => resize(event), 100);
});
resize();
})();
| 1 | // ==UserScript== |
| 2 | // @name photopea |
| 3 | // @namespace http://tampermonkey.net/ |
| 4 | // @version 0.1 |
| 5 | // @author You |
| 6 | // @match https://www.photopea.com/ |
| 7 | // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== |
| 8 | // @description photopea adblock |
| 9 | // @grant none |
| 10 | // @license MIT |
| 11 | // ==/UserScript== |
| 12 | |
| 13 | (function () { |
| 14 | "use strict"; |
| 15 | |
| 16 | const style = document.createElement("style"); |
| 17 | style.textContent = ".app > div:not(:first-child) { visibility: hidden; }"; |
| 18 | document.head.appendChild(style); |
| 19 | function addCustomEvent() { |
| 20 | const ADS_WIDTH = 320; |
| 21 | document.addEventListener("resizecanvas", (e) => { |
| 22 | // push the ads container outside of the viewport |
| 23 | window.innerWidth = document.documentElement.clientWidth + ADS_WIDTH; |
| 24 | }); |
| 25 | } |
| 26 | // inject our custom event listener into the "main world" |
| 27 | document.documentElement.setAttribute("onreset", `(${addCustomEvent})()`); |
| 28 | document.documentElement.dispatchEvent(new CustomEvent("reset")); |
| 29 | document.documentElement.removeAttribute("onreset"); |
| 30 | function resize(event = {}) { |
| 31 | if (!event.skip) { |
| 32 | document.dispatchEvent(new CustomEvent("resizecanvas")); |
| 33 | // trigger another resize event to update any listeners with the new window.innerWidth |
| 34 | const resizeEvent = new Event("resize"); |
| 35 | resizeEvent.skip = true; |
| 36 | window.dispatchEvent(resizeEvent); |
| 37 | } |
| 38 | } |
| 39 | let debounce; |
| 40 | window.addEventListener("resize", (event) => { |
| 41 | clearTimeout(debounce); |
| 42 | debounce = setTimeout(() => resize(event), 100); |
| 43 | }); |
| 44 | resize(); |
| 45 | })(); |