Tumblr Accessibility UI Update Toggle

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

Fra 02.02.2019. Se den seneste versjonen.

// ==UserScript==
// @name         Tumblr Accessibility UI Update Toggle
// @version      5.0
// @namespace    https://greasyfork.org/users/65414
// @description  Roll back 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
// @run-at       document-start
// ==/UserScript==

(function(){

    let aduiPref = localStorage.getItem('aduiPref') !== null ? JSON.parse(localStorage.getItem('aduiPref')) : false;
    let langPref = $('html').attr('lang').split('-')[0];
    let doConfig = window.location.href.indexOf('/settings/dashboard') > -1;
    let aduiStr = langPref == 'de' ? "Schakel UI-ontwerp voor toegankelijkheid in" :
                  langPref == 'fr' ? "Activer la conception de l'interface utilisateur d'accessibilité" :
                  langPref == 'it' ? "Abilita la progettazione dell'interfaccia utente di accessibilità" :
                  langPref == 'ja' ? "ユーザー補助UIデザインを有効にする" :
                  langPref == 'tr' ? "Erişilebilirlik UI tasarımını etkinleştir" :
                  langPref == 'es' ? "Habilitar el diseño de la interfaz de usuario de accesibilidad" :
                  langPref == 'ru' ? "Включить дизайн пользовательского интерфейса" :
                  langPref == 'pl' ? "Włącz projektowanie interfejsu użytkownika ułatwień dostępu" :
                  langPref == 'pt' ? "Ativar design de interface do usuário de acessibilidade" :
                  langPref == 'nl' ? "Schakel UI-ontwerp voor toegankelijkheid in" :
                  langPref == 'ko' ? "접근성 UI 디자인 사용" :
                  langPref == 'zh' ? "启用辅助功能UI设计" :
                  langPref == 'id' ? "Aktifkan desain UI aksesibilitas" :
                  langPref == 'hi' ? "अभिगम्यता UI डिज़ाइन सक्षम करें" :
                  /* eng_US/other */ "Enable accessibility UI design";

    let inject = setInterval(function(){ applyPrefs(); doConfig ? addControls() : ''}, 1);

    function aduiToggle(i){ $('body').toggleClass('flag--accessibility-design-update', i).addClass('flag--aduiToggle-injected');};
    function applyPrefs(){ !$('.flag--aduiToggle-injected').length ? aduiToggle(aduiPref):'' ; !doConfig && $('.flag--aduiToggle-injected').length ? clearInterval(inject) : '' }
    function addControls(){ $('#user_enable_adui').length && $('.flag--aduiToggle-injected').length ? clearInterval(inject) : $('.interface .group_content').append($('.interface .checkbox:last').clone()); $('.interface .checkbox:last').find('label:last').attr('for', 'user_enable_adui'); $('label[for=user_enable_adui').text(aduiStr); $('.interface .checkbox:last').find('input').prop('checked', aduiPref).attr('id', 'user_enable_adui').attr('name', 'user[enable_uiupdate]').removeAttr('value'); $(document).on('click', '#user_enable_adui', function(){ localStorage.setItem('aduiPref', !aduiPref); clearInterval(inject); aduiPref = !aduiPref; aduiToggle(); })}

})();