Greasy Fork

Greasy Fork is available in English.

Photopea: prevent adblocker dialog spam

Prevent window.dialog spam when using adblockers

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Photopea: prevent adblocker dialog spam
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Prevent window.dialog spam when using adblockers
// @author       Vassildador
// @match        https://www.photopea.com/
// @icon         https://www.google.com/s2/favicons?domain=photopea.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Override window.fetch to make the adsbygoogle.js call always "succeed", without actually loading the script.
    // Photopea checks if this call fails to load their window.confirm spam
    const f = window.fetch;
    window.fetch = (...args) => {
        if (args[0].url.includes('adsbygoogle')) {
            console.info('Tampermonkey blocked adsbygoogle, and circumvented the adblock detection.');
            return Promise.resolve()
        }
        return f.call(window, ...args);
    }
    
    // This overrides the width of two elements that receive element style.
    // The applied element style ensures that there's always space for the ad container.
    // By specifying important rules, we can overrule it.
    const css = `
        body > div.flexrow.app > div:nth-child(1) > div.flexrow > div.panelblock.mainblock > div > div:nth-child(2) > div > canvas {
            /* full viewport - right panel width - left toolbar width */
            width: calc(100vw - 309px - 40px) !important;
        }
        body > div.flexrow.app > div:nth-child(1) > div.flexrow > div.panelblock.mainblock > div > div:nth-child(2) {
            /* full viewport - right panel width - left toolbar width */
            width: calc(100vw - 309px - 40px) !important;
        }
    `
    const style = document.createElement('style');
    style.appendChild(document.createTextNode(css));
    document.head.appendChild(style);
})();