Tumblr Accessibility UI Update Toggle

Rollback the accessibility UI update by default, and add a toggle to enable/disable it in the Dashboard settings page

2019-01-31 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

// ==UserScript==
// @name         Tumblr Accessibility UI Update Toggle
// @version      4.7
// @namespace    https://greasyfork.org/users/65414
// @description  Rollback the accessibility UI update by default, and add a toggle to enable/disable it in the Dashboard settings page
// @match        http://*.tumblr.com/*
// @match        https://*.tumblr.com/*
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM.setValue
// @grant        GM.getValue
// @run-at       document-start
// ==/UserScript==

(function() {

    let updateoff = $.browser.mozilla == true ? (async function(){return GM.getValue("updateoff", true);}) : GM_getValue("updateoff", true);

    let repeatRemove = setInterval(() => $("body").toggleClass('flag--accessibility-design-update', !updateoff), 1);
    setTimeout(() => { clearInterval(repeatRemove);}, 5000);

    if (window.location.href.indexOf("/settings/dashboard") > -1) {

        function addOption(){
            if ($('#user_enable_uiupdate').length){
                clearInterval(repeatAdd);
            } else {
                $('<div class="checkbox setting"><label class="binary_switch"><input type="checkbox" name="user[enable_uiupdate]" id="user_enable_uiupdate" value="on"'+ (updateoff !== true ? ' checked="checked"' : '' ) + '> <span class="binary_switch_track"></span><span class="binary_switch_button"></span></label><label for="user_enable_uiupdate">Enable the accessibility UI design update</label></div>').appendTo(".interface .group_content");
            }
        }

        let repeatAdd = setInterval(() => addOption(), 1);
    }

    $(window).on('load', function() {
        $('#user_enable_uiupdate').click(function(){
            clearInterval(repeatRemove)
            if (updateoff == true){
                $.browser.mozilla == true ? GM.setValue("updateoff",false) : GM_setValue("updateoff",false);
            } else {
                $.browser.mozilla == true ? GM.setValue("updateoff",true) : GM_setValue("updateoff",true);
            }
            $("body").toggleClass('flag--accessibility-design-update');
        });
    });
})();