forked from dimdenGD/OldTweetDeck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinjection.js
57 lines (55 loc) · 2.48 KB
/
injection.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
window.addEventListener("message", (event) => {
if (event.data.action === "getcookie") {
chrome.runtime.sendMessage({ action: "setcookie", cookie: document.cookie });
}
});
(async () => {
let html = await fetch(chrome.runtime.getURL('/files/index.html')).then(r => r.text());
document.documentElement.innerHTML = html;
let [
vendor_js,
bundle_js,
bundle_css,
remote_vendor_js,
remote_bundle_js,
remote_bundle_css
] = await Promise.allSettled([
fetch(chrome.runtime.getURL('/files/vendor.js')).then(r => r.text()),
fetch(chrome.runtime.getURL('/files/bundle.js')).then(r => r.text()),
fetch(chrome.runtime.getURL('/files/bundle.css')).then(r => r.text()),
fetch('https://raw.githubusercontent.com/dimdenGD/OldTweetDeck/main/files/vendor.js').then(r => r.text()),
fetch('https://raw.githubusercontent.com/dimdenGD/OldTweetDeck/main/files/bundle.js').then(r => r.text()),
fetch('https://raw.githubusercontent.com/dimdenGD/OldTweetDeck/main/files/bundle.css').then(r => r.text())
]);
let vendor_js_script = document.createElement('script');
if(remote_vendor_js.status === 'fulfilled' && !localStorage.getItem('OTDalwaysUseLocalFiles')) {
vendor_js_script.innerHTML = remote_vendor_js.value;
} else {
vendor_js_script.innerHTML = vendor_js.value;
}
document.head.appendChild(vendor_js_script);
let bundle_js_script = document.createElement('script');
if(remote_bundle_js.status === 'fulfilled' && !localStorage.getItem('OTDalwaysUseLocalFiles')) {
bundle_js_script.innerHTML = remote_bundle_js.value;
} else {
bundle_js_script.innerHTML = bundle_js.value;
}
document.head.appendChild(bundle_js_script);
let bundle_css_style = document.createElement('style');
if(remote_bundle_css.status === 'fulfilled' && !localStorage.getItem('OTDalwaysUseLocalFiles')) {
bundle_css_style.innerHTML = remote_bundle_css.value;
} else {
bundle_css_style.innerHTML = bundle_css.value;
}
document.head.appendChild(bundle_css_style);
let int = setInterval(() => {
let badBody = document.querySelector('body:not(#injected-body)');
let badHead = document.querySelector('head:not(#injected-head)');
if (badBody && badHead) {
badBody.remove();
badHead.remove();
clearInterval(int);
}
}, 200);
setTimeout(() => clearInterval(int), 10000);
})();