-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
67 lines (64 loc) · 2.1 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
67
let MultiPlayerSuggestion = {description:"Play Multiplayer!", content:"Multiplayer Please!"}
let SinglePlayerSuggestion = {description:"Play Singleplayer!", content:"Singleplayer Please!"}
let DefaultSuggestion = {description: "Play Singleplayer!"}
let Config = {
Multiplayer: "https://sean.aurorii.com"
}
class DataHandler {
constructor(reset) {
if (reset){
chrome.storage.local.clear()
}
}
async addBling(amount) {
let data = await chrome.storage.local.get()
if (data["bling"]){
data["bling"] = parseInt(data["bling"])
data["bling"] += amount
}
else {
data["bling"] = amount
}
await chrome.storage.local.set(data)
}
}
chrome.omnibox.setDefaultSuggestion(DefaultSuggestion)
chrome.omnibox.onInputChanged.addListener(function (text, suggest) {
if (isMultiplayer(text)) {
chrome.omnibox.setDefaultSuggestion({description: MultiPlayerSuggestion.description})
suggest([SinglePlayerSuggestion])
}
else {
chrome.omnibox.setDefaultSuggestion(DefaultSuggestion)
suggest([MultiPlayerSuggestion])
}
})
function isMultiplayer(text) {
return text.indexOf("Multi") != -1 || text.indexOf("multi") != -1
}
chrome.omnibox.onInputEntered.addListener(function (text, disposition) {
if (isMultiplayer(text)) {
chrome.tabs.create({url:Config.Multiplayer})
}
else {
chrome.action.setPopup({popup:"/popup.html"})
chrome.action.openPopup()
}
})
function openPage(page) {
chrome.action.setPopup({popup:page})
chrome.action.openPopup()
chrome.action.setPopup({popup:"popup.html"})
}
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
if (message.type == "open") {
sendResponse({type:"close"})
setTimeout(openPage, 500, message.page)
}
})
chrome.runtime.onMessageExternal.addListener(function (message, sender, sendResponse) {
if (message.type == "bling") {
datahandler.addBling(message.amount)
}
})
chrome.runtime.setUninstallURL("https://forms.gle/eurttvCHx6oqfzDF8")