Greasy Fork

来自缓存

Greasy Fork is available in English.

Scroll to Grammar Info

When showing Grammar Info, scroll down to it, if hiding, scroll back up.

当前为 2022-05-17 提交的版本,查看 最新版本

// ==UserScript==
// @name         Scroll to Grammar Info
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  When showing Grammar Info, scroll down to it, if hiding, scroll back up.
// @author       You
// @match        https://bunpro.jp/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=bunpro.jp
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    var last_display_value = null

    function scroll_to_grammar_section() {
        var grammar_section = document.getElementById("check-grammar");
        var show_grammar_button = document.getElementById("show-grammar");

        if (!grammar_section) {
            return
        }

        if (last_display_value == grammar_section.style.display) {
            return
        }

        if (grammar_section.style.display == "block") {
            show_grammar_button.scrollIntoView({behavior: "smooth", block: "start"});
        }
        else {
            document.getElementsByTagName("body")[0].scrollIntoView({behavior: "smooth", block: "start"});
        }

        last_display_value = grammar_section.style.display
    }

    window.setInterval(scroll_to_grammar_section, 200);

})();