Merge pull request #260 from ajayyy/typescript

Rename SB.js
This commit is contained in:
Ajay Ramachandran 2020-02-04 02:16:47 -05:00 committed by GitHub
commit feda7fd1a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 170 additions and 181 deletions

View file

@ -29,7 +29,7 @@
"build": "npm run build:chrome",
"build:chrome": "webpack --env.browser=chrome --config webpack/webpack.prod.js",
"build:firefox": "webpack --env.browser=firefox --config webpack/webpack.prod.js",
"build:watch": "npm run build:chrome:watch",
"build:watch": "npm run build:watch:chrome",
"build:watch:chrome": "webpack --env.browser=chrome --config webpack/webpack.dev.js --watch",
"build:watch:firefox": "webpack --env.browser=firefox --config webpack/webpack.dev.js --watch",
"dev": "npm run build && concurrently \"npm run web-run\" \"npm run build:watch\"",

View file

@ -1,5 +1,5 @@
import * as Types from "./types";
import SB from "./SB";
import Config from "./config";
import Utils from "./utils";
var utils = new Utils({
@ -12,8 +12,8 @@ var contentScriptRegistrations = {};
// Register content script if needed
if (utils.isFirefox()) {
utils.wait(() => SB.config !== null).then(function() {
if (SB.config.supportInvidious) utils.setupExtraSiteContentScripts();
utils.wait(() => Config.config !== null).then(function() {
if (Config.config.supportInvidious) utils.setupExtraSiteContentScripts();
});
}
@ -74,7 +74,7 @@ chrome.runtime.onInstalled.addListener(function (object) {
// This let's the config sync to run fully before checking.
// This is required on Firefox
setTimeout(function() {
const userID = SB.config.userID;
const userID = Config.config.userID;
// If there is no userID, then it is the first install.
if (!userID){
@ -84,11 +84,11 @@ chrome.runtime.onInstalled.addListener(function (object) {
//generate a userID
const newUserID = utils.generateUserID();
//save this UUID
SB.config.userID = newUserID;
Config.config.userID = newUserID;
//TODO: Remove when invidious support is old
// Don't show this to new users
SB.config.invidiousUpdateInfoShowCount = 6;
Config.config.invidiousUpdateInfoShowCount = 6;
}
}, 1500);
});
@ -124,7 +124,7 @@ function unregisterFirefoxContentScript(id: string) {
//gets the sponsor times from memory
function getSponsorTimes(videoID, callback) {
let sponsorTimes = [];
let sponsorTimesStorage = SB.config.sponsorTimes.get(videoID);
let sponsorTimesStorage = Config.config.sponsorTimes.get(videoID);
if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) {
sponsorTimes = sponsorTimesStorage;
@ -148,18 +148,18 @@ function addSponsorTime(time, videoID, callback) {
}
//save this info
SB.config.sponsorTimes.set(videoID, sponsorTimes);
Config.config.sponsorTimes.set(videoID, sponsorTimes);
callback();
});
}
function submitVote(type, UUID, callback) {
let userID = SB.config.userID;
let userID = Config.config.userID;
if (userID == undefined || userID === "undefined") {
//generate one
userID = utils.generateUserID();
SB.config.userID = userID;
Config.config.userID = userID;
}
//publish this vote
@ -187,8 +187,8 @@ function submitVote(type, UUID, callback) {
async function submitTimes(videoID, callback) {
//get the video times from storage
let sponsorTimes = SB.config.sponsorTimes.get(videoID);
let userID = SB.config.userID;
let sponsorTimes = Config.config.sponsorTimes.get(videoID);
let userID = Config.config.userID;
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
let durationResult = <Types.videoDurationResponse> await new Promise((resolve, reject) => {
@ -226,7 +226,7 @@ async function submitTimes(videoID, callback) {
//save the amount contributed
if (!increasedContributionAmount) {
increasedContributionAmount = true;
SB.config.sponsorTimesContributed = SB.config.sponsorTimesContribute + sponsorTimes.length;
Config.config.sponsorTimesContributed = Config.config.sponsorTimesContributed + sponsorTimes.length;
}
} else if (error) {
callback({

View file

@ -1,5 +1,7 @@
interface SBConfig {
userID: string,
sponsorTimes: SBMap<string, any>,
whitelistedChannels: Array<any>,
startSponsorKeybind: string,
submitKeybind: string,
minutesSaved: number,
@ -16,22 +18,27 @@ interface SBConfig {
hideDiscordLink: boolean,
invidiousInstances: string[],
invidiousUpdateInfoShowCount: number,
autoUpvote: boolean
autoUpvote: boolean,
supportInvidious: false
}
interface SBObject {
configListeners: Array<Function>;
defaults: SBConfig;
localConfig: any;
config: any;
localConfig: SBConfig;
config: SBConfig;
}
// Allows a SBMap to be conveted into json form
// Currently used for local storage
class SBMap<T, U> extends Map {
constructor(entries?: [T, U][]) {
id: string;
constructor(id: string, entries?: [T, U][]) {
super();
this.id = id;
// Import all entries if they were given
if (entries !== undefined) {
for (const item of entries) {
@ -40,20 +47,53 @@ class SBMap<T, U> extends Map {
}
}
set(key, value) {
const result = super.set(key, value);
// Store updated SBMap locally
chrome.storage.sync.set({
[this.id]: encodeStoredItem(this)
});
return result;
}
delete(key) {
const result = super.delete(key);
// Store updated SBMap locally
chrome.storage.sync.set({
[this.id]: encodeStoredItem(this)
});
return result;
}
clear() {
const result = super.clear();
chrome.storage.sync.set({
[this.id]: encodeStoredItem(this)
});
return result;
}
toJSON() {
return Array.from(this.entries());
}
}
// TODO: Rename to something more meaningful
var SB: SBObject = {
var Config: SBObject = {
/**
* Callback function when an option is updated
*/
configListeners: [],
defaults: {
sponsorTimes: new SBMap(),
userID: null,
sponsorTimes: new SBMap("sponsorTimes"),
whitelistedChannels: [],
startSponsorKeybind: ";",
submitKeybind: "'",
minutesSaved: 0,
@ -70,7 +110,8 @@ var SB: SBObject = {
hideDiscordLink: false,
invidiousInstances: ["invidio.us", "invidiou.sh", "invidious.snopyta.org"],
invidiousUpdateInfoShowCount: 0,
autoUpvote: true
autoUpvote: true,
supportInvidious: false
},
localConfig: null,
config: null
@ -78,58 +119,6 @@ var SB: SBObject = {
// Function setup
// Proxy Map changes to Map in SB.localConfig
// Saves the changes to chrome.storage in json form
class MapIO {
id: string;
map: SBMap<String, any>;
constructor(id) {
// The name of the item in the array
this.id = id;
// A local copy of the SBMap (SB.config.SBMapname.SBMap)
this.map = SB.localConfig[this.id];
}
set(key, value) {
// Proxy to SBMap
this.map.set(key, value);
// Store updated SBMap locally
chrome.storage.sync.set({
[this.id]: encodeStoredItem(this.map)
});
return this.map;
}
get(key) {
return this.map.get(key);
}
has(key) {
return this.map.has(key);
}
size() {
return this.map.size;
}
delete(key) {
// Proxy to SBMap
this.map.delete(key);
// Store updated SBMap locally
chrome.storage.sync.set({
[this.id]: encodeStoredItem(this.map)
});
}
clear() {
this.map.clear();
chrome.storage.sync.set({
[this.id]: encodeStoredItem(this.map)
});
}
}
/**
* A SBMap cannot be stored in the chrome storage.
* This data will be encoded into an array instead as specified by the toJSON function.
@ -143,19 +132,19 @@ function encodeStoredItem(data) {
}
/**
* A SBMap cannot be stored in the chrome storage.
* An SBMap cannot be stored in the chrome storage.
* This data will be decoded from the array it is stored in
*
* @param {*} data
*/
function decodeStoredItem(data) {
function decodeStoredItem(id: string, data) {
if(typeof data !== "string") return data;
try {
let str = JSON.parse(data);
if(!Array.isArray(str)) return data;
return new SBMap(str);
return new SBMap(id, str);
} catch(e) {
// If all else fails, return the data
@ -166,17 +155,17 @@ function decodeStoredItem(data) {
function configProxy(): any {
chrome.storage.onChanged.addListener((changes, namespace) => {
for (const key in changes) {
SB.localConfig[key] = decodeStoredItem(changes[key].newValue);
Config.localConfig[key] = decodeStoredItem(key, changes[key].newValue);
}
for (const callback of SB.configListeners) {
for (const callback of Config.configListeners) {
callback(changes);
}
});
var handler: ProxyHandler<any> = {
set(obj, prop, value) {
SB.localConfig[prop] = value;
Config.localConfig[prop] = value;
chrome.storage.sync.set({
[prop]: encodeStoredItem(value)
@ -186,8 +175,7 @@ function configProxy(): any {
},
get(obj, prop): any {
let data = SB.localConfig[prop];
if(data instanceof SBMap) data = new MapIO(prop);
let data = Config.localConfig[prop];
return obj[prop] || data;
},
@ -206,17 +194,17 @@ function configProxy(): any {
function fetchConfig() {
return new Promise((resolve, reject) => {
chrome.storage.sync.get(null, function(items) {
SB.localConfig = items; // Data is ready
Config.localConfig = <SBConfig> <unknown> items; // Data is ready
resolve();
});
});
}
function migrateOldFormats() { // Convert sponsorTimes format
for (const key in SB.localConfig) {
for (const key in Config.localConfig) {
if (key.startsWith("sponsorTimes") && key !== "sponsorTimes" && key !== "sponsorTimesContributed") {
SB.config.sponsorTimes.set(key.substr(12), SB.config[key]);
delete SB.config[key];
Config.config.sponsorTimes.set(key.substr(12), Config.config[key]);
delete Config.config[key];
}
}
}
@ -225,26 +213,26 @@ async function setupConfig() {
await fetchConfig();
addDefaults();
convertJSON();
SB.config = configProxy();
Config.config = configProxy();
migrateOldFormats();
}
// Reset config
function resetConfig() {
SB.config = SB.defaults;
Config.config = Config.defaults;
};
function convertJSON() {
Object.keys(SB.defaults).forEach(key => {
SB.localConfig[key] = decodeStoredItem(SB.localConfig[key]);
Object.keys(Config.defaults).forEach(key => {
Config.localConfig[key] = decodeStoredItem(key, Config.localConfig[key]);
});
}
// Add defaults
function addDefaults() {
for (const key in SB.defaults) {
if(!SB.localConfig.hasOwnProperty(key)) {
SB.localConfig[key] = SB.defaults[key];
for (const key in Config.defaults) {
if(!Config.localConfig.hasOwnProperty(key)) {
Config.localConfig[key] = Config.defaults[key];
}
}
};
@ -252,4 +240,4 @@ function addDefaults() {
// Sync config
setupConfig();
export default SB;
export default Config;

View file

@ -1,4 +1,4 @@
import SB from "./SB";
import Config from "./config";
import Utils from "./utils";
var utils = new Utils();
@ -50,7 +50,7 @@ var previewBar = null;
var controls = null;
// Direct Links after the config is loaded
utils.wait(() => SB.config !== null).then(() => videoIDChange(getYouTubeVideoID(document.URL)));
utils.wait(() => Config.config !== null).then(() => videoIDChange(getYouTubeVideoID(document.URL)));
//the last time looked at (used to see if this time is in the interval)
var lastTime = -1;
@ -183,8 +183,8 @@ function contentConfigUpdateListener(changes) {
}
}
if (!SB.configListeners.includes(contentConfigUpdateListener)) {
SB.configListeners.push(contentConfigUpdateListener);
if (!Config.configListeners.includes(contentConfigUpdateListener)) {
Config.configListeners.push(contentConfigUpdateListener);
}
//check for hotkey pressed
@ -193,9 +193,9 @@ document.onkeydown = function(e: KeyboardEvent){
let video = document.getElementById("movie_player");
let startSponsorKey = SB.config.startSponsorKeybind;
let startSponsorKey = Config.config.startSponsorKeybind;
let submitKey = SB.config.submitKeybind;
let submitKey = Config.config.submitKeybind;
//is the video in focus, otherwise they could be typing a comment
if (document.activeElement === video) {
@ -270,7 +270,7 @@ function videoIDChange(id) {
//warn them if they had unsubmitted times
if (previousVideoID != null) {
//get the sponsor times from storage
let sponsorTimes = SB.config.sponsorTimes.get(previousVideoID);
let sponsorTimes = Config.config.sponsorTimes.get(previousVideoID);
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
//warn them that they have unsubmitted sponsor times
chrome.runtime.sendMessage({
@ -408,7 +408,7 @@ function sponsorsLookup(id: string, channelIDPromise?) {
});
//add the event to run on the videos "ontimeupdate"
if (!SB.config.disableSkipping) {
if (!Config.config.disableSkipping) {
v.ontimeupdate = function () {
sponsorCheck();
};
@ -429,12 +429,12 @@ function getYouTubeVideoID(url: string) {
}
// Check if valid hostname
if (SB.config && SB.config.invidiousInstances.includes(urlObject.host)) {
if (Config.config && Config.config.invidiousInstances.includes(urlObject.host)) {
onInvidious = true;
} else if (!["www.youtube.com", "www.youtube-nocookie.com"].includes(urlObject.host)) {
if (!SB.config) {
if (!Config.config) {
// Call this later, in case this is an Invidious tab
utils.wait(() => SB.config !== null).then(() => videoIDChange(getYouTubeVideoID(url)));
utils.wait(() => Config.config !== null).then(() => videoIDChange(getYouTubeVideoID(url)));
}
return false
@ -533,7 +533,7 @@ function updatePreviewBar() {
//checks if this channel is whitelisted, should be done only after the channelID has been loaded
function whitelistCheck() {
//see if this is a whitelisted channel
let whitelistedChannels = SB.config.whitelistedChannels;
let whitelistedChannels = Config.config.whitelistedChannels;
if (whitelistedChannels != undefined && whitelistedChannels.includes(channelURL)) {
channelWhitelisted = true;
@ -542,7 +542,7 @@ function whitelistCheck() {
//video skipping
function sponsorCheck() {
if (SB.config.disableSkipping) {
if (Config.config.disableSkipping) {
// Make sure this isn't called again
v.ontimeupdate = null;
return;
@ -608,7 +608,7 @@ function checkIfTimeToSkip(currentVideoTime, startTime, endTime) {
//skip fromt he start time to the end time for a certain index sponsor time
function skipToTime(v, index, sponsorTimes, openNotice) {
if (!SB.config.disableAutoSkip) {
if (!Config.config.disableAutoSkip) {
v.currentTime = sponsorTimes[index][1];
}
@ -619,24 +619,24 @@ function skipToTime(v, index, sponsorTimes, openNotice) {
if (openNotice) {
//send out the message saying that a sponsor message was skipped
if (!SB.config.dontShowNotice) {
let skipNotice = new SkipNotice(this, currentUUID, SB.config.disableAutoSkip, skipNoticeContentContainer);
if (!Config.config.dontShowNotice) {
let skipNotice = new SkipNotice(this, currentUUID, Config.config.disableAutoSkip, skipNoticeContentContainer);
//auto-upvote this sponsor
if (SB.config.trackViewCount && !SB.config.disableAutoSkip && SB.config.autoUpvote) {
if (Config.config.trackViewCount && !Config.config.disableAutoSkip && Config.config.autoUpvote) {
vote(1, currentUUID, null);
}
}
}
//send telemetry that a this sponsor was skipped
if (SB.config.trackViewCount && !sponsorSkipped[index]) {
if (Config.config.trackViewCount && !sponsorSkipped[index]) {
utils.sendRequestToServer("POST", "/api/viewedVideoSponsorTime?UUID=" + currentUUID);
if (!SB.config.disableAutoSkip) {
if (!Config.config.disableAutoSkip) {
// Count this as a skip
SB.config.minutesSaved = SB.config.minutesSaved + (sponsorTimes[index][1] - sponsorTimes[index][0]) / 60;
SB.config.skipCount = SB.config.skipCount + 1;
Config.config.minutesSaved = Config.config.minutesSaved + (sponsorTimes[index][1] - sponsorTimes[index][0]) / 60;
Config.config.skipCount = Config.config.skipCount + 1;
sponsorSkipped[index] = true;
}
}
@ -713,7 +713,7 @@ async function updateVisibilityOfPlayerControlsButton() {
await createButtons();
if (SB.config.hideVideoPlayerControls || onInvidious) {
if (Config.config.hideVideoPlayerControls || onInvidious) {
document.getElementById("startSponsorButton").style.display = "none";
document.getElementById("submitButton").style.display = "none";
} else {
@ -721,13 +721,13 @@ async function updateVisibilityOfPlayerControlsButton() {
}
//don't show the info button on embeds
if (SB.config.hideInfoButtonPlayerControls || document.URL.includes("/embed/") || onInvidious) {
if (Config.config.hideInfoButtonPlayerControls || document.URL.includes("/embed/") || onInvidious) {
document.getElementById("infoButton").style.display = "none";
} else {
document.getElementById("infoButton").style.removeProperty("display");
}
if (SB.config.hideDeleteButtonPlayerControls || onInvidious) {
if (Config.config.hideDeleteButtonPlayerControls || onInvidious) {
document.getElementById("deleteButton").style.display = "none";
}
}
@ -779,7 +779,7 @@ async function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) {
await utils.wait(isSubmitButtonLoaded);
//if it isn't visible, there is no data
let shouldHide = (uploadButtonVisible && !(SB.config.hideDeleteButtonPlayerControls || onInvidious)) ? "unset" : "none"
let shouldHide = (uploadButtonVisible && !(Config.config.hideDeleteButtonPlayerControls || onInvidious)) ? "unset" : "none"
document.getElementById("deleteButton").style.display = shouldHide;
if (showStartSponsor) {
@ -787,7 +787,7 @@ async function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) {
(<HTMLImageElement> document.getElementById("startSponsorImage")).src = chrome.extension.getURL("icons/PlayerStartIconSponsorBlocker256px.png");
document.getElementById("startSponsorButton").setAttribute("title", chrome.i18n.getMessage("sponsorStart"));
if (document.getElementById("startSponsorImage").style.display != "none" && uploadButtonVisible && !SB.config.hideInfoButtonPlayerControls) {
if (document.getElementById("startSponsorImage").style.display != "none" && uploadButtonVisible && !Config.config.hideInfoButtonPlayerControls) {
document.getElementById("submitButton").style.display = "unset";
} else if (!uploadButtonVisible) {
//disable submit button
@ -882,7 +882,7 @@ function clearSponsorTimes() {
let currentVideoID = sponsorVideoID;
let sponsorTimes = SB.config.sponsorTimes.get(currentVideoID);
let sponsorTimes = Config.config.sponsorTimes.get(currentVideoID);
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
let confirmMessage = chrome.i18n.getMessage("clearThis") + getSponsorTimesMessage(sponsorTimes)
@ -890,7 +890,7 @@ function clearSponsorTimes() {
if(!confirm(confirmMessage)) return;
//clear the sponsor times
SB.config.sponsorTimes.delete(currentVideoID);
Config.config.sponsorTimes.delete(currentVideoID);
//clear sponsor times submitting
sponsorTimesSubmitting = [];
@ -922,11 +922,11 @@ function vote(type, UUID, skipNotice) {
}
// Count this as a skip
SB.config.minutesSaved = SB.config.minutesSaved + factor * (sponsorTimes[sponsorIndex][1] - sponsorTimes[sponsorIndex][0]) / 60;
Config.config.minutesSaved = Config.config.minutesSaved + factor * (sponsorTimes[sponsorIndex][1] - sponsorTimes[sponsorIndex][0]) / 60;
SB.config.skipCount = 0;
Config.config.skipCount = 0;
SB.config.skipCount = SB.config.skipCount + factor * 1;
Config.config.skipCount = Config.config.skipCount + factor * 1;
}
chrome.runtime.sendMessage({
@ -964,7 +964,7 @@ function closeAllSkipNotices(){
}
function dontShowNoticeAgain() {
SB.config.dontShowNotice = true;
Config.config.dontShowNotice = true;
closeAllSkipNotices();
}
@ -991,7 +991,7 @@ function submitSponsorTimes() {
let currentVideoID = sponsorVideoID;
let sponsorTimes = SB.config.sponsorTimes.get(currentVideoID);
let sponsorTimes = Config.config.sponsorTimes.get(currentVideoID);
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
//check if a sponsor exceeds the duration of the video
@ -1001,7 +1001,7 @@ function submitSponsorTimes() {
}
}
//update sponsorTimes
SB.config.sponsorTimes.set(currentVideoID, sponsorTimes);
Config.config.sponsorTimes.set(currentVideoID, sponsorTimes);
//update sponsorTimesSubmitting
sponsorTimesSubmitting = sponsorTimes;
@ -1046,7 +1046,7 @@ function sendSubmitMessage(){
submitButton.addEventListener("animationend", animationEndListener);
//clear the sponsor times
SB.config.sponsorTimes.delete(currentVideoID);
Config.config.sponsorTimes.delete(currentVideoID);
//add submissions to current sponsors list
sponsorTimes = sponsorTimes.concat(sponsorTimesSubmitting);

View file

@ -1,4 +1,4 @@
import SB from "./SB";
import Config from "./config";
import Utils from "./utils";
var utils = new Utils();
@ -8,11 +8,11 @@ window.addEventListener('DOMContentLoaded', init);
async function init() {
utils.localizeHtmlPage();
if (!SB.configListeners.includes(optionsConfigUpdateListener)) {
SB.configListeners.push(optionsConfigUpdateListener);
if (!Config.configListeners.includes(optionsConfigUpdateListener)) {
Config.configListeners.push(optionsConfigUpdateListener);
}
await utils.wait(() => SB.config !== null);
await utils.wait(() => Config.config !== null);
// Set all of the toggle options to the correct option
let optionsContainer = document.getElementById("options");
@ -22,7 +22,7 @@ async function init() {
switch (optionsElements[i].getAttribute("option-type")) {
case "toggle":
let option = optionsElements[i].getAttribute("sync-option");
let optionResult = SB.config[option];
let optionResult = Config.config[option];
let checkbox = optionsElements[i].querySelector("input");
let reverse = optionsElements[i].getAttribute("toggle-type") === "reverse";
@ -44,7 +44,7 @@ async function init() {
// Add click listener
checkbox.addEventListener("click", () => {
SB.config[option] = reverse ? !checkbox.checked : checkbox.checked;
Config.config[option] = reverse ? !checkbox.checked : checkbox.checked;
// See if anything extra must be run
switch (option) {
@ -104,7 +104,7 @@ function optionsConfigUpdateListener(changes) {
*/
function updateDisplayElement(element: HTMLElement) {
let displayOption = element.getAttribute("sync-option")
let displayText = SB.config[displayOption];
let displayText = Config.config[displayOption];
element.innerText = displayText;
// See if anything extra must be run
@ -131,12 +131,12 @@ function invidiousInstanceAddInit(element: HTMLElement, option: string) {
alert(chrome.i18n.getMessage("addInvidiousInstanceError"));
} else {
// Add this
let instanceList = SB.config[option];
let instanceList = Config.config[option];
if (!instanceList) instanceList = [];
instanceList.push(textBox.value);
SB.config[option] = instanceList;
Config.config[option] = instanceList;
let checkbox = <HTMLInputElement> document.querySelector("#support-invidious input");
checkbox.checked = true;
@ -155,7 +155,7 @@ function invidiousInstanceAddInit(element: HTMLElement, option: string) {
resetButton.addEventListener("click", function(e) {
if (confirm(chrome.i18n.getMessage("resetInvidiousInstanceAlert"))) {
// Set to a clone of the default
SB.config[option] = SB.defaults[option].slice(0);
Config.config[option] = Config.defaults[option].slice(0);
}
});
}
@ -175,7 +175,7 @@ function invidiousInit(checkbox: HTMLInputElement, option: string) {
permissions: permissions
}, function (result) {
if (result != checkbox.checked) {
SB.config[option] = result;
Config.config[option] = result;
checkbox.checked = result;
}
@ -192,7 +192,7 @@ function invidiousOnClick(checkbox: HTMLInputElement, option: string) {
if (checkbox.checked) {
utils.setupExtraSitePermissions(function (granted) {
if (!granted) {
SB.config[option] = false;
Config.config[option] = false;
checkbox.checked = false;
}
});
@ -214,14 +214,14 @@ function activateKeybindChange(element: HTMLElement) {
let option = element.getAttribute("sync-option");
let currentlySet = SB.config[option] !== null ? chrome.i18n.getMessage("keybindCurrentlySet") : "";
let currentlySet = Config.config[option] !== null ? chrome.i18n.getMessage("keybindCurrentlySet") : "";
let status = <HTMLElement> element.querySelector(".option-hidden-section > .keybind-status");
status.innerText = chrome.i18n.getMessage("keybindDescription") + currentlySet;
if (SB.config[option] !== null) {
if (Config.config[option] !== null) {
let statusKey = <HTMLElement> element.querySelector(".option-hidden-section > .keybind-status-key");
statusKey.innerText = SB.config[option];
statusKey.innerText = Config.config[option];
}
element.querySelector(".option-hidden-section").classList.remove("hidden");
@ -249,7 +249,7 @@ function keybindKeyPressed(element: HTMLElement, e: KeyboardEvent) {
let option = element.getAttribute("sync-option");
SB.config[option] = key;
Config.config[option] = key;
let status = <HTMLElement> element.querySelector(".option-hidden-section > .keybind-status");
status.innerText = chrome.i18n.getMessage("keybindDescriptionComplete");
@ -281,14 +281,14 @@ function activateTextChange(element: HTMLElement) {
return;
}
textBox.value = SB.config[option];
textBox.value = Config.config[option];
let setButton = element.querySelector(".text-change-set");
setButton.addEventListener("click", () => {
let confirmMessage = element.getAttribute("confirm-message");
if (confirmMessage === null || confirm(chrome.i18n.getMessage(confirmMessage))) {
SB.config[option] = textBox.value;
Config.config[option] = textBox.value;
}
});

View file

@ -1,4 +1,4 @@
import SB from "./SB";
import Config from "./config";
import Utils from "./utils";
var utils = new Utils();
@ -42,7 +42,7 @@ async function runThePopup(messageListener?: MessageListener) {
utils.localizeHtmlPage();
await utils.wait(() => SB.config !== null);
await utils.wait(() => Config.config !== null);
var PageElements: any = {};
@ -127,9 +127,9 @@ async function runThePopup(messageListener?: MessageListener) {
let currentVideoID = null;
//see if discord link can be shown
let hideDiscordLink = SB.config.hideDiscordLink;
let hideDiscordLink = Config.config.hideDiscordLink;
if (hideDiscordLink == undefined || !hideDiscordLink) {
let hideDiscordLaunches = SB.config.hideDiscordLaunches;
let hideDiscordLaunches = Config.config.hideDiscordLaunches;
//only if less than 10 launches
if (hideDiscordLaunches == undefined || hideDiscordLaunches < 10) {
PageElements.discordButtonContainer.style.display = null;
@ -137,12 +137,12 @@ async function runThePopup(messageListener?: MessageListener) {
if (hideDiscordLaunches == undefined) {
hideDiscordLaunches = 1;
}
SB.config.hideDiscordLaunches = hideDiscordLaunches + 1;
Config.config.hideDiscordLaunches = hideDiscordLaunches + 1;
}
}
//show proper disable skipping button
let disableSkipping = SB.config.disableSkipping;
let disableSkipping = Config.config.disableSkipping;
if (disableSkipping != undefined && disableSkipping) {
PageElements.disableSkipping.style.display = "none";
PageElements.enableSkipping.style.display = "unset";
@ -150,23 +150,23 @@ async function runThePopup(messageListener?: MessageListener) {
//if the don't show notice again variable is true, an option to
// disable should be available
let dontShowNotice = SB.config.dontShowNotice;
let dontShowNotice = Config.config.dontShowNotice;
if (dontShowNotice != undefined && dontShowNotice) {
PageElements.showNoticeAgain.style.display = "unset";
}
//get the amount of times this user has contributed and display it to thank them
if (SB.config.sponsorTimesContributed != undefined) {
if (SB.config.sponsorTimesContributed > 1) {
if (Config.config.sponsorTimesContributed != undefined) {
if (Config.config.sponsorTimesContributed > 1) {
PageElements.sponsorTimesContributionsDisplayEndWord.innerText = chrome.i18n.getMessage("Sponsors");
} else {
PageElements.sponsorTimesContributionsDisplayEndWord.innerText = chrome.i18n.getMessage("Sponsor");
}
PageElements.sponsorTimesContributionsDisplay.innerText = SB.config.sponsorTimesContributed;
PageElements.sponsorTimesContributionsDisplay.innerText = Config.config.sponsorTimesContributed;
PageElements.sponsorTimesContributionsContainer.style.display = "unset";
//get the userID
let userID = SB.config.userID;
let userID = Config.config.userID;
if (userID != undefined) {
//there are probably some views on these submissions then
//get the amount of views from the sponsors submitted
@ -206,26 +206,26 @@ async function runThePopup(messageListener?: MessageListener) {
}
//get the amount of times this user has skipped a sponsor
if (SB.config.skipCount != undefined) {
if (SB.config.skipCount != 1) {
if (Config.config.skipCount != undefined) {
if (Config.config.skipCount != 1) {
PageElements.sponsorTimesSkipsDoneEndWord.innerText = chrome.i18n.getMessage("Sponsors");
} else {
PageElements.sponsorTimesSkipsDoneEndWord.innerText = chrome.i18n.getMessage("Sponsor");
}
PageElements.sponsorTimesSkipsDoneDisplay.innerText = SB.config.skipCount;
PageElements.sponsorTimesSkipsDoneDisplay.innerText = Config.config.skipCount;
PageElements.sponsorTimesSkipsDoneContainer.style.display = "unset";
}
//get the amount of time this user has saved.
if (SB.config.minutesSaved != undefined) {
if (SB.config.minutesSaved != 1) {
if (Config.config.minutesSaved != undefined) {
if (Config.config.minutesSaved != 1) {
PageElements.sponsorTimeSavedEndWord.innerText = chrome.i18n.getMessage("minsLower");
} else {
PageElements.sponsorTimeSavedEndWord.innerText = chrome.i18n.getMessage("minLower");
}
PageElements.sponsorTimeSavedDisplay.innerText = getFormattedHours(SB.config.minutesSaved);
PageElements.sponsorTimeSavedDisplay.innerText = getFormattedHours(Config.config.minutesSaved);
PageElements.sponsorTimeSavedContainer.style.display = "unset";
}
@ -254,7 +254,7 @@ async function runThePopup(messageListener?: MessageListener) {
}
//load video times for this video
let sponsorTimesStorage = SB.config.sponsorTimes.get(currentVideoID);
let sponsorTimesStorage = Config.config.sponsorTimes.get(currentVideoID);
if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) {
if (sponsorTimesStorage[sponsorTimesStorage.length - 1] != undefined && sponsorTimesStorage[sponsorTimesStorage.length - 1].length < 2) {
startTimeChosen = true;
@ -346,7 +346,7 @@ async function runThePopup(messageListener?: MessageListener) {
sponsorTimes[sponsorTimesIndex][startTimeChosen ? 1 : 0] = response.time;
let localStartTimeChosen = startTimeChosen;
SB.config.sponsorTimes.set(currentVideoID, sponsorTimes);
Config.config.sponsorTimes.set(currentVideoID, sponsorTimes);
//send a message to the client script
if (localStartTimeChosen) {
@ -679,7 +679,7 @@ async function runThePopup(messageListener?: MessageListener) {
sponsorTimes[index][1] = getSponsorTimeEditTimes("endTime", index);
//save this
SB.config.sponsorTimes.set(currentVideoID, sponsorTimes);
Config.config.sponsorTimes.set(currentVideoID, sponsorTimes);
messageHandler.query({
active: true,
currentWindow: true
@ -718,7 +718,7 @@ async function runThePopup(messageListener?: MessageListener) {
sponsorTimes.splice(index, 1);
//save this
SB.config.sponsorTimes.set(currentVideoID, sponsorTimes);
Config.config.sponsorTimes.set(currentVideoID, sponsorTimes);
messageHandler.query({
active: true,
currentWindow: true
@ -769,7 +769,7 @@ async function runThePopup(messageListener?: MessageListener) {
//reset sponsorTimes
sponsorTimes = [];
SB.config.sponsorTimes.set(currentVideoID, sponsorTimes);
Config.config.sponsorTimes.set(currentVideoID, sponsorTimes);
messageHandler.query({
active: true,
currentWindow: true
@ -816,7 +816,7 @@ async function runThePopup(messageListener?: MessageListener) {
}
function showNoticeAgain() {
SB.config.dontShowNotice = false;
Config.config.dontShowNotice = false;
PageElements.showNoticeAgain.style.display = "none";
}
@ -857,7 +857,7 @@ async function runThePopup(messageListener?: MessageListener) {
//make the options username setting option visible
function setUsernameButton() {
//get username from the server
utils.sendRequestToServer("GET", "/api/getUsername?userID=" + SB.config.userID, function (xmlhttp, error) {
utils.sendRequestToServer("GET", "/api/getUsername?userID=" + Config.config.userID, function (xmlhttp, error) {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
PageElements.usernameInput.value = JSON.parse(xmlhttp.responseText).userName;
@ -886,7 +886,7 @@ async function runThePopup(messageListener?: MessageListener) {
PageElements.setUsernameStatus.innerText = "Loading...";
//get the userID
utils.sendRequestToServer("POST", "/api/setUsername?userID=" + SB.config.userID + "&username=" + PageElements.usernameInput.value, function (xmlhttp, error) {
utils.sendRequestToServer("POST", "/api/setUsername?userID=" + Config.config.userID + "&username=" + PageElements.usernameInput.value, function (xmlhttp, error) {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
//submitted
PageElements.submitUsername.style.display = "none";
@ -954,7 +954,7 @@ async function runThePopup(messageListener?: MessageListener) {
}
function hideDiscordButton() {
SB.config.hideDiscordLink = true;
Config.config.hideDiscordLink = true;
PageElements.discordButtonContainer.style.display = "none";
}
@ -984,7 +984,7 @@ async function runThePopup(messageListener?: MessageListener) {
{message: 'getChannelURL'},
function(response) {
//get whitelisted channels
let whitelistedChannels = SB.config.whitelistedChannels;
let whitelistedChannels = Config.config.whitelistedChannels;
if (whitelistedChannels == undefined) {
whitelistedChannels = [];
}
@ -1000,7 +1000,7 @@ async function runThePopup(messageListener?: MessageListener) {
PageElements.downloadedSponsorMessageTimes.style.fontWeight = "bold";
//save this
SB.config.whitelistedChannels = whitelistedChannels;
Config.config.whitelistedChannels = whitelistedChannels;
//send a message to the client
messageHandler.query({
@ -1030,7 +1030,7 @@ async function runThePopup(messageListener?: MessageListener) {
{message: 'getChannelURL'},
function(response) {
//get whitelisted channels
let whitelistedChannels = SB.config.whitelistedChannels;
let whitelistedChannels = Config.config.whitelistedChannels;
if (whitelistedChannels == undefined) {
whitelistedChannels = [];
}
@ -1047,7 +1047,7 @@ async function runThePopup(messageListener?: MessageListener) {
PageElements.downloadedSponsorMessageTimes.style.fontWeight = "unset";
//save this
SB.config.whitelistedChannels = whitelistedChannels;
Config.config.whitelistedChannels = whitelistedChannels;
//send a message to the client
messageHandler.query({
@ -1070,7 +1070,7 @@ async function runThePopup(messageListener?: MessageListener) {
* Should skipping be disabled (visuals stay)
*/
function toggleSkipping(disabled) {
SB.config.disableSkipping = disabled;
Config.config.disableSkipping = disabled;
let hiddenButton = PageElements.disableSkipping;
let shownButton = PageElements.enableSkipping;

View file

@ -1,5 +1,5 @@
import * as CompileConfig from "../config.json";
import SB from "./SB";
import Config from "./config";
class Utils {
@ -144,7 +144,8 @@ class Utils {
id: id
});
}
} else {
} else if (chrome.declarativeContent) {
// Only if we have permission
chrome.declarativeContent.onPageChanged.removeRules(["invidious"]);
}
@ -181,7 +182,7 @@ class Utils {
*/
getInvidiousInstancesRegex() {
var invidiousInstancesRegex = [];
for (const url of SB.config.invidiousInstances) {
for (const url of Config.config.invidiousInstances) {
invidiousInstancesRegex.push("https://*." + url + "/*");
invidiousInstancesRegex.push("http://*." + url + "/*");
}