Greasy Fork is available in English.

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.4
  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. //setTimeout(function(){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").click();}, 1500);
  141. ////////////////////////mostra % volume/////
  142. let previousVolume = -1;
  143. function displaySquareVolume() {
  144. const player = document.getElementById('movie_player');
  145. const currentVolume = player.getVolume();
  146.  
  147. if (currentVolume !== previousVolume) {
  148. previousVolume = currentVolume;
  149. const squareVolume = document.querySelectorAll('div[data-layer="4"]');
  150. squareVolume.forEach((div) => {
  151. if(div.className === 'ytp-bezel-text-hide') {
  152. div.classList.remove('ytp-bezel-text-hide');
  153. }
  154. if (div.classList.length === 0) {
  155. const ytpBezelTextWrapper = div.querySelector('.ytp-bezel-text-wrapper');
  156. ytpBezelTextWrapper.title="Volume";
  157. const ytpBezelText = ytpBezelTextWrapper.querySelector('.ytp-bezel-text');
  158. const ytpBezel = div.querySelector('.ytp-bezel');
  159. div.style.display = 'block';
  160.  
  161. if (ytpBezelText && ytpBezel) {
  162. ytpBezelText.innerText = currentVolume + "%";
  163. ytpBezel.style.display = 'none';
  164. }
  165.  
  166. setTimeout(()=> {
  167. div.style.display = 'none';
  168. }, 20000);//resta fisso per 20 secondi
  169. }
  170. });
  171. }
  172. }
  173.  
  174. function checkVideoExists() {
  175. const videoElement = document.querySelector('video');
  176. if (videoElement) {
  177. videoElement.addEventListener('volumechange', displaySquareVolume);
  178. previousVolume = videoElement.volume * 100;
  179. }
  180. }
  181.  
  182. const observer = new MutationObserver(checkVideoExists);
  183. const body = document.body;
  184. const config = {childList: true, subtree: true};
  185. observer.observe(body, config);
  186. GM_addStyle('.ytp-bezel-text-wrapper{color:green;cursor:pointer;}');//% volume colore verde
  187. /////////////////////////riproduzione automatica disattivata
  188. document.addEventListener('yt-navigate-finish', () => {
  189. // Il codice sarà eseguito solo sulle pagine www.youtube.com/watch?v
  190. if (!window.location.href.includes("watch")) return;
  191. var i = window.setInterval(() => {
  192. const t = document.getElementsByClassName('ytp-autonav-toggle-button')[0];
  193. if (t.getAttribute('aria-checked') === "true") {
  194. t.click();
  195. clearInterval(i); // Interrompe il loop quando la riproduzione automatica è disattivata
  196. }
  197. }, 1000);
  198. });
  199. /////////////////////barra volume video sempre visibile
  200. GM_addStyle('.ytp-volume-panel {width:52px!important;}');
  201. GM_addStyle('.ytp-volume-slider-handle:before {background:green!important;}');//linea volume verde
  202. GM_addStyle('.ytp-volume-slider-handle {background:red!important;}');//pallino volume
  203. //////////////////////////////////
  204. //shorts e tendenze
  205. GM_addStyle('#dismissible.ytd-rich-shelf-renderer {display:none!important;}');
  206. //Rimuovi Youtube Commenti
  207. GM_addStyle('ytd-comments.style-scope{ display:none !important;}');
  208. //adblock grosso banner youtube premium
  209. GM_addStyle(`#masthead-ad { display:none!important;}`);
  210.  
  211. //promemoria privacy
  212. document.cookie = "HideTicker=true;domain=.youtube.com;max-age=315360000";
  213. //annotazioni video
  214. GM_addStyle(`.html5-video-player .ytp-cards-button{display:none!important;}`);
  215. //popup non hai eseguito laccesso
  216. GM_addStyle(`yt-tooltip-renderer{display:none!important;}`);
  217. ///////////rimuove scritta consigliati allinterno video
  218. GM_addStyle('.ytp-cards-teaser-label{display:none !important;}');
  219. ///////////icome home ecc e titoli home tendenze ecc
  220. GM_addStyle('.title,.pieSegment,svg {color:#5f84f1 !important;}');
  221. //scrittura verde
  222. 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;}');
  223.  
  224. //////////////play avanti ingrandisci colore rosso
  225. GM_addStyle('path[class=\"ytp-svg-fill\"] { fill: red !important;}');
  226. //volume verde
  227. GM_addStyle('path[class=\"ytp-svg-fill ytp-svg-volume-animation-speaker\"] { fill: green !important;}');
  228.  
  229. //ingranaggio impostazioni
  230. 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;}');
  231. //mini player
  232. 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;}');
  233. //modalita cinema
  234. 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;}');
  235. ////////////////////////////covid
  236. GM_addStyle('ytd-compact-promoted-item-renderer[view-style=COMPACT_PROMOTED_ITEM_STYLE_RICH_GRID] #dismissible.ytd-compact-promoted-item-renderer{display:none !important;}');
  237. ////////////time
  238. // Salva la posizione nel local storage
  239. function savePosition(left, top) {
  240. GM_setValue('clockPosition', JSON.stringify({ left: left, top: top }));
  241. }
  242.  
  243. // Recupera la posizione dal local storage
  244. function loadPosition() {
  245. let position = GM_getValue('clockPosition');
  246. return position ? JSON.parse(position) : { left: '200px', top: '10px' };
  247. }
  248.  
  249. // Crea l'elemento dell'orologio
  250. var clock = document.createElement('div');
  251. clock.style.position = 'fixed';
  252. clock.style.fontSize = '15px';
  253. clock.style.cursor = 'pointer';
  254. clock.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
  255. clock.style.color = 'lime';
  256. clock.style.padding = '5px';
  257. clock.style.borderRadius = '5px';
  258. clock.style.zIndex = '9000';
  259. document.body.appendChild(clock);
  260.  
  261. // Imposta la posizione iniziale
  262. let initialPosition = loadPosition();
  263. clock.style.left = initialPosition.left;
  264. clock.style.top = initialPosition.top;
  265.  
  266. // Funzione per aggiornare l'orologio
  267. function updateClock() {
  268. var now = new Date();
  269. var hours = String(now.getHours()).padStart(2, '0');
  270. var minutes = String(now.getMinutes()).padStart(2, '0');
  271. var seconds = String(now.getSeconds()).padStart(2, '0');
  272. var milliseconds = String(now.getMilliseconds()).padStart(3, '0');
  273. clock.textContent = `${hours}:${minutes}:${seconds}:${milliseconds}`;
  274. }
  275.  
  276. // Aggiorna l'orologio ogni 90 millisecondi
  277. setInterval(updateClock, 90);
  278.  
  279. // Aggiungi la data al passaggio del mouse
  280. clock.addEventListener('mouseenter', function() {
  281. let currentDate = new Date();
  282. clock.setAttribute('title', currentDate.toLocaleDateString('it', { day: '2-digit', month: 'long', weekday: 'long', year: 'numeric' }));
  283. });
  284.  
  285. // Funzioni per rendere l'orologio dragabile con limiti
  286. clock.addEventListener('mousedown', function(e) {
  287. var offsetX = e.clientX - parseInt(clock.style.left);
  288. var offsetY = e.clientY - parseInt(clock.style.top);
  289.  
  290. function mouseMoveHandler(e) {
  291. var newLeft = e.clientX - offsetX;
  292. var newTop = e.clientY - offsetY;
  293.  
  294. // Limiti per il trascinamento
  295. var minLeft = 0;
  296. var maxLeft = window.innerWidth - clock.offsetWidth;
  297. var minTop = 0;
  298. var maxTop = window.innerHeight - clock.offsetHeight;
  299.  
  300. // Applicare i limiti
  301. if (newLeft < minLeft) newLeft = minLeft;
  302. if (newLeft > maxLeft) newLeft = maxLeft;
  303. if (newTop < minTop) newTop = minTop;
  304. if (newTop > maxTop) newTop = maxTop;
  305.  
  306. clock.style.left = newLeft + 'px';
  307. clock.style.top = newTop + 'px';
  308. savePosition(clock.style.left, clock.style.top);
  309. }
  310.  
  311. function reset() {
  312. document.removeEventListener('mousemove', mouseMoveHandler);
  313. document.removeEventListener('mouseup', reset);
  314. }
  315.  
  316. document.addEventListener('mousemove', mouseMoveHandler);
  317. document.addEventListener('mouseup', reset);
  318. });
  319.  
  320. ///////////////////////////////////////////autochiude menu guide button
  321. function minimizeSidebarIfOpened() {
  322. var guide = document.getElementById('guide');
  323. var menuButton = document.querySelector('#guide-icon.ytd-masthead');
  324. if (guide && guide.getAttribute('opened') !== null && menuButton) {
  325. menuButton.click();
  326. }
  327. }
  328.  
  329. var intervalId = setInterval(minimizeSidebarIfOpened, 2000);
  330.  
  331. // Cancella l'intervallo quando non è più necessario
  332. function clearIntervalIfSidebarClosed() {
  333. var guide = document.getElementById('guide');
  334. var menuButton = document.querySelector('#guide-icon.ytd-masthead');
  335. if ((!guide || guide.getAttribute('opened') === null) && menuButton) {
  336. clearInterval(intervalId);
  337. }
  338. }
  339.  
  340. // Controlla se è necessario cancellare l'intervallo ogni 5 secondi
  341. setInterval(clearIntervalIfSidebarClosed, 5000);
  342. })();