mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-07 03:57:09 +03:00
Converted more code to TypeScript.
This commit is contained in:
@@ -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
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1123
src/popup.js
1123
src/popup.js
File diff suppressed because it is too large
Load Diff
7
src/types.ts
Normal file
7
src/types.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
interface videoDurationResponse {
|
||||
duration: number;
|
||||
}
|
||||
|
||||
export {
|
||||
videoDurationResponse
|
||||
};
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user