Skip to content

Instantly share code, notes, and snippets.

@luetage
Last active September 21, 2022 13:56
Show Gist options
  • Save luetage/b9a34552a6abf48f992b2effabcbff80 to your computer and use it in GitHub Desktop.
Save luetage/b9a34552a6abf48f992b2effabcbff80 to your computer and use it in GitHub Desktop.
Automatically reject cookies on consent dialog.
// ==UserScript==
// @name YouTube Reject Cookies
// @namespace https://gist.github.com/luetage/b9a34552a6abf48f992b2effabcbff80
// @updateURL https://gist.github.com/luetage/b9a34552a6abf48f992b2effabcbff80/raw
// @description Automatically reject cookies on consent dialog.
// @version 2022.9.9
// @author luetage
// @match https://www.youtube.com/*
// @run-at document-start
// ==/UserScript==
(function () {
"use strict";
function reject(mutations) {
mutations.forEach((mutation) => {
mutation.addedNodes.forEach((node) => {
if (node.id === "button") {
const btn = document.querySelector(
"[aria-label='Reject the use of cookies and other data for the purposes described']"
);
if (btn) btn.click();
}
});
});
}
window.onload = () => {
const selfdestruct = new MutationObserver(reject);
selfdestruct.observe(document.body, { childList: true, subtree: true });
setTimeout(() => {
selfdestruct.disconnect();
}, 7000);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment