🌐 delete cookies 🍪

Agrees to the cookies dialog to make it disappear forever except for YouTube where cookies will be rejected thanks to the new function provided by YouTube!

目前为 2022-09-02 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name 🌐 delete cookies 🍪
  3. // @name:fr 🌐 suppression de l'avertissement des cookies 🍪
  4. // @namespace https://greasyfork.org/en/users/876222-zzz-the-hacker
  5. // @version 1.1
  6. // @description Agrees to the cookies dialog to make it disappear forever except for YouTube where cookies will be rejected thanks to the new function provided by YouTube!
  7. // @description:fr Confirme l'acceptation des cookies pour le faire disparaître définitivement sauf pour YouTube où les cookies seront refusés grâce à la nouvelle fonction apportée par YouTube !
  8. // @author zzz le hacker
  9. // @match https://consent.google.*/*
  10. // @match https://www.google.tld/*
  11. // @match https://starve.io/
  12. // @match https://www.google.com
  13. // @match https://www.youtube.com/
  14. // @match https://www.facebook.com/
  15. // @match https://twitter.com/
  16. // @match https://www.instagram.com/
  17. // @match http://www.baidu.com/
  18. // @match https://www.wikipedia.org/
  19. // @match https://www.reddit.com/
  20. // @match https://consent.yahoo.com/v2/collectConsent?sessionId=3_cc-session_83f05cbb-450a-4c64-a23a-bc67eb43a71f
  21. // @match https://yahoo.com/
  22. // @match https://www.amazon.com/
  23. // @match https://www.netflix.com/fr/
  24. // @match https://www.netflix.com/fr-en/
  25. // @match https://www.twitch.tv/
  26. // @match https://www.ebay.com/
  27. // @match https://moomoo.io/
  28. // @match https://diep.io
  29. // @match https://devast.io/
  30. // @match https://slither.io
  31. // @match https://krunker.io/
  32. // @match https://odysee.com/
  33. // @match https://www.amazon.de/
  34. // @match https://www.amazon.fr/
  35. // @match https://www.amazon.nl/
  36. // @match https://www.amazon.it/
  37. // @match https://www.amazon.es/
  38. // @match https://www.amazon.co.uk/
  39. // @match https://truthsocial.com/
  40. // @run-at document-start
  41. // @grant none
  42. // ==/UserScript==
  43.  
  44. (function(){
  45. "use strict";
  46. alert('cookie deleter : actived - agrees (or refuse if you are going to YouTube) to the cookies dialog to make it disappear forever')
  47. if (document.readyState != 'loading') consent();
  48. else document.addEventListener('DOMContentLoaded', consent);
  49.  
  50. function consent() {
  51. var e=document.querySelector('#introAgreeButton');
  52. if (!e) e=document.querySelector('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://consent.google.com/s"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://twitter.com/"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://starve.io/"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://consent.google.*/*"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://www.google.tld/*"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://starve.io/"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://www.google.com"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://www.youtube.com/"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://www.facebook.com/"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://twitter.com/"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://www.instagram.com/"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="http://www.baidu.com/"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://www.wikipedia.org/"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://www.reddit.com/"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://consent.yahoo.com/v2/collectConsent?sessionId=3_cc-session_83f05cbb-450a-4c64-a23a-bc67eb43a71f"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://yahoo.com/"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://www.amazon.com/"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://www.netflix.com/fr/"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://www.netflix.com/fr-en/"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://www.twitch.tv/"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://www.ebay.com/"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://diep.io"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://moomoo.io/"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://devast.io/"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://slither.io"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://krunker.io/"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://odysee.com/"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://truthsocial.com/"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://www.amazon.de/"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://www.amazon.fr/"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://www.amazon.nl/"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://www.amazon.it/"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://www.amazon.es/"] button');('div.jw8mI button#zV9nZe.tHlp8d, div.VDity button#L2AGLb.tHlp8d, form[action="https://www.amazon.co.uk/"] button');
  53. e && e.click();
  54. }
  55.  
  56. var t, e=r.querySelector('#introAgreeButton')
  57. || ( (t=r.querySelectorAll('#lightbox[class*="ytd-consent-bump"] a.ytd-button-renderer:not([href])')) && (t.length==1) && (e=t[0]) )
  58. || ( (t=r.querySelectorAll('form button')) && (t.length == 1) && (e=t[0]) )
  59. || ( (t=r.querySelectorAll(':scope form button')) && (t.length == 4) && (e=t[1]) ) /*20220524*/
  60. || ( (t=r.querySelectorAll('ytd-button-renderer > a:not([href]) tp-yt-paper-button[class*="primary"]')) && (t.length == 1) && (e=t[0]) )
  61. || ( (t=r.querySelectorAll('ytd-button-renderer > a:not([href]) tp-yt-paper-button[class*="primary"]')) && (t.length == 2) && (e=t[0]) );
  62. e && e.click();
  63.  
  64. if (location.href.startsWith('https://consent.youtube.com/')) {
  65. if (document.readyState != 'loading') consent();
  66. else document.addEventListener('DOMContentLoaded', consent);
  67. return;
  68. }
  69.  
  70. if (window !== window.top) return;
  71.  
  72. function cookies() {
  73. var r={}, a=document.cookie;
  74. a.split(';').forEach(function(e){
  75. var p=e.split('=');
  76. if (p[0]) r[p.shift().trim()]=p.join('=');
  77. });
  78. return r;
  79. }
  80.  
  81. var ck=cookies();
  82. if (ck['APISID']) return;
  83.  
  84. function hasDismiss(e, l=1) {
  85. var p=e;
  86. while (p && l-- && (p=p.parentNode)) {
  87. if (p.id=='dismiss-button') return p;
  88. }
  89. }
  90.  
  91. function SImutF(mutL){
  92. for (let mut of mutL) {
  93. let t=mut.target, db=t;
  94. if ( (t.id=='dismiss-button') || (db=hasDismiss(t,2)) ) {
  95. if (db.__c__) continue;
  96. if (t.classList.contains('yt-upsell-dialog-renderer') || t.classList.contains('ytd-mealbar-promo-renderer')) ;
  97. else if (t.classList.contains('yt-tooltip-renderer')) {
  98. t=t.querySelector('yt-button-renderer');
  99. if (!t) continue;
  100. }
  101. else continue;
  102. db.__c__=true;
  103. setTimeout(function(){
  104. t.click();
  105. delete db.__c__;
  106. }, 300);
  107. subObs.observe(t,{attributes: true, subtree: true});
  108. }
  109. }
  110. }
  111. var obs=new MutationObserver(SImutF);
  112. var subObs=new MutationObserver(SImutF);
  113. var obs_w4PU=new MutationObserver(function(mutL){
  114. for (let mut of mutL) {
  115. for (let n of mut.addedNodes) {
  116. if (n.nodeName == 'YTD-POPUP-CONTAINER') {
  117. this.disconnect();
  118. setObs();
  119. return;
  120. }
  121. }
  122. }
  123. });
  124. var obs_w4ErRd=new MutationObserver(function(mutL){
  125. for (let mut of mutL) {
  126. for (let n of mut.addedNodes) {
  127. if (n.id == 'columns') {
  128. let r=n.querySelector('yt-playability-error-supported-renderers');
  129. if (r) {
  130. this.disconnect();
  131. setErRdObs();
  132. return;
  133. }
  134. }
  135. }
  136. }
  137. });
  138. var obsCk=new MutationObserver(function(mutL){
  139. var cb;
  140. for (let mut of mutL) {
  141. for (let n of mut.addedNodes) {
  142. if (n.nodeName == 'TP-YT-IRON-OVERLAY-BACKDROP') {
  143. cb=document.querySelector('#lightbox');
  144. consent();
  145. }
  146. if ( (n.nodeName == 'YTD-CONSENT-BUMP-LIGHTBOX') || (n=cb) ) {
  147. this.disconnect();
  148. setTimeout(function(){
  149. let ck=cookies();
  150. if (ck['CONSENT'] && !ck['CONSENT'].startsWith('YES')) document.cookie='CONSENT=YES+;path=/;secure;domain=youtube.com;expires='+(new Date(Date.now()+567648000000)).toUTCString()+';';
  151. }, 5000);
  152. // not an iframe anymore
  153. consent(null,n);
  154. return;
  155. }
  156. }
  157. }
  158. });
  159.  
  160. var ErRd, ErRdIT,
  161. obsErRd=new MutationObserver(function(mutL){
  162. var t, ITc=30;
  163. for (let mut of mutL) {
  164. t=mut.target;
  165. if (t.id=='dismiss-button') {
  166. if (t.classList.contains('yt-player-error-message-renderer')) t=t.querySelector(':scope yt-button-renderer paper-button#button');
  167. else continue;
  168. if (ErRdIT) clearInterval(ErRdIT);
  169. ErRdIT=setInterval(function(){
  170. if (!ITc-- || ErRd.hidden || !t) {
  171. clearInterval(ErRdIT);
  172. ErRdIT=0;
  173. }
  174. else t.click();
  175. }, 300);
  176. return;
  177. }
  178. }
  179. });
  180.  
  181. function init() {
  182. var t;
  183. if (document.querySelector('ytm-app')) {
  184. new MutationObserver(function(mutL){
  185. for (let mut of mutL) {
  186. for (let n of mut.addedNodes) {
  187. if (n.classList.contains('upsell-dialog-lightbox') || n.classList.contains('consent-bump-lightbox') ) {
  188. if (t=document.querySelector('.upsell-dialog-dismiss-button button, .consent-bump-button-wrapper button')) {
  189. t.click();
  190. }
  191. }
  192. }
  193. }
  194. }).observe(document.body, {childList: true, subtree: false});
  195. }
  196.  
  197. setObs();
  198. setErRdObs();
  199. if (ck['CONSENT'] && !ck['CONSENT'].startsWith('YES')) {
  200. obsCk.observe(document.body, {childList:true});
  201. setTimeout(function(){obsCk.disconnect();},30000);
  202. }
  203. }
  204.  
  205. var c=1;
  206. function setObs(){
  207. var r=document.querySelector('ytd-app ytd-popup-container');
  208. if (!r) {
  209. if (c--) obs_w4PU.observe(document.querySelector('ytd-app'), {childList:true});
  210. return;
  211. }
  212. obs.observe(r, {childList: true, subtree: true});
  213. }
  214.  
  215. function setErRdObs() {
  216. ErRd=document.querySelector('ytd-app yt-playability-error-supported-renderers');
  217. if (!ErRd) {
  218. obs_w4ErRd.observe(document.querySelector('ytd-app'), {childList: true, subtree: true});
  219. setTimeout(function(){obs_w4ErRd.disconnect();}, 20000);
  220. }
  221. else obsErRd.observe(ErRd ,{childList: true, subtree: true, attributes: true});
  222. }
  223.  
  224. if (document.readyState != 'loading') init();
  225. else document.addEventListener('DOMContentLoaded', init);
  226.  
  227. function inject() {
  228.  
  229. var r=document.head || document.documentElement;
  230. if (!r) {
  231. setTimeout(inject,0);
  232. return;
  233. }
  234.  
  235. var s=document.createElement('style');
  236. r.appendChild(s);
  237. s.textContent="#consent-bump,iron-overlay-backdrop,yt-upsell-dialog-renderer{opacity:0;}yt-upsell-dialog-renderer *,yt-bubble-hint-renderer,.upsell-dialog-lightbox,.consent-bump-lightbox{display:none !important;}ytd-app > ytd-consent-bump-lightbox,ytd-app > ytd-consent-bump-v2-lightbox,ytd-app ~ iron-overlay-backdrop,ytd-app ~ tp-yt-iron-overlay-backdrop{display:none;}";
  238.  
  239. s=document.createElement('script');
  240. s.textContent= `(function(){var c=160, pl, plR, prom, oldp={}, t, done, hasPaused;
  241.  
  242. const obs=new MutationObserver(function(mutL){
  243. if (!prom) {
  244. if (prom=document.querySelector('ytd-player#ytd-player') ) {
  245. if (prom.getPlayerPromise) {
  246. prom.getPlayerPromise().then(function(a){
  247. pl=a;
  248. patch();
  249. });
  250. }
  251. else prom=null;
  252. }
  253. }
  254.  
  255. for (let mut of mutL) {
  256. for (let n of mut.addedNodes) {
  257. if (n.id == 'movie_player') {
  258. plR=n.closest('ytd-player#ytd-player');
  259. if (!plR) continue;
  260. this.disconnect();
  261. setTimeout(function(){
  262. pl=plR.getPlayer();
  263. patch();
  264. }, 0);
  265. return;
  266. }
  267. }
  268. }
  269. });
  270.  
  271. function init(){
  272. obs.observe(document.querySelector('ytd-app') || document.body, {childList: true, subtree: true});
  273. setTimeout(function(){obs.disconnect();},10000);
  274. f();
  275. }
  276.  
  277. function f(){
  278. plR=document.querySelector('ytd-player#ytd-player');
  279. if (plR) pl=plR.getPlayer();
  280.  
  281. if (!pl) {
  282. if (--c) setTimeout(f,100);
  283. return;
  284. }
  285. else patch();
  286. }
  287. if (document.readyState != 'loading') init();
  288. else document.addEventListener('DOMContentLoaded', init);
  289.  
  290. function patch() {
  291. if (done) return;
  292. if (pl) done=1;
  293. obs.disconnect();
  294. for (let i in pl) if (typeof pl[i] == 'function') {
  295. if ( !['cancelPlayback', 'pauseVideo', 'stopVideo', 'playVideo'].includes(i) ) continue;
  296. oldp[i]=pl[i];
  297. pl[i]=function() {
  298. let pass= (!hasPaused && i=='playVideo') ? true:false;
  299. let st=(new Error()).stack;
  300. if ( !pass && (st.search(/(\\.onFulfilled|_onFulfilled|scheduler\\.js:|handlePopupClose_)/)>0) && (st.search(/onYtStopOldPlayer/) ==-1) ) {
  301. if (i=='pauseVideo') hasPaused=1;
  302. return;
  303. }
  304. oldp[i].apply(this,arguments);
  305. }
  306. }
  307. }
  308. })();`;
  309.  
  310. r.appendChild(s);
  311. if (s.parentNode) s.parentNode.removeChild(s);
  312.  
  313. } // inject()
  314.  
  315. inject();
  316. })();