您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Small CSS tweaks to youtube with color theme settings
当前为
- // ==UserScript==
- // @name Youtube plus
- // @description Small CSS tweaks to youtube with color theme settings
- // @grant GM_addStyle
- // @include *://youtube.com/*
- // @include *://www.youtube.com/*
- // @run-at document-load
- // @version 2.1
- // @namespace https://greasyfork.org/users/3167
- // ==/UserScript==
- var defaultcolor = "hsla(3, 60%, 47%, 1)";
- var customcolor = defaultcolor;
- var firstrun = false;
- if (typeof(Storage) !== "undefined") {
- if (localStorage.yt_custom_color) {
- customcolor = localStorage.yt_custom_color;
- } else {
- firstrun = true;
- localStorage.yt_custom_color = customcolor;
- }
- }
- console.log("yt_custom_color", customcolor);
- var stylesheet = `
- body {
- /* --yt-custom-color: " + customcolor + "; */
- }
- .ytp-pause-overlay {
- display: none;
- }
- #player-ads { display: none; }
- body, ytd-app {
- --yt-brand-paper-button-color: var(--yt-custom-color) !important;
- --yt-brand-color: var(--yt-custom-color) !important;
- }
- paper-button.ytd-subscribe-button-renderer {
- background: var(--yt-custom-color);
- }
- a.yt-simple-endpoint.yt-formatted-string, ytd-guide-entry-renderer[active] path.style-scope.yt-icon {
- color: var(--yt-custom-color);
- }
- #progress.ytd-thumbnail-overlay-resume-playback-renderer, .ytp-red2 .ytp-swatch-background-color, .ytp-red2 .ytp-swatch-background-color-secondary, .ytp-play-progress.ytp-swatch-background-color, .ytp-swatch-background-color-secondary {
- background-color: var(--yt-custom-color);
- }
- path#lozenge-path, #logo path.style-scope.yt-icon, path.style-scope.ytd-topbar-logo-renderer {
- fill: var(--yt-custom-color);
- }
- div#top div#player {
- max-height: calc(100vh - var(--ytd-masthead-height, 56px));
- }
- `;
- if (typeof GM_addStyle != "undefined") {
- GM_addStyle (stylesheet);
- } else {
- var css = document.createElement("style");
- css.type = "text/css";
- css.innerHTML = stylesheet;
- document.head.appendChild(css);
- }
- var customcolorpicker = document.createElement('input');
- customcolorpicker.type = "color";
- customcolorpicker.onchange = "setcustomcolor(this.value);";
- customcolorpicker.style = "display: none;";
- customcolorpicker.addEventListener("change", function() {
- setcustomcolor(this.value);
- });
- var setcustomcolor = function (colorinput) {
- console.log("Changing color theme to: " + colorinput);
- customcolor = colorinput;
- document.body.style.setProperty('--yt-custom-color', customcolor);
- localStorage.yt_custom_color = customcolor;
- var savedcolor = localStorage.yt_custom_color;
- console.log("Saved color theme: " + savedcolor);
- }
- unsafeWindow.setcustomcolor = setcustomcolor;
- var pickcustomcolor = function () {
- console.log("click");
- customcolorpicker.click();
- }
- unsafeWindow.pickcustomcolor = pickcustomcolor;
- var resetcustomcolor = function () {
- unsafeWindow.setcustomcolor(defaultcolor);
- }
- unsafeWindow.resetcustomcolor = resetcustomcolor;
- var video_emitkey = function(keycode) {
- var video_element = document.getElementById("movie_player");
- if (video_element) {
- var ke = new KeyboardEvent('keydown');
- delete ke.keyCode;
- Object.defineProperty(ke, "keyCode", {"value" : keycode});
- video_element.dispatchEvent(ke);
- }
- }
- var volumecontrol_init = function() {
- var video_player = document.getElementById("ytd-player");
- if (video_player) {
- if (!video_player.youtubeplus_wheel_hooked) {
- video_player.addEventListener('wheel', function(e) {
- e.preventDefault();
- if (e.deltaY < 0) {
- video_emitkey(38);
- }
- if (e.deltaY > 0) {
- video_emitkey(40);
- }
- });
- video_player.youtubeplus_wheel_hooked = true;
- }
- }
- }
- var init = function() {
- setcustomcolor(customcolor);
- volumecontrol_init();
- mutator_init();
- console.log("Youtube++ init!");
- }
- var mutator_callback = function() {
- console.log("Mutation detected...");
- volumecontrol_init();
- mutator_init();
- }
- var mutator_init = function() {
- var targetNode = document.body;
- if (targetNode && !targetNode.youtubeplus_mutator_hooked) {
- var observer = new MutationObserver(mutator_callback);
- observer.observe(targetNode, { childList: true });
- targetNode.youtubeplus_mutator_hooked = true;
- }
- }
- console.log("Youtube++ loaded!");
- init();