-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
66 lines (62 loc) · 1.83 KB
/
background.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
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request === "load-index") {
chrome.scripting.executeScript(
{
target: { tabId: sender.tab.id },
files: ["logic.js"],
},
sendResponse("success")
);
} else if (request === "load-error") {
chrome.scripting.executeScript(
{
target: { tabId: sender.tab.id },
files: ["error.js"],
},
sendResponse("success")
);
} else if (request === "open-options") {
chrome.runtime.openOptionsPage(() => {
sendResponse("success");
});
}
fetch(
"https://raw.githubusercontent.com/esfalsa/applesauce/main/manifest.json"
)
.then((response) => response.json())
.then(({ disabled }) => {
if (disabled || chrome.runtime.getManifest().disabled) {
chrome.tabs.create({
url: "disabled.html",
});
chrome.tabs.remove(sender.tab.id);
}
});
});
chrome.action.onClicked.addListener(async () => {
let tabs = await chrome.tabs.query({
url: "*://*.nationstates.net/template-overall=none/page=blank/applesauce*",
});
if (!tabs?.length) {
chrome.tabs.create({
url: "https://www.nationstates.net/template-overall=none/page=blank/applesauce",
});
} else {
chrome.tabs.update(tabs[0].id, { active: true });
}
});
fetch("https://raw.githubusercontent.com/esfalsa/applesauce/main/manifest.json")
.then((response) => response.json())
.then(({ version, disabled }) => {
if (disabled || chrome.runtime.getManifest().disabled) {
chrome.tabs.create({
url: "disabled.html",
});
} else if (version !== chrome.runtime.getManifest().version) {
chrome.tabs.create({
url: `update.html?latest=${version}¤t=${
chrome.runtime.getManifest().version
}`,
});
}
});