Prevent execution of a specific inline script tag

后端 未结 2 1054
没有蜡笔的小新
没有蜡笔的小新 2021-01-18 05:58

I\'m trying to write a script for Tampermonkey that prevents the execution of a specific inline script tag. The body of the page looks something like this

&l         


        
2条回答
  •  北海茫月
    2021-01-18 06:40

    Delete script tag on document-start (as suggested by wOxxOm):

    (function() {
        'use strict';
        window.stop();
        const xhr = new XMLHttpRequest();
        xhr.open('GET', window.location.href);
        xhr.onload = () => {
            var html = xhr.responseText
            .replace(//g, s => {
                // check if script tag should be replaced/deleted
                if (s.includes('window.location')) {
                    return '';
                } else {
                    return s;
                }
            });
            document.open();
            document.write(html);
            document.close();
        };
        xhr.send();
    })();
    

提交回复
热议问题