隐藏 Wikiwand 中的多余元素

删除 Wikiwand 中的多余元素,在工具栏添加跳转 Youtube 的按钮。可根据你的网络状态自行调整脚本头部的重复超时值。

目前为 2023-10-10 提交的版本。查看 最新版本

// ==UserScript==
// @name         隐藏 Wikiwand 中的多余元素
// @name:en      Hide Superfluous Elements in Wikiwand
// @namespace    Black Rabbit
// @author       Black Rabbit
// @version      0.1.2
// @description  删除 Wikiwand 中的多余元素,在工具栏添加跳转 Youtube 的按钮。可根据你的网络状态自行调整脚本头部的重复超时值。
// @description:en  Hide Superfluous Elements in Wikiwand, in toolbar add a button that jump to Youtube. Adjust the repeating timeout value in the head of the script according your network state.
// @match        *://www.wikiwand.com/*
// @run-at       document-start
// @icon         https://www.google.com/s2/favicons?sz=64&domain=wikiwand.com
// @grant        none
// ==/UserScript==

var timeout = 2000; // repeat hiding behaviour for 2000 ms
var itv;
var already = false;
var title;
var parent;

function runScript() {
    if (window.location.href.includes("www.wikiwand.com")) {
        if (window.location.pathname === '/' && !already) {
            itv = setInterval(homepage,50);
            console.log("start interval: homepage");
            already = true;
        } else if (!already) {
            itv = setInterval(dtpage,50);
            console.log("start interval: dtpage");
            already = true;
        }
        setTimeout (function () {
            if (already){
                clearInterval (itv);
                console.log("stop interval");
                already = false;
            }
        }, timeout);
    }
}

// first run
runScript();

// run when head changed
var observer = new MutationObserver(function(mutations) {
    for (var mutation of mutations) {
        if (mutation.type === 'childList') { // || mutation.type === 'attributes' mutation.type === 'childList'
            runScript();
        }
    }
});
var targetNode = document.head;
var config = { childList: true, subtree: true}; // , attributes: true, subtree: true
observer.observe(targetNode, config);

// run when backward or forward
window.onpopstate = function (event) { //.onpopstate
    if (window.location.href.includes("www.wikiwand.com")) {
        if (window.location.pathname === '/') {
            // 如果路径是根目录
            itv = setInterval(homepage,50);
            console.log("start interval: homepage");
        } else {
            // 如果路径是其他
            itv = setInterval(dtpage,50);
            console.log("start interval: dtpage");
        }
        setTimeout (function () {
            clearInterval (itv);
            console.log("stop interval");
        }, timeout);
    }
};

// detail page
function dtpage() {
    var elements = document.querySelectorAll('[class^="navbar_install__"]');
    for (var e of elements) {
        e.style.display = "none";
    }
    var footers = document.querySelectorAll('[class^="footer_wrapper__"]');
    for (var e of footers) {
        e.style.display = "none";
    }
    var titles = document.querySelectorAll('h1.section-h');
    for (var e of titles) {
        title = e.textContent;
    }
    //parent = document.querySelector('use[href="/images/icons.svg#icon-lang"]').parentElement.parentElement;
    parent = document.querySelector('ul.navbar_icons__2bQ22 > :nth-child(5)');
    add();
}

// home page
function homepage() {
    var buttons = document.querySelectorAll('[class^="navbar_button__"]');
    for (var e of buttons) {
        e.style.display = "none";
    }
    var footers = document.querySelectorAll('[class^="footer_wrapper__"]');
    for (var e of footers) {
        e.style.display = "none";
    }
    var sticky = document.querySelectorAll('[class*="navbar_sticky__"]');
    for (var e of sticky) {
        e.style.display = "none";
    }
    var hero_stores = document.querySelectorAll('[class*="hero_stores__"]');
    for (var e of hero_stores) {
        e.style.display = "none";
    }
    var hero_videoWrapper = document.querySelectorAll('[class*="hero_videoWrapper__"]');
    for (var e of hero_videoWrapper) {
        e.style.display = "none";
    }
    var themes_wrapper = document.querySelectorAll('[class*="themes_wrapper__"]');
    for (var e of themes_wrapper) {
        e.style.display = "none";
    }
    var try_wrapper = document.querySelectorAll('[class*="try_wrapper__"]');
    for (var e of try_wrapper) {
        e.style.display = "none";
    }
    var listen_wrapper = document.querySelectorAll('[class*="listen_wrapper__"]');
    for (var e of listen_wrapper) {
        e.style.display = "none";
    }
    var features_wrapper = document.querySelectorAll('[class*="features_wrapper__"]');
    for (var e of features_wrapper) {
        e.style.display = "none";
    }
    var summaries_wrapper = document.querySelectorAll('[class*="summaries_wrapper__"]');
    for (var e of summaries_wrapper) {
        e.style.display = "none";
    }
    var support_wrapper = document.querySelectorAll('[class*="support_wrapper__"]');
    for (var e of support_wrapper) {
        e.style.display = "none";
    }
    var mobile_wrapper = document.querySelectorAll('[class*="mobile_wrapper__"]');
    for (var e of mobile_wrapper) {
        e.style.display = "none";
    }
    var bling_wrapper = document.querySelectorAll('[class*="bling_wrapper__"]');
    for (var e of bling_wrapper) {
        e.style.display = "none";
    }
    var underline_underline = document.querySelectorAll('[class*="underline_underline__"]');
    for (var e of underline_underline) {
        e.style.display = "none";
    }
}

// function addbutton() {
//     // https://www.youtube.com/results?search_query=
//     setTimeout(function(){console.log(title);},2000);
//     setTimeout(function(){console.log(parent);},2000);
// }

var added = false;
function add() {
    if (title && parent && !added) {
        console.log("title and parent appeared !!!!! button added !!!");
        added = true;
        var li = document.createElement('li');
        li.className = 'navbar_item__8AUpD youtube-button';
        var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
        svg.setAttribute('t', '1696956270714');
        svg.setAttribute('class', 'icon');
        svg.setAttribute('viewBox', '0 0 1024 1024');
        svg.setAttribute('version', '1.1');
        svg.setAttribute('p-id', '10969');
        svg.setAttribute('width', '35');
        svg.setAttribute('height', '35');
        svg.setAttribute('fill', 'currentcolor');
        svg.innerHTML = '<path d="M992 268.8s0-3.2 0 0c-12.8-54.4-54.4-96-105.6-112-73.6-16-342.4-19.2-374.4-19.2s-300.8 0-374.4 22.4C83.2 172.8 44.8 214.4 32 268.8c-12.8 76.8-19.2 153.6-19.2 230.4 0 76.8 6.4 156.8 22.4 236.8 12.8 51.2 54.4 89.6 105.6 105.6 70.4 19.2 339.2 19.2 371.2 19.2s300.8 0 374.4-22.4c51.2-16 92.8-57.6 105.6-112 12.8-76.8 19.2-153.6 19.2-230.4 3.2-73.6-3.2-150.4-19.2-227.2z m-60.8 448c-6.4 28.8-32 54.4-60.8 60.8-57.6 16-278.4 19.2-358.4 19.2s-300.8-3.2-358.4-19.2c-28.8-6.4-51.2-32-60.8-57.6-12.8-73.6-19.2-147.2-19.2-220.8 0-73.6 6.4-147.2 19.2-217.6 6.4-28.8 32-54.4 60.8-60.8 57.6-16 278.4-19.2 358.4-19.2s300.8 3.2 358.4 16c28.8 9.6 51.2 32 60.8 60.8 12.8 73.6 19.2 147.2 19.2 220.8 0 76.8-6.4 147.2-19.2 217.6z m-252.8-243.2l-246.4-140.8c-9.6-6.4-22.4-6.4-32 0-9.6 6.4-16 19.2-16 28.8V640c0 12.8 6.4 22.4 16 28.8 6.4 3.2 9.6 3.2 16 3.2s9.6 0 16-3.2l246.4-140.8c9.6-6.4 16-16 16-28.8s-6.4-19.2-16-25.6zM448 585.6V416l147.2 83.2-147.2 86.4z" p-id="7708"></path>'
        li.appendChild(svg);
        function openYoutube() {
            window.open("https://www.youtube.com/results?search_query=" + title);
        }
        li.addEventListener('click', openYoutube);
        parent.insertAdjacentElement('afterend', li);
    }
}

//addbutton();

QingJ © 2025

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