forked from wseagar/eight-dollars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
71 lines (67 loc) · 1.84 KB
/
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
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
const defaultConfig = {
advancedSearch: false,
advancedSearchMigratedToFalseOnce: false,
memeMode: false,
textEnabled: true,
removeBlueVerification: false,
textOptions: {
verifiedLabel: "Verified",
twitterBlueLabel: "Paid",
enableBorder: true,
},
removeTweets: false,
};
function createSettingsDomNode(items) {
const settingsDomNode = document.createElement("div");
settingsDomNode.id = "eight-dollars-settings";
settingsDomNode.style.display = "none";
settingsDomNode.innerText = JSON.stringify(items);
document.body.appendChild(settingsDomNode);
}
function injectScript() {
const s = document.createElement("script", { id: "eight-dollars" });
s.src = chrome.runtime.getURL("script.js");
s.onload = function () {
this.remove();
};
document.head.appendChild(s);
}
function injectSearch() {
const s = document.createElement("script", { id: "eight-dollars-search" });
s.src = chrome.runtime.getURL("search.js");
s.onload = function () {
this.remove();
};
document.head.appendChild(s);
}
if (typeof chrome !== "undefined" && chrome.storage) {
chrome.storage.local.get(defaultConfig, function (items) {
if (!items.advancedSearchMigratedToFalseOnce) {
chrome.storage.local.set({
advancedSearch: false,
advancedSearchMigratedToFalseOnce: true,
}, function () {
items.advancedSearch = false;
items.advancedSearchMigratedToFalseOnce = true;
createSettingsDomNode(items);
injectScript();
if (items.advancedSearch) {
injectSearch();
}
})
}
else {
createSettingsDomNode(items);
injectScript();
if (items.advancedSearch) {
injectSearch();
}
}
});
} else {
createSettingsDomNode(defaultConfig);
injectScript();
if (defaultConfig.advancedSearch) {
injectSearch();
}
}