Custom Styles

включить/выключить кастомные стили 1 кнопкой

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Custom Styles
// @namespace    https://greasyfork.org/ru/scripts/457633/
// @version      0.2
// @author       v666ad
// @match        https://shikimori.me/*
// @match        https://shikimori.one/*
// @description включить/выключить кастомные стили 1 кнопкой
// @license      MIT
// @run-at       document-end
// @grant        none
// ==/UserScript==

let customStylesEnabled = false // Custom styles are disabled by default.

let customStyleElement = null
let sourceCustomStyles = ""

function supports_HTML5_storage() {
    try {
        return 'localStorage' in window && window['localStorage'] !== null;
    } catch (e) {
        return false;
    }
}

if (supports_HTML5_storage()) {
    let customStylesEnabledLocalStorageExists = localStorage.getItem("customStylesEnabled")
    if (!customStylesEnabledLocalStorageExists) {
        localStorage.setItem("customStylesEnabled", customStylesEnabled)
    } else {
        customStylesEnabled = (customStylesEnabledLocalStorageExists === "true")
    }
}

function enableDisableCustomStyles() {
    if (customStylesEnabled) {
        customStyleElement.innerHTML = ""
    } else {
        customStyleElement.innerHTML = sourceCustomStyles
    }
    customStylesEnabled = !customStylesEnabled
    if (supports_HTML5_storage()) {
        localStorage.setItem("customStylesEnabled", customStylesEnabled)
    }
}

function main() {
    if (!document.querySelector("header.l-top_menu-v2 div.menu-dropdown.profile div.submenu a.icon-other")) {
        customStyleElement = document.getElementById("custom_css")
        sourceCustomStyles = customStyleElement.innerHTML
        document.querySelectorAll("header.l-top_menu-v2 div.menu-dropdown.profile div.submenu div.legend")[1].insertAdjacentHTML("afterend", `<a class="icon-other" tabindex="-1" title="Вернуть/Убрать пользовательские стили"><span class="text">Стили</span></a>`)
    }
    document.querySelector("header.l-top_menu-v2 div.menu-dropdown.profile div.submenu a.icon-other").onclick = enableDisableCustomStyles
    if (!customStylesEnabled) {
        customStyleElement.innerHTML = ""
    }
}

function ready(fn) {
    document.addEventListener('page:load', fn);
    document.addEventListener('turbolinks:load', fn);

    if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading") {
        fn();
    } else {
        document.addEventListener('DOMContentLoaded', fn);
    }
}

ready(main);