-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent-script.js
More file actions
115 lines (108 loc) · 3.68 KB
/
content-script.js
File metadata and controls
115 lines (108 loc) · 3.68 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
var selector = '[id^=react-aria]';
var port = chrome.runtime.connect({name: "react-aria-detector"});
function foundReactAria() {
port.postMessage({reactAria: true});
let domain = window.location.hostname;
chrome.storage.local.get('domains').then(function (entries) {
let domains = entries.domains ?? [];
if (!domains.includes(domain)) {
domains.push(domain);
chrome.storage.local.set({domains: domains});
}
});
}
let bannedDomains = [
'csb.app',
'localhost',
'127.0.0.1',
'local-credentialless',
'chromatic',
'stage.adobe',
'echosignstage',
'react-spectrum.adobe.com',
];
function checkForReactAria() {
let domain = window.location.hostname;
for (let bannedDomain of bannedDomains) {
if (domain.includes(bannedDomain)) {
return;
}
}
let observer;
chrome.storage.onChanged.addListener(function (changes, namespace) {
chrome.storage.local.get('pausedDomains').then(function (entries) {
let pausedDomains = entries.pausedDomains || [];
if (pausedDomains.includes(domain) && observer) {
console.log('React Aria detection paused on this domain. Disconnected observer.')
observer.disconnect();
}
});
});
chrome.storage.local.get('pausedDomains').then(function (entries) {
let pausedDomains = entries.pausedDomains || [];
if (pausedDomains.includes(domain)) {
console.log('React Aria detection paused on domain: ', domain);
return;
}
chrome.storage.local.get('domains').then(function (entries) {
let result = (entries.domains ?? []).includes(domain);
if (result) {
console.log('React Aria already found on this domain!');
foundReactAria();
} else {
console.log('Checking for React Aria...');
var reactAriaElements = document.querySelectorAll(selector);
// check SSR
if (reactAriaElements.length > 0) {
foundReactAria();
} else {
// check for delayed react rendering
let promise = new Promise(function (resolve, reject) {
setTimeout(() => {
console.log('Checking for React Aria after load...');
// wait for react to potentially load, then check again.
reactAriaElements = document.querySelectorAll(selector);
if (reactAriaElements.length > 0) {
foundReactAria();
resolve();
} else {
reject();
}
});
});
// catch any later renders
promise.catch(() => {
console.log('Checking for React Aria in MutationObserver...');
observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (mutation.addedNodes) {
for (let i = 0; i < mutation.addedNodes.length; i++) {
if (mutation.addedNodes[i].matches?.(selector)) {
foundReactAria();
observer.disconnect();
break;
}
}
}
});
});
observer.observe(document.body, {
childList: true,
subtree: true
});
});
}
}
});
});
}
chrome.runtime.onMessage.addListener( (message, sender, sendResponse) => {
chrome.storage.local.get('pausedDomains').then(function (entries) {
let pausedDomains = entries.pausedDomains || [];
if (!pausedDomains.includes(window.location.hostname)) {
pausedDomains.push(window.location.hostname);
chrome.storage.local.set({pausedDomains: pausedDomains});
}
}, []);
});
checkForReactAria();