Converted more code to TypeScript.

This commit is contained in:
Ajay Ramachandran
2020-01-28 23:52:15 -05:00
parent 03836b69f2
commit d77f8abf42
6 changed files with 37 additions and 1150 deletions

View File

@@ -1,12 +1,17 @@
isBackgroundScript = true;
import Utils from "./utils";
import SB from "./SB";
import * as Types from "./types";
Utils.isBackgroundScript = true;
// Used only on Firefox, which does not support non persistent background pages.
var contentScriptRegistrations = {};
// Register content script if needed
if (isFirefox()) {
wait(() => SB.config !== undefined).then(function() {
if (SB.config.supportInvidious) setupExtraSiteContentScripts();
if (Utils.isFirefox()) {
Utils.wait(() => SB.config !== undefined).then(function() {
if (SB.config.supportInvidious) Utils.setupExtraSiteContentScripts();
});
}
@@ -77,7 +82,7 @@ chrome.runtime.onInstalled.addListener(function (object) {
chrome.tabs.create({url: chrome.extension.getURL("/help/index_en.html")});
//generate a userID
const newUserID = generateUserID();
const newUserID = Utils.generateUserID();
//save this UUID
SB.config.userID = newUserID;
@@ -143,7 +148,7 @@ function submitVote(type, UUID, callback) {
if (userID == undefined || userID === "undefined") {
//generate one
userID = generateUserID();
userID = Utils.generateUserID();
SB.config.userID = userID;
}
@@ -176,7 +181,7 @@ async function submitTimes(videoID, callback) {
let userID = SB.config.userID;
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
let durationResult = await new Promise((resolve, reject) => {
let durationResult = <Types.videoDurationResponse> await new Promise((resolve, reject) => {
chrome.tabs.query({
active: true,
currentWindow: true
@@ -208,19 +213,17 @@ async function submitTimes(videoID, callback) {
});
if (xmlhttp.status == 200) {
//add these to the storage log
currentContributionAmount = SB.config.sponsorTimesContributed;
//save the amount contributed
if (!increasedContributionAmount) {
increasedContributionAmount = true;
SB.config.sponsorTimesContributed = currentContributionAmount + sponsorTimes.length;
}
SB.config.sponsorTimesContributed = SB.config.sponsorTimesContribute + sponsorTimes.length;
}
} else if (error) {
callback({
statusCode: -1
});
}
}
});
}
}

View File

@@ -75,7 +75,7 @@ class PreviewBar {
bar.style.left = (timestamps[i][0] / duration * 100) + "%";
bar.style.position = "absolute"
this.container.insertAdjacentElement("beforeEnd", bar);
this.container.insertAdjacentElement("beforeend", bar);
}
}

File diff suppressed because it is too large Load Diff

7
src/types.ts Normal file
View File

@@ -0,0 +1,7 @@
interface videoDurationResponse {
duration: number;
}
export {
videoDurationResponse
};

View File

@@ -134,7 +134,7 @@ class Utils {
matches: this.getInvidiousInstancesRegex()
};
if (isBackgroundScript) {
if (this.isBackgroundScript) {
registerFirefoxContentScript(registration);
} else {
chrome.runtime.sendMessage(registration);
@@ -172,7 +172,7 @@ class Utils {
if (this.isFirefox()) {
let id = "invidious";
if (isBackgroundScript) {
if (this.isBackgroundScript) {
if (contentScriptRegistrations[id]) {
contentScriptRegistrations[id].unregister();
delete contentScriptRegistrations[id];