-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinject.js
31 lines (31 loc) · 1.04 KB
/
inject.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
(function () {
console.log("accept-cookies: overriding attachShadow");
const acceptCookiesOrigAttachShadow = Element.prototype.attachShadow;
let shadowEvents = [];
let seenContentScript = false;
window.addEventListener("acceptCookiesReady", () => {
console.log("accept-cookies: saw ready event");
seenContentScript = true;
shadowEvents.forEach((e) => document.dispatchEvent(e));
shadowEvents = [];
});
Element.prototype.attachShadow = function (options = {}) {
options.mode = "open";
const shadowDom = acceptCookiesOrigAttachShadow.call(this, options);
let selector = this.nodeName.toLowerCase();
if (this.id) {
selector += "#" + this.id;
} else if (this.className) {
selector += "." + this.className.trim().replace(/\s+/g, ".");
}
const attachShadow = new CustomEvent("acceptCookiesAttachShadow", {
detail: selector,
});
if (seenContentScript) {
document.dispatchEvent(attachShadow);
} else {
shadowEvents.push(attachShadow);
}
return shadowDom;
};
})();