better wiktionary

improving the webpage layout for reader, and adding hideshow button for every language

目前为 2024-03-24 提交的版本。查看 最新版本

// ==UserScript==
// @name         better wiktionary
// @namespace    http://tampermonkey.net/
// @version      2024-03-24
// @description  improving the webpage layout for reader, and adding hideshow button for every language
// @author       Al Arcus
// @match        *://*.wiktionary.org/**
// @icon         https://www.google.com/s2/favicons?sz=64&domain=wiktionary.org
// @require      https://code.jquery.com/jquery-3.6.0.min.js
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    // Add CSS to hide .toclevel-1 > ul by default
    var style = document.createElement('style');
    style.innerHTML = `
        .toclevel-1 > ul { display: none; }
        .toc-toggle-button {
            position: absolute;
            left: 9px;
            min-width: 18px;
            min-height: 18px;
            padding: 0;
            font-size: 0.7rem;
        }
        .mw-body-content, .mw-first-heading{
            margin: 0 auto;
            margin-top: 0px;
            margin-right: auto;
            margin-bottom: 0px;
            margin-left: auto;
        }

        .mw-body-content, .mw-first-heading{
          max-width: 948px;
        }

        .mw-content-ltr > p{
            max-width: 49em;
        }

        li{
              max-width: 49em;
        }

        #mw-panel {
          left: auto !important;
          right: 0px;
        }

        .mw-body, #mw-head-base, #left-navigation, #mw-data-after-content, .mw-footer {
            margin-left: 230px !important;
            margin-right: 11em;
        }


        .mw-body {
            border-right-width: 1px;
        }

        #mw-head {
          right: 10em;
          left: 5em;
          width: auto;
        }

        .NavFrame, .NavHead {
            background-image: none !important;
        }
        .translations-cell {
            background-color: #231400 !important;
        }


        .toc {
                position: fixed;
                top: 0;
                left: 0;
                width: 200px;
                height: 100%;
                background-color: #f6f6f6;
                overflow-y: auto;
                padding: 20px;
                border: 1px solid #a7d7f9;
            }

        .toc > ul {
          margin-left: 1em;
        }
    `;
    document.head.appendChild(style);
    // Loop through each .toclevel-1 element
    $('.toclevel-1').each(function(index) {
        // Extract the name from the href attribute
        var name = $(this).find('a').attr('href').replace('#', '');

        // Set ul's id to toc-{name}-sublist
        $(this).find('ul').attr('id', 'toc-' + name + '-sublist');

        // Add button to hide/show TOC subsection
        var button = $('<button class="toc-toggle-button">+</button>');
        $(this).prepend(button);

        // Add click event to toggle visibility of subsection
        button.click(function() {
            $('#toc-' + name + '-sublist').toggle();
        });
    });
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址