// ==UserScript== // @name YouTube 伪装成 哔哩哔哩 // @namespace https://github.com/userElaina/this-is-the-China-website // @version 2023.09.22.02 // @description 中国人就用哔哩哔哩 // @author userElaina // @license MIT // @match *://*.youtube.com/* // @grant none // @downloadURL none // ==/UserScript== function changeStyle(s0, s1) { let newStyle = document.createElement("style"); document.head.appendChild(newStyle); let newSheet = newStyle.sheet; newSheet.addRule(s0, s1); newSheet.insertRule(s0 + ' { ' + s1 + ' }', 0); } function sleep(time) { return new Promise((resolve) => setTimeout(resolve, time)); } async function f_succ(f, msSleep = 500, maxCount = 10) { let count = 0; while (true) { if (f()) { return true; } count++; if (count > maxCount) { return false; } await sleep(msSleep); } } (async function () { // change title await f_succ(() => { let split_num = window.location.href.split('/'); if (split_num.length < 4 || (split_num.length == 4 && split_num[3].length == 0)) { document.title = "哔哩哔哩 (゜-゜)つロ 干杯~-bilibili"; return true; } if(document.title.endsWith('YouTube')){ document.title = document.title.replace(/\s-\sYouTube*/g, " - 哔哩哔哩"); return true; } return false; }); // change icon await f_succ(() => { let icon = document.querySelector('link[rel="icon"]'); if (icon === null) { return false; } icon.href = 'https://raw.githubusercontent.com/userElaina/this-is-the-China-website/main/youtube/bilibili.ico'; return true; }); // change title loop f_succ(() => { let split_num = window.location.href.split('/'); if (split_num.length < 4 || (split_num.length == 4 && split_num[3].length == 0)) { document.title = "哔哩哔哩 (゜-゜)つロ 干杯~-bilibili"; } if(document.title.endsWith('YouTube')){ document.title = document.title.replace(/\s-\sYouTube*/g, " - 哔哩哔哩"); } return false; }, 2000, 2147483647); // change logo on top left f_succ(() => { let logo = document.getElementById("logo-icon"); if (logo === null) { return false; } logo.innerHTML = ''; return true; }); sleep(1000).then(() => { /* use `changeStyle` instead of `query().style=...` because some elements are added dynamically */ function changeBgColor(s0) { changeStyle(s0, 'background-color: #00aeec'); } // button.ytp-button.ytp-settings-button.ytp-hd-quality-badge::after changeBgColor('.ytp-settings-button.ytp-hd-quality-badge:after, .ytp-settings-button.ytp-hdr-quality-badge:after, .ytp-settings-button.ytp-4k-quality-badge:after, .ytp-settings-button.ytp-5k-quality-badge:after, .ytp-settings-button.ytp-8k-quality-badge:after, .ytp-settings-button.ytp-3d-badge-grey:after, .ytp-settings-button.ytp-3d-badge:after'); // button.ytp-subtitles-button.ytp-button::after changeBgColor('.ytp-chrome-controls .ytp-button[aria-pressed]:after'); /* let notice = document.querySelector('div.yt-spec-icon-badge-shape__badge'); if (notice != null) { notice.style.backgroundColor = '#00aeec'; } */ changeBgColor('.yt-spec-icon-badge-shape--type-notification .yt-spec-icon-badge-shape__badge'); /* document.querySelectorAll('div.ytp-play-progress.ytp-swatch-background-color').forEach(v => { v.style.backgroundColor = '#00aeec'; }); document.querySelector('div.ytp-scrubber-button.ytp-swatch-background-color').style.backgroundColor = '#00aeec'; */ changeBgColor('.ytp-swatch-background-color'); /* setInterval(() => { document.querySelectorAll('[id=progress]').forEach(v => { v.style.backgroundColor = '#00aeec'; }); }, 1000); */ changeBgColor('#progress.ytd-thumbnail-overlay-resume-playback-renderer'); // Settings - Annotations changeBgColor('.ytp-menuitem[aria-checked=true] .ytp-menuitem-toggle-checkbox'); }); })();