Youtube Dark figuccio

youtube dark mode stop riproduzione autom

目前为 2024-03-03 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Youtube Dark figuccio
  3. // @namespace https://greasyfork.org/users/237458
  4. // @version 11.3
  5. // @description youtube dark mode stop riproduzione autom
  6. // @author figuccio
  7. // @match https://*.youtube.com/*
  8. // @match https://consent.youtube.com/*
  9. // @run-at document-end
  10. // @grant GM_addStyle
  11. // @grant GM_setValue
  12. // @grant GM_getValue
  13. // @noframes
  14. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
  15. // @icon https://www.youtube.com/s/desktop/3748dff5/img/favicon_48.png
  16. // @grant GM_registerMenuCommand
  17. // @grant GM_addElement
  18. // @require http://code.jquery.com/jquery-latest.js
  19. // @require https://code.jquery.com/ui/1.12.1/jquery-ui.js
  20. // @license MIT
  21. // ==/UserScript==
  22. (function () {
  23. 'use strict';
  24. /////////////////////time
  25. let timeout;
  26. let videoElement;
  27.  
  28. // Crea un div contenitore
  29. const containerDiv = document.createElement("div");
  30. containerDiv.style.cssText = `position:fixed;top:10px;right:10px;display:flex;align-items:center;z-index:999999999;`;
  31.  
  32. //Crea un div rettangolare arrotondato che visualizza l'ora
  33. const timeDiv = document.createElement("div");
  34. timeDiv.title="Data-ora";
  35. timeDiv.style.cssText = `
  36. background-color: rgba(0, 0, 0, 0.5);
  37. color:lime;
  38. font-size:15px;
  39. padding: 5px;
  40. border-radius: 5px;
  41. cursor: pointer;
  42. font-family: "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  43. font-weight: bold;
  44. border:2px solid green;
  45. `;
  46.  
  47. containerDiv.appendChild(timeDiv);//orologio
  48.  
  49. function initialize() {
  50. updateTime();
  51. }
  52.  
  53. function updateTime() {
  54. findvideo(); // Emette il valore di videoElement
  55. const now = new Date();
  56. //data
  57. const date = new Date().toLocaleString('it', {'weekday': 'short', 'month': 'long', 'day': '2-digit','year':'numeric'});
  58. /////////////////////ore-minuti-sec-millisec
  59. const time = new Date().toLocaleTimeString();
  60. const sss = new Date().getMilliseconds();
  61.  
  62. timeDiv.textContent =date +" - "+ time +":"+ sss;//giorno-mese-anno h m s
  63. setTimeout(updateTime, 200);//Continua ad aggiornare l'ora 1000 /200 ms
  64. }
  65.  
  66. // Scatta nell'angolo in alto a destra del video
  67. function stickToTopRight() {
  68. if (videoElement) {
  69. // Ottieni le informazioni sulle dimensioni e sulla posizione del lettore video
  70. const videoRect = videoElement.getBoundingClientRect();
  71. // Imposta la posizione del div contenitore, fissata nell'angolo in alto a destra
  72. containerDiv.style.top = `${videoRect.top + 10}px`;
  73. containerDiv.style.right = `${document.documentElement.clientWidth - videoRect.right + 10}px`;
  74. }
  75. }
  76.  
  77. // Aggiorna la posizione del div contenitore e mantienilo fisso quando la finestra del video viene ridimensionata o viene visualizzata a schermo intero
  78. function updatePosition() {
  79. stickToTopRight();
  80. setTimeout(updatePosition, 500); // Aggiorna la posizione ogni 0,5 secondi 500
  81. }
  82.  
  83. function findvideo() {
  84. if (window.location.href.includes("www.bilibili.com/video/")) {
  85. videoElement = document.querySelector("bwp-video");
  86. if (!videoElement) {
  87. videoElement = document.querySelector("video");
  88. if (0 == (new Date().getSeconds() % 2)) console.log("222:" + videoElement);
  89. }
  90. else if (0 == (new Date().getSeconds() % 2)) console.log("111:" + videoElement);
  91. } else {
  92. videoElement = document.querySelector("video");
  93. if (0 == (new Date().getSeconds() % 2)) console.log("222:" + videoElement);
  94. }
  95. if (null == videoElement) {
  96. containerDiv.style.display = "none";
  97. }
  98. else {
  99. containerDiv.style.display = "flex";
  100. }
  101.  
  102. }
  103.  
  104. // Monitora le modifiche dello stato a schermo intero e aggiungi il div contenitore al livello a schermo intero
  105. function handleFullscreenChange() {
  106. if (document.fullscreenElement) {
  107. // Aggiungi il div contenitore all'elemento a schermo intero quando accedi a schermo intero
  108. document.fullscreenElement.appendChild(containerDiv);
  109. } else {
  110. // Aggiungi nuovamente il div contenitore alla pagina quando esci dalla modalità a schermo intero
  111. document.body.appendChild(containerDiv);
  112. }
  113.  
  114. }
  115.  
  116. // Chiama le funzioni di inizializzazione e aggiornamento della posizione per avviarne l'aggiornamento in tempo reale
  117. initialize();
  118. updatePosition();
  119.  
  120. // Aggiungi il div contenitore alla pagina
  121. document.body.appendChild(containerDiv);
  122.  
  123. // Ascolta gli eventi di modifica dello stato a schermo intero
  124. document.addEventListener("fullscreenchange", handleFullscreenChange);
  125. /////////////////////////////////////////////////////////
  126.  
  127. ////////////////////////mostra % volume/////
  128. let previousVolume = -1;
  129. function displaySquareVolume() {
  130. const player = document.getElementById('movie_player');
  131. const currentVolume = player.getVolume();
  132.  
  133. if (currentVolume !== previousVolume) {
  134. previousVolume = currentVolume;
  135. const squareVolume = document.querySelectorAll('div[data-layer="4"]');
  136. squareVolume.forEach((div) => {
  137. if(div.className === 'ytp-bezel-text-hide') {
  138. div.classList.remove('ytp-bezel-text-hide');
  139. }
  140. if (div.classList.length === 0) {
  141. const ytpBezelTextWrapper = div.querySelector('.ytp-bezel-text-wrapper');
  142. ytpBezelTextWrapper.title="Volume";
  143. const ytpBezelText = ytpBezelTextWrapper.querySelector('.ytp-bezel-text');
  144. const ytpBezel = div.querySelector('.ytp-bezel');
  145. div.style.display = 'block';
  146.  
  147. if (ytpBezelText && ytpBezel) {
  148. ytpBezelText.innerText = currentVolume + "%";
  149. ytpBezel.style.display = 'none';
  150. }
  151.  
  152. setTimeout(()=> {
  153. div.style.display = 'none';
  154. }, 20000);//resta fisso per 20 secondi
  155. }
  156. });
  157. }
  158. }
  159.  
  160. function checkVideoExists() {
  161. const videoElement = document.querySelector('video');
  162. if (videoElement) {
  163. videoElement.addEventListener('volumechange', displaySquareVolume);
  164. previousVolume = videoElement.volume * 100;
  165. }
  166. }
  167.  
  168. const observer = new MutationObserver(checkVideoExists);
  169. const body = document.body;
  170. const config = {childList: true, subtree: true};
  171. observer.observe(body, config);
  172. GM_addStyle('.ytp-bezel-text-wrapper{color:green;cursor:pointer;}');//% volume colore verde
  173. ///////////////////////
  174. ///////////////////////////////////volume predefinito 70%
  175. if (GM_getValue('Default_Volume') === undefined) //Se Default_Volume non è stato ancora impostato
  176. { //Starts the if condition
  177. GM_setValue('Default_Volume', 70); //Salva il volume predefinito al 70%
  178. } //Finishes the if condition
  179.  
  180. window.sessionStorage.setItem('yt-player-volume', '{"data":"{\\"volume\\":' + GM_getValue('Default_Volume') + ',\\"muted\\":false}","creation":' + new Date().valueOf() + '}'); //Imposta il volume YT predefinito
  181.  
  182. //nuovo accetta cookie consent prima di continuare dicembre 2023
  183. if (!document.cookie.match("(^|;)\\s*CONSENT=YES\\+")) {
  184. document.cookie ="SOCS=CAISEwgDEgk2MDkwMDAzMTIaAml0IAEaBgiA4-SuBg;max-age=315360000";//febbraio 2024 accetta tutto
  185. document.cookie ="CONSENT=YES+;domain=.youtube.com;max-age=315360000";
  186. document.cookie ="PREF=f6=40000400&f7=140;domain=youtube.com";//ok tema scuro illum cinem disattivata
  187. location.reload();
  188. }
  189. /////////////////////////riproduzione automatica disattivata
  190. document.addEventListener('yt-navigate-finish', () => {
  191. /* Qualsiasi codice riportato di seguito verrà eseguito solo sulle pagine www.youtube.com/watch?v */
  192. if (!window.location.href.includes("watch")) return;
  193. var i = window.setInterval(() => {
  194. const t = document.getElementsByClassName('ytp-autonav-toggle-button')[0];
  195. if (t.getAttribute('aria-checked') === "true") {
  196. t.click();
  197.  
  198. clearInterval(i);
  199. } else if (t.getAttribute('aria-checked') === "true") {
  200. t.click();
  201. }
  202. }, 1000);
  203. })
  204. /////////////////////barra volume video sempre visibile
  205. GM_addStyle('.ytp-volume-panel {width:52px!important;}');
  206. GM_addStyle('.ytp-volume-slider-handle:before {background:green!important;}');//linea volume verde
  207. GM_addStyle('.ytp-volume-slider-handle {background:red!important;}');//pallino volume
  208.  
  209. //////////////////////////////////
  210. //shorts e tendenze
  211. GM_addStyle('#dismissible.ytd-rich-shelf-renderer {display:none!important;}');
  212. //Rimuovi Youtube Commenti
  213. GM_addStyle('ytd-comments.style-scope{ display:none !important;}');
  214. //adblock grosso banner youtube premium
  215. GM_addStyle(`#masthead-ad { display:none!important;}`);
  216.  
  217. //promemoria privacy
  218. document.cookie = "HideTicker=true;domain=.youtube.com;max-age=315360000";
  219. //annotazioni video
  220. GM_addStyle(`.html5-video-player .ytp-cards-button{display:none!important;}`);
  221. //popup non hai eseguito laccesso
  222. GM_addStyle(`yt-tooltip-renderer{display:none!important;}`);
  223. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  224. //hide guide local storage
  225. (function () {
  226. 'use strict';
  227.  
  228. let guide = ['Default', 'Compact', 'Compact-E'];
  229. let guideMode = GM_getValue('guide', 2);
  230. let p = 'ytd-app[guide-persistent-and-visible]';
  231. let m = 'ytd-app[mini-guide-visible]';
  232. let i = '!important';
  233.  
  234. function setStyle() {
  235. const guideEL = document.querySelector('[guideStyle]');
  236. if (guideEL) guideEL.remove();
  237. guideMode = GM_getValue('guide', 2);
  238. switch (guideMode) {
  239. case 1:
  240. GM_addElement(document.documentElement, 'style', {
  241. textContent: `${p} tp-yt-app-drawer {display: none${i};}${p} tp-yt-app-header {left: 72px${i};}${p} #channel-container {max-height: 218px${i};}${p} ytd-page-manager {margin-left: var(--ytd-mini-guide-width)${i};}${p} ytd-mini-guide-renderer {display: unset${i};}${p} ytd-playlist-header-renderer.ytd-browse {left: var(--ytd-mini-guide-width)${i};}${m} tp-yt-app-drawer {display: unset ${i};visibility: visible ${i};}${m} tp-yt-app-header {left: 240px ${i};}${m} #channel-container {max-height: 230px;}${m} ytd-page-manager {margin-left: var(--app-drawer-width) ${i};}${m} ytd-mini-guide-renderer {display: none ${i};}${m} #scrim.tp-yt-app-drawer {opacity: 1 ${i};}${m} #contentContainer.tp-yt-app-drawer {transform: translate3d(0, 0, 0) ${i};}${m} #contentContainer.tp-yt-app-drawer #header.ytd-app {display: none ${i};}${m} ytd-playlist-header-renderer.ytd-browse {left: var(--app-drawer-width) ${i};}`,
  242. guideStyle: 'Compact',
  243. });
  244. break;
  245. case 2:
  246. GM_addElement(document.documentElement, 'style', {
  247. textContent: `${p} tp-yt-app-drawer {display: none${i};}${p} tp-yt-app-header {left: 72px${i};}${p} #channel-container {max-height: 218px${i};}${p} ytd-page-manager {margin-left: var(--ytd-mini-guide-width)${i};}${p} ytd-mini-guide-renderer {display: unset${i};}${p} ytd-playlist-header-renderer.ytd-browse {left: var(--ytd-mini-guide-width)${i};}${m} tp-yt-app-drawer {display: unset ${i};visibility: visible ${i};}${m} tp-yt-app-header {left: 240px ${i};}${m} #channel-container {max-height: 230px;}${m} ytd-page-manager {margin-left: var(--app-drawer-width) ${i};}${m} ytd-mini-guide-renderer {display: none ${i};}${m} #scrim.tp-yt-app-drawer {opacity: 1 ${i};}${m} #contentContainer.tp-yt-app-drawer {transform: translate3d(0, 0, 0) ${i};}${m} #contentContainer.tp-yt-app-drawer #header.ytd-app {display: none ${i};}${m} ytd-playlist-header-renderer.ytd-browse {left: var(--app-drawer-width) ${i};}`,
  248. guideStyle: 'Compact-E',
  249. });
  250. break;
  251. }
  252. }
  253. setStyle();
  254.  
  255. function changeStyle() {
  256. if (guideMode < 2) {
  257. GM_setValue('guide', guideMode + 1);
  258. } else {
  259. GM_setValue('guide', (guideMode = 0));
  260. }
  261.  
  262. setStyle();
  263. GM_registerMenuCommand(`Guide style: ${guide[guideMode]}`, changeStyle, {
  264. title: 'Fare clic per selezionare successivo',
  265. autoClose: false,
  266. id: guideCommand,
  267. });
  268. }
  269.  
  270. const guideCommand = GM_registerMenuCommand(`Guide style: ${guide[guideMode]}`, changeStyle, {
  271. title: 'Fare clic per selezionare successivo',
  272. autoClose: false,
  273. });
  274. })();
  275.  
  276. ///////////rimuove scritta consigliati allinterno video
  277. GM_addStyle('.ytp-cards-teaser-label{display:none !important;}');
  278. ///////////icome home ecc e titoli home tendenze ecc
  279. GM_addStyle('.title,.pieSegment,svg {color:#5f84f1 !important;}');
  280. //scrittura verde
  281. GM_addStyle('.aplos-donut-center-content,.formatted-percentage.yta-explore-table-row,.entity-name.ytcp-navigation-drawer,#tags-count,h3.ytcp-uploads-basics,.source.ytpp-self-certification-predictor span.ytpp-self-certification-predictor,.m10n-icon-section.ytpp-self-certification-predictor span.ytpp-self-certification-predictor,#unplayableText,.content-title,.progress-label.ytcp-video-upload-progress,.issue-text.ytcd-help-center-issues-item,#campaign-title.ytd-donation-shelf-renderer,#published-time,.paddingten,#ctr-title,.label,#keywords-description,.channel-name,#purchase-amount,.paper-input-char-counter,.likes-label,#subtitle,.yt-multi-page-menu-section-renderer,.published-time-text,.yta-table-card,.ytcp-trend-label,.metric-value-absolute,#title-placeholder,#toggle.ytd-grid-renderer,#vote-count-middle,.ytcp-omnisearch,.ytcp-table-header,#vote-count-left,#subscribers,#guide-section-title,.content-text,#embed-label,#upnext,.count-text,.ytd-channel-about-metadata-renderer,#title,#subscriber-count,#byline,#content,.view-count,.yt-simple-endpoint,#account-name {color:green!important;}');
  282.  
  283. //////////////play avanti ingrandisci colore rosso
  284. GM_addStyle('path[class=\"ytp-svg-fill\"] { fill: red !important;}');
  285. //volume verde
  286. GM_addStyle('path[class=\"ytp-svg-fill ytp-svg-volume-animation-speaker\"] { fill: green !important;}');
  287.  
  288. //ingranaggio impostazioni
  289. GM_addStyle('path[d=\"m 23.94,18.78 c .03,-0.25 .05,-0.51 .05,-0.78 0,-0.27 -0.02,-0.52 -0.05,-0.78 l 1.68,-1.32 c .15,-0.12 .19,-0.33 .09,-0.51 l -1.6,-2.76 c -0.09,-0.17 -0.31,-0.24 -0.48,-0.17 l -1.99,.8 c -0.41,-0.32 -0.86,-0.58 -1.35,-0.78 l -0.30,-2.12 c -0.02,-0.19 -0.19,-0.33 -0.39,-0.33 l -3.2,0 c -0.2,0 -0.36,.14 -0.39,.33 l -0.30,2.12 c -0.48,.2 -0.93,.47 -1.35,.78 l -1.99,-0.8 c -0.18,-0.07 -0.39,0 -0.48,.17 l -1.6,2.76 c -0.10,.17 -0.05,.39 .09,.51 l 1.68,1.32 c -0.03,.25 -0.05,.52 -0.05,.78 0,.26 .02,.52 .05,.78 l -1.68,1.32 c -0.15,.12 -0.19,.33 -0.09,.51 l 1.6,2.76 c .09,.17 .31,.24 .48,.17 l 1.99,-0.8 c .41,.32 .86,.58 1.35,.78 l .30,2.12 c .02,.19 .19,.33 .39,.33 l 3.2,0 c .2,0 .36,-0.14 .39,-0.33 l .30,-2.12 c .48,-0.2 .93,-0.47 1.35,-0.78 l 1.99,.8 c .18,.07 .39,0 .48,-0.17 l 1.6,-2.76 c .09,-0.17 .05,-0.39 -0.09,-0.51 l -1.68,-1.32 0,0 z m -5.94,2.01 c -1.54,0 -2.8,-1.25 -2.8,-2.8 0,-1.54 1.25,-2.8 2.8,-2.8 1.54,0 2.8,1.25 2.8,2.8 0,1.54 -1.25,2.8 -2.8,2.8 l 0,0 z\"] {fill:#33d79e !important;}');
  290. //mini player
  291. GM_addStyle('path[d=\"M25,17 L17,17 L17,23 L25,23 L25,17 L25,17 Z M29,25 L29,10.98 C29,9.88 28.1,9 27,9 L9,9 C7.9,9 7,9.88 7,10.98 L7,25 C7,26.1 7.9,27 9,27 L27,27 C28.1,27 29,26.1 29,25 L29,25 Z M27,25.02 L9,25.02 L9,10.97 L27,10.97 L27,25.02 L27,25.02 Z\"] {fill:#33d79e !important;}');
  292. //modalita cinema
  293. GM_addStyle('path[d=\"m 28,11 0,14 -20,0 0,-14 z m -18,2 16,0 0,10 -16,0 0,-10 z\"] { fill:#33d79e !important;}');
  294. ////////////////////////////covid
  295. GM_addStyle('ytd-compact-promoted-item-renderer[view-style=COMPACT_PROMOTED_ITEM_STYLE_RICH_GRID] #dismissible.ytd-compact-promoted-item-renderer{display:none !important;}');
  296. ///////////////////time
  297. GM_addStyle('.ytp-time-display{color:lime!important;background:transparent!important;font-size:14px!important;}');
  298. let bar = document.getElementsByClassName("style-scope ytd-searchbox")[0];
  299. let clock = document.createElement("span");
  300. clock.classList.add("ytp-time-display");
  301. clock.innerText = "Toto";
  302. clock.title="Time";
  303.  
  304. function clockTime() {
  305. var today = new Date();
  306. const time = new Date().toLocaleTimeString();
  307. const date = today.toLocaleString('it', {'weekday': 'short', 'month': 'long', 'day': '2-digit','year':'numeric'}); // Aggiungi questa linea per ottenere la data
  308. var milli = today.getMilliseconds();
  309. clock.innerText = time + ":" + milli + " - " + date; // Modifica il formato in base alle tue preferenze
  310. setTimeout(clockTime, 70);
  311. }
  312. clockTime();
  313. bar.insertBefore(clock, bar.childNodes[0]);
  314. //////////////////////////
  315. })();
  316.