Youtube Dark figuccio

youtube dark mode stop riproduzione autom

  1. // ==UserScript==
  2. // @name Youtube Dark figuccio
  3. // @namespace https://greasyfork.org/users/237458
  4. // @version 13.5
  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. // @icon https://www.youtube.com/s/desktop/3748dff5/img/favicon_48.png
  15. // @grant GM_registerMenuCommand
  16. // @license MIT
  17. // ==/UserScript==
  18. (function () {
  19. 'use strict';
  20. /////////////////////time
  21. let timeout;
  22. let videoElement;
  23.  
  24. // Crea un div contenitore
  25. const containerDiv = document.createElement("div");
  26. containerDiv.style.cssText = `position:fixed;top:10px;right:10px;display:flex;align-items:center;z-index:999999999;`;
  27.  
  28. //Crea un div rettangolare arrotondato che visualizza l'ora
  29. const timeDiv = document.createElement("div");
  30. timeDiv.title="Data-ora";
  31. timeDiv.style.cssText = `
  32. background-color: rgba(0, 0, 0, 0.5);
  33. color:lime;
  34. font-size:15px;
  35. padding: 5px;
  36. border-radius: 5px;
  37. cursor: pointer;
  38. font-family: "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  39. font-weight: bold;
  40. border:2px solid green;
  41. `;
  42.  
  43. containerDiv.appendChild(timeDiv);//orologio
  44.  
  45. function initialize() {
  46. updateTime();
  47. }
  48.  
  49. function updateTime() {
  50. findvideo(); // Emette il valore di videoElement
  51. const now = new Date();
  52. //data
  53. const date = new Date().toLocaleString('it', {'weekday': 'short', 'month': 'long', 'day': '2-digit','year':'numeric'});
  54. /////////////////////ore-minuti-sec-millisec
  55. const time = new Date().toLocaleTimeString();
  56. const sss = new Date().getMilliseconds();
  57.  
  58. timeDiv.textContent =date +" - "+ time +":"+ sss;//giorno-mese-anno h m s
  59. setTimeout(updateTime, 200);//Continua ad aggiornare l'ora 1000 /200 ms
  60. }
  61.  
  62. // Scatta nell'angolo in alto a destra del video
  63. function stickToTopRight() {
  64. if (videoElement) {
  65. // Ottieni le informazioni sulle dimensioni e sulla posizione del lettore video
  66. const videoRect = videoElement.getBoundingClientRect();
  67. // Imposta la posizione del div contenitore, fissata nell'angolo in alto a destra
  68. containerDiv.style.top = `${videoRect.top + 10}px`;
  69. containerDiv.style.right = `${document.documentElement.clientWidth - videoRect.right + 10}px`;
  70. }
  71. }
  72.  
  73. // Aggiorna la posizione del div contenitore e mantienilo fisso quando la finestra del video viene ridimensionata o viene visualizzata a schermo intero
  74. function updatePosition() {
  75. stickToTopRight();
  76. setTimeout(updatePosition, 500); // Aggiorna la posizione ogni 0,5 secondi 500
  77. }
  78.  
  79. function findvideo() {
  80. if (window.location.href.includes("www.bilibili.com/video/")) {
  81. videoElement = document.querySelector("bwp-video");
  82. if (!videoElement) {
  83. videoElement = document.querySelector("video");
  84. if (0 == (new Date().getSeconds() % 2)) console.log("222:" + videoElement);
  85. }
  86. else if (0 == (new Date().getSeconds() % 2)) console.log("111:" + videoElement);
  87. } else {
  88. videoElement = document.querySelector("video");
  89. if (0 == (new Date().getSeconds() % 2)) console.log("222:" + videoElement);
  90. }
  91. if (null == videoElement) {
  92. containerDiv.style.display = "none";
  93. }
  94. else {
  95. containerDiv.style.display = "flex";
  96. }
  97.  
  98. }
  99.  
  100. // Monitora le modifiche dello stato a schermo intero e aggiungi il div contenitore al livello a schermo intero
  101. function handleFullscreenChange() {
  102. if (document.fullscreenElement) {
  103. // Aggiungi il div contenitore all'elemento a schermo intero quando accedi a schermo intero
  104. document.fullscreenElement.appendChild(containerDiv);
  105. } else {
  106. // Aggiungi nuovamente il div contenitore alla pagina quando esci dalla modalità a schermo intero
  107. document.body.appendChild(containerDiv);
  108. }
  109.  
  110. }
  111.  
  112. // Chiama le funzioni di inizializzazione e aggiornamento della posizione per avviarne l'aggiornamento in tempo reale
  113. initialize();
  114. updatePosition();
  115.  
  116. // Aggiungi il div contenitore alla pagina
  117. document.body.appendChild(containerDiv);
  118.  
  119. // Ascolta gli eventi di modifica dello stato a schermo intero
  120. document.addEventListener("fullscreenchange", handleFullscreenChange);
  121. // Funzione per fare clic sul pulsante "Accetta" dei cookie e impostare le preferenze marzo 2024
  122. function accettaCookieEImpostaPreferenze() {
  123. var accettaButton = document.querySelector("#content > div.body.style-scope.ytd-consent-bump-v2-lightbox > div.eom-buttons.style-scope.ytd-consent-bump-v2-lightbox > div:nth-child(1) > ytd-button-renderer:nth-child(2) > yt-button-shape > button > yt-touch-feedback-shape > div > div.yt-spec-touch-feedback-shape__fill");
  124. if (accettaButton) {
  125. accettaButton.click(); // Fai clic sul pulsante "Accetta"
  126. console.log("Pulsante 'Accetta' dei cookie su YouTube cliccato!");
  127.  
  128. // Imposta i cookie per le preferenze
  129. document.cookie ="PREF=f6=40000400&f7=140;domain=.youtube.com"; // Imposta il tema scuro, l'illuminazione cinematografica disattivata, ecc.
  130. console.log("Preferenze impostate!");
  131. } else {
  132. console.log("Pulsante 'Accetta' dei cookie su YouTube non trovato.");
  133. }
  134. }
  135.  
  136. // Attendi che il documento sia completamente caricato prima di fare clic sul pulsante e impostare le preferenze
  137. window.addEventListener('load', function() {
  138. setTimeout(accettaCookieEImpostaPreferenze, 3000); // Imposta un ritardo di 3 secondi prima di fare clic sul pulsante e impostare le preferenze (modificabile a seconda delle esigenze)
  139. });
  140. ////////////////////////mostra % volume/////
  141. let previousVolume = -1;
  142. function displaySquareVolume() {
  143. const player = document.getElementById('movie_player');
  144. const currentVolume = player.getVolume();
  145.  
  146. if (currentVolume !== previousVolume) {
  147. previousVolume = currentVolume;
  148. const squareVolume = document.querySelectorAll('div[data-layer="4"]');
  149. squareVolume.forEach((div) => {
  150. if(div.className === 'ytp-bezel-text-hide') {
  151. div.classList.remove('ytp-bezel-text-hide');
  152. }
  153. if (div.classList.length === 0) {
  154. const ytpBezelTextWrapper = div.querySelector('.ytp-bezel-text-wrapper');
  155. ytpBezelTextWrapper.title="Volume";
  156. const ytpBezelText = ytpBezelTextWrapper.querySelector('.ytp-bezel-text');
  157. const ytpBezel = div.querySelector('.ytp-bezel');
  158. div.style.display = 'block';
  159.  
  160. if (ytpBezelText && ytpBezel) {
  161. ytpBezelText.innerText = currentVolume + "%";
  162. ytpBezel.style.display = 'none';
  163. }
  164.  
  165. setTimeout(()=> {
  166. div.style.display = 'none';
  167. }, 20000);//resta fisso per 20 secondi
  168. }
  169. });
  170. }
  171. }
  172.  
  173. function checkVideoExists() {
  174. const videoElement = document.querySelector('video');
  175. if (videoElement) {
  176. videoElement.addEventListener('volumechange', displaySquareVolume);
  177. previousVolume = videoElement.volume * 100;
  178. }
  179. }
  180.  
  181. const observer = new MutationObserver(checkVideoExists);
  182. const body = document.body;
  183. const config = {childList: true, subtree: true};
  184. observer.observe(body, config);
  185. GM_addStyle('.ytp-bezel-text-wrapper{color:green;cursor:pointer;}');//% volume colore verde
  186. /////////////////////////riproduzione automatica disattivata
  187. document.addEventListener('yt-navigate-finish', () => {
  188. // Il codice sarà eseguito solo sulle pagine www.youtube.com/watch?v
  189. if (!window.location.href.includes("watch")) return;
  190. var i = window.setInterval(() => {
  191. const t = document.getElementsByClassName('ytp-autonav-toggle-button')[0];
  192. if (t.getAttribute('aria-checked') === "true") {
  193. t.click();
  194. clearInterval(i); // Interrompe il loop quando la riproduzione automatica è disattivata
  195. }
  196. }, 1000);
  197. });
  198. /////////////////////barra volume video sempre visibile
  199. GM_addStyle('.ytp-volume-panel {width:52px!important;}');
  200. GM_addStyle('.ytp-volume-slider-handle:before {background:green!important;}');//linea volume verde
  201. GM_addStyle('.ytp-volume-slider-handle {background:red!important;}');//pallino volume
  202. //////////////////////////////////
  203. //shorts e tendenze
  204. GM_addStyle('#dismissible.ytd-rich-shelf-renderer {display:none!important;}');
  205. //Rimuovi Youtube Commenti
  206. GM_addStyle('ytd-comments.style-scope{ display:none !important;}');
  207. //adblock grosso banner youtube premium
  208. GM_addStyle(`#masthead-ad { display:none!important;}`);
  209.  
  210. //promemoria privacy
  211. document.cookie = "HideTicker=true;domain=.youtube.com;max-age=315360000";
  212. //annotazioni video
  213. GM_addStyle(`.html5-video-player .ytp-cards-button{display:none!important;}`);
  214. //popup non hai eseguito laccesso
  215. GM_addStyle(`yt-tooltip-renderer{display:none!important;}`);
  216. ///////////rimuove scritta consigliati allinterno video
  217. GM_addStyle('.ytp-cards-teaser-label{display:none !important;}');
  218. ///////////icome home ecc e titoli home tendenze ecc
  219. GM_addStyle('.title,.pieSegment,svg {color:#5f84f1 !important;}');
  220. //scrittura verde
  221. 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;}');
  222.  
  223. //////////////play avanti ingrandisci colore rosso
  224. GM_addStyle('path[class=\"ytp-svg-fill\"] { fill: red !important;}');
  225. //volume verde
  226. GM_addStyle('path[class=\"ytp-svg-fill ytp-svg-volume-animation-speaker\"] { fill: green !important;}');
  227.  
  228. //ingranaggio impostazioni
  229. 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;}');
  230. //mini player
  231. 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;}');
  232. //modalita cinema
  233. 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;}');
  234. ////////////////////////////covid
  235. GM_addStyle('ytd-compact-promoted-item-renderer[view-style=COMPACT_PROMOTED_ITEM_STYLE_RICH_GRID] #dismissible.ytd-compact-promoted-item-renderer{display:none !important;}');
  236. ////////////time
  237. // Salva la posizione nel local storage
  238. function savePosition(left, top) {
  239. GM_setValue('clockPosition', JSON.stringify({ left: left, top: top }));
  240. }
  241.  
  242. // Recupera la posizione dal local storage
  243. function loadPosition() {
  244. let position = GM_getValue('clockPosition');
  245. return position ? JSON.parse(position) : { left: '200px', top: '10px' };
  246. }
  247.  
  248. // Crea l'elemento dell'orologio
  249. var clock = document.createElement('div');
  250. clock.style.position = 'fixed';
  251. clock.style.fontSize = '15px';
  252. clock.style.cursor = 'pointer';
  253. clock.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
  254. clock.style.color = 'lime';
  255. clock.style.padding = '5px';
  256. clock.style.borderRadius = '5px';
  257. clock.style.zIndex = '9000';
  258. document.body.appendChild(clock);
  259.  
  260. // Imposta la posizione iniziale
  261. let initialPosition = loadPosition();
  262. clock.style.left = initialPosition.left;
  263. clock.style.top = initialPosition.top;
  264.  
  265. // Funzione per aggiornare l'orologio
  266. function updateClock() {
  267. var now = new Date();
  268. var hours = String(now.getHours()).padStart(2, '0');
  269. var minutes = String(now.getMinutes()).padStart(2, '0');
  270. var seconds = String(now.getSeconds()).padStart(2, '0');
  271. var milliseconds = String(now.getMilliseconds()).padStart(3, '0');
  272. clock.textContent = `${hours}:${minutes}:${seconds}:${milliseconds}`;
  273. }
  274.  
  275. // Aggiorna l'orologio ogni 90 millisecondi
  276. setInterval(updateClock, 90);
  277.  
  278. // Aggiungi la data al passaggio del mouse
  279. clock.addEventListener('mouseenter', function() {
  280. let currentDate = new Date();
  281. clock.setAttribute('title', currentDate.toLocaleDateString('it', { day: '2-digit', month: 'long', weekday: 'long', year: 'numeric' }));
  282. });
  283.  
  284. // Funzioni per rendere l'orologio dragabile con limiti
  285. clock.addEventListener('mousedown', function(e) {
  286. var offsetX = e.clientX - parseInt(clock.style.left);
  287. var offsetY = e.clientY - parseInt(clock.style.top);
  288.  
  289. function mouseMoveHandler(e) {
  290. var newLeft = e.clientX - offsetX;
  291. var newTop = e.clientY - offsetY;
  292.  
  293. // Limiti per il trascinamento
  294. var minLeft = 0;
  295. var maxLeft = window.innerWidth - clock.offsetWidth- 10; // Aggiunto margine di sicurezza impedisce che millisecondi escano fuori schermo se lo sposti a left
  296. var minTop = 0;
  297. var maxTop = window.innerHeight - clock.offsetHeight;
  298.  
  299. // Applicare i limiti
  300. if (newLeft < minLeft) newLeft = minLeft;
  301. if (newLeft > maxLeft) newLeft = maxLeft; // Impedisce al testo di uscire dallo schermo
  302. if (newTop < minTop) newTop = minTop;
  303. if (newTop > maxTop) newTop = maxTop;
  304.  
  305. clock.style.left = newLeft + 'px';
  306. clock.style.top = newTop + 'px';
  307. savePosition(clock.style.left, clock.style.top);
  308. }
  309.  
  310. function reset() {
  311. document.removeEventListener('mousemove', mouseMoveHandler);
  312. document.removeEventListener('mouseup', reset);
  313. }
  314.  
  315. document.addEventListener('mousemove', mouseMoveHandler);
  316. document.addEventListener('mouseup', reset);
  317. });
  318.  
  319. ///////////////////////////////////////////autochiude menu guide button
  320. function minimizeSidebarIfOpened() {
  321. var guide = document.getElementById('guide');
  322. var menuButton = document.querySelector('#guide-icon.ytd-masthead');
  323. if (guide && guide.getAttribute('opened') !== null && menuButton) {
  324. menuButton.click();
  325. }
  326. }
  327.  
  328. var intervalId = setInterval(minimizeSidebarIfOpened, 2000);
  329.  
  330. // Cancella l'intervallo quando non è più necessario
  331. function clearIntervalIfSidebarClosed() {
  332. var guide = document.getElementById('guide');
  333. var menuButton = document.querySelector('#guide-icon.ytd-masthead');
  334. if ((!guide || guide.getAttribute('opened') === null) && menuButton) {
  335. clearInterval(intervalId);
  336. }
  337. }
  338.  
  339. // Controlla se è necessario cancellare l'intervallo ogni 5 secondi
  340. setInterval(clearIntervalIfSidebarClosed, 5000);
  341. })();