您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
This script is designed to work only on Youtube Trending page. Script cuts the time parameter which is used to continue watching from last position, changes the color of visited links to aqua and most importantly lets you ignore channels on trending page.
当前为
// ==UserScript== // @name Youtube Simple URL, Visited and Blacklist // @namespace http://tampermonkey.net/ // @version 0.42 // @description This script is designed to work only on Youtube Trending page. Script cuts the time parameter which is used to continue watching from last position, changes the color of visited links to aqua and most importantly lets you ignore channels on trending page. // @author taipignas // @match https://www.youtube.com/* // @grant none // ==/UserScript== (function () { 'use strict'; // run main function on initialization, not just on title change main(); // setup title change listener var title = document.querySelector('title'); const config = { attributes: true, childList: true, subtree: true, characterData: true }; const callback = function (mutationsList, observer) { main(); for (let mutation of mutationsList) { if (mutation.type === 'childList') { console.log('A child node has been added or removed.'); } if (mutation.type === 'subtree') { console.log('A subtree'); } if (mutation.type === 'characterData') { console.log('A characterData'); } else if (mutation.type === 'attributes') { console.log('The ' + mutation.attributeName + ' attribute was modified.'); } } }; const observer = new MutationObserver(callback); observer.observe(title, config); // add channel or user id to localstorage ignorelist function ignore(e) { hideSingle(e); let ignoreList = []; ignoreList[0] = localStorage.getItem('ignoreList'); ignoreList.push(e); localStorage.setItem('ignoreList', ignoreList); console.log(localStorage.getItem('ignoreList')); } // hide single video tile. used when clicking a button function hideSingle(e) { document.querySelector(`a[href$="${e}"]`).parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display = "none"; } // hide all video tiles matching id. used in main function to hide all ignored channel on initialization. function hideAll(e) { document.querySelectorAll(`a[href$="${e}"]`).forEach(element => { element.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display = "none" }); } function ToggleBlacklistedVisability() { localStorage.getItem('ignoreListSetting') == 1 ? localStorage.setItem('ignoreListSetting', 0) : localStorage.setItem('ignoreListSetting', 1); window.location.reload(); reload console.log(localStorage.getItem('ignoreListSetting')); } // main function function main() { if (window.location.href.includes('trending')) { // leave only simple video link with no properties like time to continue from document.querySelectorAll("a#video-title[href^='/watch?v=']").forEach(element => { element.href = element.href.slice(0, 43) }); // query local storage ignorelist and hide all if (localStorage.getItem('ignoreListSetting') == 1 && localStorage.getItem('ignoreList') != null) { for (let channel of localStorage.getItem('ignoreList').split(',')) { hideAll(channel); } } // query video tiles container and add each a button to send its channel id to ignore function var container = document.querySelectorAll("ytd-video-renderer"); for (let tile of container) { let button = document.createElement(`button`); button.textContent = `ignore`; button.setAttribute(`style`, `position: absolute; right: 0;`); let url = tile.querySelector("a[href^='/user/']") ? tile.querySelector("a[href^='/user/']") : tile.querySelector("a[href^='/channel/']"); let username = url.href; username = username.slice(username.lastIndexOf('/') + 1); button.value = username; button.onclick = function () { ignore(this.value) }; tile.firstElementChild.appendChild(button); } let ignoreListSetting = localStorage.getItem('ignoreListSetting'); let button = document.createElement(`button`); button.textContent = (ignoreListSetting == 1 ? `show` : `hide`) + ` ignored channels`; // (ignoreListSetting=="1"? `show` : `hide`) + // button.setAttribute(`style`, `position: absolute; right: 0;`); button.onclick = function () { ToggleBlacklistedVisability() }; document.querySelector("ytd-video-renderer").parentNode.prepend(button); // css code to change style color of visited links var style = document.createElement('style'); style.innerHTML = `a#video-title:visited {color:aqua !important;}`; document.head.appendChild(style); }; }; })();