Roll20 Boilerplate v2

Use this before other scripts

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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         Roll20 Boilerplate v2
// @namespace    http://statonions.com
// @version      0.2.4
// @description  Use this before other scripts
// @author       Justice Noon
// @match        https://app.roll20.net/editor/
// @include      https://app.roll20.net/assets/*
// @run-at       document-start
// @grant        GM_webRequest
// @webRequest   {"selector": {"include":"*/assets/app.js?*","exclude":"*/assets/app.js?n*"}, "action": "cancel" }
//Changelog: Rollback VTTES detection because it doesn't work on chrome unpacked (sometimes) depending on load order. Exposed variable is now just d20 everywhere. VTTES already exposes it. Activating VTTES or this script should do the same thing for scripts relying on window.d20
// ==/UserScript==

(function() {
    'use strict';
    var readyScript = '';

    GM_webRequest([{"selector": {"include":"*/assets/app.js?*","exclude":"*/assets/app.js?n*"}, "action": "cancel" }], function(info, message, details) {
        console.log(info, message, details);
    });
    var oReq = new XMLHttpRequest();
    oReq.addEventListener("load", function() {
		readyScript = this.responseText.replace('getPointer,degreesToRadians;', 'getPointer,degreesToRadians;window.d20=d20;');
    });
    oReq.open("GET", "https://app.roll20.net/assets/app.js?n" + Date.now());
    oReq.send();

    const observer = new MutationObserver(mutations => {
        mutations.forEach(({ addedNodes }) => {
            addedNodes.forEach(node => {
                if(node.nodeType === 1 && node.tagName === 'SCRIPT') {
                    const src = node.src || '';
                    //Load modified app when it would have loaded normally
                    if(src.indexOf('assets/app.js') > -1) {
                        window.eval(readyScript);
                        node.type = 'javascript/blocked';
                        node.parentElement.removeChild(node);
                        observer.disconnect();
                    }
                }
            })
        })
    })

    observer.observe(document.documentElement, {
        childList: true,
        subtree: true
    })
})();