-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
33 lines (32 loc) · 940 Bytes
/
content.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
function waitForElement(querySelector, timeout){
return new Promise((resolve, reject)=>{
var timer = false;
if (document.querySelectorAll(querySelector).length) return resolve();
const observer = new MutationObserver(()=>{
if (document.querySelectorAll(querySelector).length){
observer.disconnect();
if (timer !== false) clearTimeout(timer);
return resolve();
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
if (timeout) timer = setTimeout(()=>{
observer.disconnect();
reject();
}, timeout);
});
}
p = waitForElement('[href="/home"][role="tab"][aria-selected="false"]', 5000);
p.then(()=> {
var a = document.querySelectorAll('[href="/home"][role="tab"][aria-selected="false"]');
if (a.length > 0) {
a[0].click();
console.log("Then: Success! Following is better than For you!");
}
});
p.catch(()=> {
console.log("Catch: failed to detect tab entries");
});