// ==UserScript== // @name 隐藏 Wikiwand 中的多余元素及添加跳转 Youtube 与 Bilibili 的按钮 // @name:en Hide Superfluous Elements in Wikiwand & Add search button to Youtube and Bilibili // @namespace Black Rabbit // @author Black Rabbit // @version 0.1.4 // @description 删除 Wikiwand 中的多余元素,在工具栏添加跳转 Youtube 和 Bilibili 的按钮。可根据你的网络状态自行调整脚本头部的重复超时值。可自定义要显示的按钮类型。 // @description:en Hide Superfluous Elements in Wikiwand, in toolbar add a button that jump to Youtube and Bilibili. Custom the repeating timeout value in the head of the script according your network state. Custom the button type. // @match *://www.wikiwand.com/* // @run-at document-start // @icon https://www.google.com/s2/favicons?sz=64&domain=wikiwand.com // @grant none // @downloadURL https://update.greasyfork.icu/scripts/477110/%E9%9A%90%E8%97%8F%20Wikiwand%20%E4%B8%AD%E7%9A%84%E5%A4%9A%E4%BD%99%E5%85%83%E7%B4%A0%E5%8F%8A%E6%B7%BB%E5%8A%A0%E8%B7%B3%E8%BD%AC%20Youtube%20%E4%B8%8E%20Bilibili%20%E7%9A%84%E6%8C%89%E9%92%AE.user.js // @updateURL https://update.greasyfork.icu/scripts/477110/%E9%9A%90%E8%97%8F%20Wikiwand%20%E4%B8%AD%E7%9A%84%E5%A4%9A%E4%BD%99%E5%85%83%E7%B4%A0%E5%8F%8A%E6%B7%BB%E5%8A%A0%E8%B7%B3%E8%BD%AC%20Youtube%20%E4%B8%8E%20Bilibili%20%E7%9A%84%E6%8C%89%E9%92%AE.meta.js // ==/UserScript== var timeout = 2000; // repeat hiding behaviour for 2000 ms var videotype = 2; // 0 for only Youtube, 1 for only Bilibili, 2 for both of them 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"; } // get title for searching var titles = document.querySelectorAll('h1.section-h'); for (var e of titles) { title = e.textContent; } // get parent for injecting //parent = document.querySelector('use[href="/images/icons.svg#icon-lang"]').parentElement.parentElement; parent = document.querySelector('ul.navbar_icons__2bQ22 > :nth-child(5)'); // add video button 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; if (videotype === 0){ youtubeBtn(); } else if (videotype === 1){ bilibiliBtn(); } else if (videotype === 2){ bilibiliBtn(); youtubeBtn(); } function youtubeBtn() { 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', '-88 -88 1200 1200'); svg.setAttribute('version', '1.1'); svg.setAttribute('p-id', '10969'); svg.setAttribute('width', '38'); svg.setAttribute('height', '38'); 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); } function bilibiliBtn() { var li2 = document.createElement('li'); li2.className = 'navbar_item__8AUpD bilibili-button'; var svg2 = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); svg2.setAttribute('t', '1698482736673'); svg2.setAttribute('class', 'icon'); svg2.setAttribute('viewBox', '-88 -88 1200 1200'); svg2.setAttribute('version', '1.1'); svg2.setAttribute('p-id', '15432'); svg2.setAttribute('width', '39'); svg2.setAttribute('height', '39'); svg2.setAttribute('fill', 'currentcolor'); svg2.innerHTML = ''; li2.appendChild(svg2); function openBilibili() { window.open("https://search.bilibili.com/video?keyword=" + title); } li2.addEventListener('click', openBilibili); parent.insertAdjacentElement('afterend', li2); } } } //addbutton();