sscarl24 / uBO-Extra

// ==UserScript==
// @name         uBO-Extra
// @description  A companion user-script to uBlock Origin which helps to gain ability to foil early anti-user mechanisms working around content blockers or even a browser privacy settings.
// @author       X01X012013
// @version      2.21
// @encoding     utf-8
// @icon         https://raw.githubusercontent.com/gorhill/uBO-Extra/master/icon128.png
// @include      http://*/*
// @include      https://*/*
// @grant        unsafeWindow
// @grant        GM_xmlhttpRequest
// @grant        GM_registerMenuCommand
// @grant        GM_getValue
// @grant        GM_setValue
// @connect      *
// @run-at       document-start
// @homepage     https://github.com/gorhill/uBO-Extra/
// @supportURL   https://github.com/gorhill/uBO-Extra/issues
// ==/UserScript==

(function() {
    "use strict";

    
    const checkUpdate = function () {
        GM_xmlhttpRequest({
            method: "GET",
            url: "https://raw.githubusercontent.com/gorhill/uBO-Extra/master/contentscript.js",
            onload: function (result) {
                GM_setValue("text", result.responseText);
                GM_setValue("time", (new Date()).getTime());
                unsafeWindow.console.info("uBO-Extra has been updated to the latest script version.");
            },
            onerror: function () {
                unsafeWindow.console.warn("uBO-Extra Updater failed to check for update.");
            }
        });
    };
    
    const wrapper_pre = "try {";
    const text = GM_getValue("text", "");
    const wrapper_post = "} catch (e) { console.error(e); } finally { let script = document.currentScript, parent = script && script.parentNode; parent && parent.removeChild(script); }";
    
    if (text.length) {
        
        const elem = unsafeWindow.document.createElement("script");
        elem.innerHTML = wrapper_pre + text + wrapper_post;
        unsafeWindow.document.head.appendChild(elem);
        
        if (GM_getValue("time", 0) + 86400000 < (new Date()).getTime()) {
            
            setTimeout(checkUpdate, 5000);
        }
    } else {
        
        checkUpdate();
    }
        GM_registerMenuCommand("Update uBO-Extra", checkUpdate);

})();