-
Notifications
You must be signed in to change notification settings - Fork 0
/
youtube-cookies.js
85 lines (73 loc) · 2.12 KB
/
youtube-cookies.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// ==UserScript==
// @name Reject Youtube Cookies
// @namespace msd.github
// @match https://www.youtube.com/*
// @grant none
// @version 1.0
// @author msd
// @description Skip all the pesky prompts about cookies (clicks "reject all")
// ==/UserScript==
const select_consent_form = '//ytd-consent-bump-v2-lightbox'
const select_consent_form__reject_all_button_1 = '//yt-formatted-string[text()="Reject all"]';
const select_consent_form__reject_all_button_2 = '//button//span[text()="Reject all"]';
const select_consent_form__reject_all_button_last = '//*[text()="Reject all"]';
const INITIAL_DELAY = 500; //< ms
const RETRY_DELAY = 200; //< ms
const MAX_RETRIES = 15;
function xpathArray(xpath, root)
{
if (root === undefined)
{
root = document;
}
let result = document.evaluate(xpath, root);
let a = [];
let e;
while ((e = result.iterateNext()) !== null)
{
a.push(e);
}
return a;
}
let $x = xpathArray; // convenience and convention like web console helper
// $x('.//*[text()="Reject all"]', $('#dialog'))[0].parentElement.parentElement
function clickReject(cform)
{
let method1 = xpathArray(select_consent_form__reject_all_button_1, cform);
if (method1.length !== 0)
{
method1.forEach(e => e.click());
return;
}
let method2 = xpathArray(select_consent_form__reject_all_button_2, cform);
if (method2.length !== 0)
{
method2.forEach(e => e.click());
// if the above doesnt work maybe(?) try clicking the following:
// ../../../button/yt-touch-feedback-shape/div
return;
}
let method3 = xpathArray(select_consent_form__reject_all_button_last, cform);
if (method3.length !== 0)
{
method3.forEach(e => e.click());
return;
}
}
function _main(tries)
{
let cform;
if ((cform = xpathArray(select_consent_form)).length !== 0)
{
cform.forEach(clickReject);
}
else if (tries < MAX_RETRIES)
{
setTimeout(_main, RETRY_DELAY, tries + 1);
}
}
function main()
{
setTimeout(_main, 500, 0);
}
window.addEventListener("load", main);