diff options
Diffstat (limited to 'src/background.ts')
-rw-r--r-- | src/background.ts | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/src/background.ts b/src/background.ts index 99df62db..23914f46 100644 --- a/src/background.ts +++ b/src/background.ts @@ -123,7 +123,7 @@ chrome.runtime.onInstalled.addListener(function () { // If there is no userID, then it is the first install. if (!userID && !Config.local.alreadyInstalled){ //open up the install page - chrome.tabs.create({url: chrome.extension.getURL("/help/index.html")}); + chrome.tabs.create({url: chrome.runtime.getURL("/help/index.html")}); //generate a userID const newUserID = generateUserID(); @@ -137,7 +137,7 @@ chrome.runtime.onInstalled.addListener(function () { if (Config.config.supportInvidious) { if (!(await utils.containsInvidiousPermission())) { - chrome.tabs.create({url: chrome.extension.getURL("/permissions/index.html")}); + chrome.tabs.create({url: chrome.runtime.getURL("/permissions/index.html")}); } } }, 1500); @@ -160,8 +160,8 @@ async function registerFirefoxContentScript(options: Registration) { ids: [options.id] }).catch(() => []); - if (existingRegistrations.length > 0 - && existingRegistrations[0].matches.every((match) => options.matches.includes(match))) { + if (existingRegistrations && existingRegistrations.length > 0 + && options.matches.every((match) => existingRegistrations[0].matches.includes(match))) { // No need to register another script, already registered return; } @@ -222,27 +222,35 @@ async function submitVote(type: number, UUID: string, category: string) { const typeSection = (type !== undefined) ? "&type=" + type : "&category=" + category; - //publish this vote - const response = await asyncRequestToServer("POST", "/api/voteOnSponsorTime?UUID=" + UUID + "&userID=" + userID + typeSection); - - if (response.ok) { - return { - successType: 1, - responseText: await response.text() - }; - } else if (response.status == 405) { - //duplicate vote - return { - successType: 0, - statusCode: response.status, - responseText: await response.text() - }; - } else { - //error while connect + try { + const response = await asyncRequestToServer("POST", "/api/voteOnSponsorTime?UUID=" + UUID + "&userID=" + userID + typeSection); + + if (response.ok) { + return { + successType: 1, + responseText: await response.text() + }; + } else if (response.status == 405) { + //duplicate vote + return { + successType: 0, + statusCode: response.status, + responseText: await response.text() + }; + } else { + //error while connect + return { + successType: -1, + statusCode: response.status, + responseText: await response.text() + }; + } + } catch (e) { + console.error(e); return { successType: -1, - statusCode: response.status, - responseText: await response.text() + statusCode: -1, + responseText: "" }; } } |