// ==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 // @downloadURL 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 = '' li.appendChild(svg); function openYoutube() { window.open("https://www.youtube.com/results?search_query=" + title); } li.addEventListener('click', openYoutube); parent.insertAdjacentElement('afterend', li); } } //addbutton();