mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-06 19:47:04 +03:00
@@ -29,7 +29,7 @@
|
|||||||
"build": "npm run build:chrome",
|
"build": "npm run build:chrome",
|
||||||
"build:chrome": "webpack --env.browser=chrome --config webpack/webpack.prod.js",
|
"build:chrome": "webpack --env.browser=chrome --config webpack/webpack.prod.js",
|
||||||
"build:firefox": "webpack --env.browser=firefox --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:chrome": "webpack --env.browser=chrome --config webpack/webpack.dev.js --watch",
|
||||||
"build:watch:firefox": "webpack --env.browser=firefox --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\"",
|
"dev": "npm run build && concurrently \"npm run web-run\" \"npm run build:watch\"",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import * as Types from "./types";
|
import * as Types from "./types";
|
||||||
import SB from "./SB";
|
import Config from "./config";
|
||||||
|
|
||||||
import Utils from "./utils";
|
import Utils from "./utils";
|
||||||
var utils = new Utils({
|
var utils = new Utils({
|
||||||
@@ -12,8 +12,8 @@ var contentScriptRegistrations = {};
|
|||||||
|
|
||||||
// Register content script if needed
|
// Register content script if needed
|
||||||
if (utils.isFirefox()) {
|
if (utils.isFirefox()) {
|
||||||
utils.wait(() => SB.config !== null).then(function() {
|
utils.wait(() => Config.config !== null).then(function() {
|
||||||
if (SB.config.supportInvidious) utils.setupExtraSiteContentScripts();
|
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 let's the config sync to run fully before checking.
|
||||||
// This is required on Firefox
|
// This is required on Firefox
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
const userID = SB.config.userID;
|
const userID = Config.config.userID;
|
||||||
|
|
||||||
// If there is no userID, then it is the first install.
|
// If there is no userID, then it is the first install.
|
||||||
if (!userID){
|
if (!userID){
|
||||||
@@ -84,11 +84,11 @@ chrome.runtime.onInstalled.addListener(function (object) {
|
|||||||
//generate a userID
|
//generate a userID
|
||||||
const newUserID = utils.generateUserID();
|
const newUserID = utils.generateUserID();
|
||||||
//save this UUID
|
//save this UUID
|
||||||
SB.config.userID = newUserID;
|
Config.config.userID = newUserID;
|
||||||
|
|
||||||
//TODO: Remove when invidious support is old
|
//TODO: Remove when invidious support is old
|
||||||
// Don't show this to new users
|
// Don't show this to new users
|
||||||
SB.config.invidiousUpdateInfoShowCount = 6;
|
Config.config.invidiousUpdateInfoShowCount = 6;
|
||||||
}
|
}
|
||||||
}, 1500);
|
}, 1500);
|
||||||
});
|
});
|
||||||
@@ -124,7 +124,7 @@ function unregisterFirefoxContentScript(id: string) {
|
|||||||
//gets the sponsor times from memory
|
//gets the sponsor times from memory
|
||||||
function getSponsorTimes(videoID, callback) {
|
function getSponsorTimes(videoID, callback) {
|
||||||
let sponsorTimes = [];
|
let sponsorTimes = [];
|
||||||
let sponsorTimesStorage = SB.config.sponsorTimes.get(videoID);
|
let sponsorTimesStorage = Config.config.sponsorTimes.get(videoID);
|
||||||
|
|
||||||
if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) {
|
if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) {
|
||||||
sponsorTimes = sponsorTimesStorage;
|
sponsorTimes = sponsorTimesStorage;
|
||||||
@@ -148,18 +148,18 @@ function addSponsorTime(time, videoID, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//save this info
|
//save this info
|
||||||
SB.config.sponsorTimes.set(videoID, sponsorTimes);
|
Config.config.sponsorTimes.set(videoID, sponsorTimes);
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function submitVote(type, UUID, callback) {
|
function submitVote(type, UUID, callback) {
|
||||||
let userID = SB.config.userID;
|
let userID = Config.config.userID;
|
||||||
|
|
||||||
if (userID == undefined || userID === "undefined") {
|
if (userID == undefined || userID === "undefined") {
|
||||||
//generate one
|
//generate one
|
||||||
userID = utils.generateUserID();
|
userID = utils.generateUserID();
|
||||||
SB.config.userID = userID;
|
Config.config.userID = userID;
|
||||||
}
|
}
|
||||||
|
|
||||||
//publish this vote
|
//publish this vote
|
||||||
@@ -187,8 +187,8 @@ function submitVote(type, UUID, callback) {
|
|||||||
|
|
||||||
async function submitTimes(videoID, callback) {
|
async function submitTimes(videoID, callback) {
|
||||||
//get the video times from storage
|
//get the video times from storage
|
||||||
let sponsorTimes = SB.config.sponsorTimes.get(videoID);
|
let sponsorTimes = Config.config.sponsorTimes.get(videoID);
|
||||||
let userID = SB.config.userID;
|
let userID = Config.config.userID;
|
||||||
|
|
||||||
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
|
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
|
||||||
let durationResult = <Types.videoDurationResponse> await new Promise((resolve, reject) => {
|
let durationResult = <Types.videoDurationResponse> await new Promise((resolve, reject) => {
|
||||||
@@ -226,7 +226,7 @@ async function submitTimes(videoID, callback) {
|
|||||||
//save the amount contributed
|
//save the amount contributed
|
||||||
if (!increasedContributionAmount) {
|
if (!increasedContributionAmount) {
|
||||||
increasedContributionAmount = true;
|
increasedContributionAmount = true;
|
||||||
SB.config.sponsorTimesContributed = SB.config.sponsorTimesContribute + sponsorTimes.length;
|
Config.config.sponsorTimesContributed = Config.config.sponsorTimesContributed + sponsorTimes.length;
|
||||||
}
|
}
|
||||||
} else if (error) {
|
} else if (error) {
|
||||||
callback({
|
callback({
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
interface SBConfig {
|
interface SBConfig {
|
||||||
|
userID: string,
|
||||||
sponsorTimes: SBMap<string, any>,
|
sponsorTimes: SBMap<string, any>,
|
||||||
|
whitelistedChannels: Array<any>,
|
||||||
startSponsorKeybind: string,
|
startSponsorKeybind: string,
|
||||||
submitKeybind: string,
|
submitKeybind: string,
|
||||||
minutesSaved: number,
|
minutesSaved: number,
|
||||||
@@ -16,22 +18,27 @@ interface SBConfig {
|
|||||||
hideDiscordLink: boolean,
|
hideDiscordLink: boolean,
|
||||||
invidiousInstances: string[],
|
invidiousInstances: string[],
|
||||||
invidiousUpdateInfoShowCount: number,
|
invidiousUpdateInfoShowCount: number,
|
||||||
autoUpvote: boolean
|
autoUpvote: boolean,
|
||||||
|
supportInvidious: false
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SBObject {
|
interface SBObject {
|
||||||
configListeners: Array<Function>;
|
configListeners: Array<Function>;
|
||||||
defaults: SBConfig;
|
defaults: SBConfig;
|
||||||
localConfig: any;
|
localConfig: SBConfig;
|
||||||
config: any;
|
config: SBConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allows a SBMap to be conveted into json form
|
// Allows a SBMap to be conveted into json form
|
||||||
// Currently used for local storage
|
// Currently used for local storage
|
||||||
class SBMap<T, U> extends Map {
|
class SBMap<T, U> extends Map {
|
||||||
constructor(entries?: [T, U][]) {
|
id: string;
|
||||||
|
|
||||||
|
constructor(id: string, entries?: [T, U][]) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
this.id = id;
|
||||||
|
|
||||||
// Import all entries if they were given
|
// Import all entries if they were given
|
||||||
if (entries !== undefined) {
|
if (entries !== undefined) {
|
||||||
for (const item of entries) {
|
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() {
|
toJSON() {
|
||||||
return Array.from(this.entries());
|
return Array.from(this.entries());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO: Rename to something more meaningful
|
var Config: SBObject = {
|
||||||
var SB: SBObject = {
|
|
||||||
/**
|
/**
|
||||||
* Callback function when an option is updated
|
* Callback function when an option is updated
|
||||||
*/
|
*/
|
||||||
configListeners: [],
|
configListeners: [],
|
||||||
defaults: {
|
defaults: {
|
||||||
sponsorTimes: new SBMap(),
|
userID: null,
|
||||||
|
sponsorTimes: new SBMap("sponsorTimes"),
|
||||||
|
whitelistedChannels: [],
|
||||||
startSponsorKeybind: ";",
|
startSponsorKeybind: ";",
|
||||||
submitKeybind: "'",
|
submitKeybind: "'",
|
||||||
minutesSaved: 0,
|
minutesSaved: 0,
|
||||||
@@ -70,7 +110,8 @@ var SB: SBObject = {
|
|||||||
hideDiscordLink: false,
|
hideDiscordLink: false,
|
||||||
invidiousInstances: ["invidio.us", "invidiou.sh", "invidious.snopyta.org"],
|
invidiousInstances: ["invidio.us", "invidiou.sh", "invidious.snopyta.org"],
|
||||||
invidiousUpdateInfoShowCount: 0,
|
invidiousUpdateInfoShowCount: 0,
|
||||||
autoUpvote: true
|
autoUpvote: true,
|
||||||
|
supportInvidious: false
|
||||||
},
|
},
|
||||||
localConfig: null,
|
localConfig: null,
|
||||||
config: null
|
config: null
|
||||||
@@ -78,58 +119,6 @@ var SB: SBObject = {
|
|||||||
|
|
||||||
// Function setup
|
// 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.
|
* A SBMap cannot be stored in the chrome storage.
|
||||||
* This data will be encoded into an array instead as specified by the toJSON function.
|
* 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
|
* This data will be decoded from the array it is stored in
|
||||||
*
|
*
|
||||||
* @param {*} data
|
* @param {*} data
|
||||||
*/
|
*/
|
||||||
function decodeStoredItem(data) {
|
function decodeStoredItem(id: string, data) {
|
||||||
if(typeof data !== "string") return data;
|
if(typeof data !== "string") return data;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let str = JSON.parse(data);
|
let str = JSON.parse(data);
|
||||||
|
|
||||||
if(!Array.isArray(str)) return data;
|
if(!Array.isArray(str)) return data;
|
||||||
return new SBMap(str);
|
return new SBMap(id, str);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
|
||||||
// If all else fails, return the data
|
// If all else fails, return the data
|
||||||
@@ -166,17 +155,17 @@ function decodeStoredItem(data) {
|
|||||||
function configProxy(): any {
|
function configProxy(): any {
|
||||||
chrome.storage.onChanged.addListener((changes, namespace) => {
|
chrome.storage.onChanged.addListener((changes, namespace) => {
|
||||||
for (const key in changes) {
|
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);
|
callback(changes);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var handler: ProxyHandler<any> = {
|
var handler: ProxyHandler<any> = {
|
||||||
set(obj, prop, value) {
|
set(obj, prop, value) {
|
||||||
SB.localConfig[prop] = value;
|
Config.localConfig[prop] = value;
|
||||||
|
|
||||||
chrome.storage.sync.set({
|
chrome.storage.sync.set({
|
||||||
[prop]: encodeStoredItem(value)
|
[prop]: encodeStoredItem(value)
|
||||||
@@ -186,8 +175,7 @@ function configProxy(): any {
|
|||||||
},
|
},
|
||||||
|
|
||||||
get(obj, prop): any {
|
get(obj, prop): any {
|
||||||
let data = SB.localConfig[prop];
|
let data = Config.localConfig[prop];
|
||||||
if(data instanceof SBMap) data = new MapIO(prop);
|
|
||||||
|
|
||||||
return obj[prop] || data;
|
return obj[prop] || data;
|
||||||
},
|
},
|
||||||
@@ -206,17 +194,17 @@ function configProxy(): any {
|
|||||||
function fetchConfig() {
|
function fetchConfig() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
chrome.storage.sync.get(null, function(items) {
|
chrome.storage.sync.get(null, function(items) {
|
||||||
SB.localConfig = items; // Data is ready
|
Config.localConfig = <SBConfig> <unknown> items; // Data is ready
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function migrateOldFormats() { // Convert sponsorTimes format
|
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") {
|
if (key.startsWith("sponsorTimes") && key !== "sponsorTimes" && key !== "sponsorTimesContributed") {
|
||||||
SB.config.sponsorTimes.set(key.substr(12), SB.config[key]);
|
Config.config.sponsorTimes.set(key.substr(12), Config.config[key]);
|
||||||
delete SB.config[key];
|
delete Config.config[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -225,26 +213,26 @@ async function setupConfig() {
|
|||||||
await fetchConfig();
|
await fetchConfig();
|
||||||
addDefaults();
|
addDefaults();
|
||||||
convertJSON();
|
convertJSON();
|
||||||
SB.config = configProxy();
|
Config.config = configProxy();
|
||||||
migrateOldFormats();
|
migrateOldFormats();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset config
|
// Reset config
|
||||||
function resetConfig() {
|
function resetConfig() {
|
||||||
SB.config = SB.defaults;
|
Config.config = Config.defaults;
|
||||||
};
|
};
|
||||||
|
|
||||||
function convertJSON() {
|
function convertJSON() {
|
||||||
Object.keys(SB.defaults).forEach(key => {
|
Object.keys(Config.defaults).forEach(key => {
|
||||||
SB.localConfig[key] = decodeStoredItem(SB.localConfig[key]);
|
Config.localConfig[key] = decodeStoredItem(key, Config.localConfig[key]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add defaults
|
// Add defaults
|
||||||
function addDefaults() {
|
function addDefaults() {
|
||||||
for (const key in SB.defaults) {
|
for (const key in Config.defaults) {
|
||||||
if(!SB.localConfig.hasOwnProperty(key)) {
|
if(!Config.localConfig.hasOwnProperty(key)) {
|
||||||
SB.localConfig[key] = SB.defaults[key];
|
Config.localConfig[key] = Config.defaults[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -252,4 +240,4 @@ function addDefaults() {
|
|||||||
// Sync config
|
// Sync config
|
||||||
setupConfig();
|
setupConfig();
|
||||||
|
|
||||||
export default SB;
|
export default Config;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import SB from "./SB";
|
import Config from "./config";
|
||||||
|
|
||||||
import Utils from "./utils";
|
import Utils from "./utils";
|
||||||
var utils = new Utils();
|
var utils = new Utils();
|
||||||
@@ -50,7 +50,7 @@ var previewBar = null;
|
|||||||
var controls = null;
|
var controls = null;
|
||||||
|
|
||||||
// Direct Links after the config is loaded
|
// 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)
|
//the last time looked at (used to see if this time is in the interval)
|
||||||
var lastTime = -1;
|
var lastTime = -1;
|
||||||
@@ -183,8 +183,8 @@ function contentConfigUpdateListener(changes) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SB.configListeners.includes(contentConfigUpdateListener)) {
|
if (!Config.configListeners.includes(contentConfigUpdateListener)) {
|
||||||
SB.configListeners.push(contentConfigUpdateListener);
|
Config.configListeners.push(contentConfigUpdateListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
//check for hotkey pressed
|
//check for hotkey pressed
|
||||||
@@ -193,9 +193,9 @@ document.onkeydown = function(e: KeyboardEvent){
|
|||||||
|
|
||||||
let video = document.getElementById("movie_player");
|
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
|
//is the video in focus, otherwise they could be typing a comment
|
||||||
if (document.activeElement === video) {
|
if (document.activeElement === video) {
|
||||||
@@ -270,7 +270,7 @@ function videoIDChange(id) {
|
|||||||
//warn them if they had unsubmitted times
|
//warn them if they had unsubmitted times
|
||||||
if (previousVideoID != null) {
|
if (previousVideoID != null) {
|
||||||
//get the sponsor times from storage
|
//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) {
|
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
|
||||||
//warn them that they have unsubmitted sponsor times
|
//warn them that they have unsubmitted sponsor times
|
||||||
chrome.runtime.sendMessage({
|
chrome.runtime.sendMessage({
|
||||||
@@ -408,7 +408,7 @@ function sponsorsLookup(id: string, channelIDPromise?) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//add the event to run on the videos "ontimeupdate"
|
//add the event to run on the videos "ontimeupdate"
|
||||||
if (!SB.config.disableSkipping) {
|
if (!Config.config.disableSkipping) {
|
||||||
v.ontimeupdate = function () {
|
v.ontimeupdate = function () {
|
||||||
sponsorCheck();
|
sponsorCheck();
|
||||||
};
|
};
|
||||||
@@ -429,12 +429,12 @@ function getYouTubeVideoID(url: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if valid hostname
|
// Check if valid hostname
|
||||||
if (SB.config && SB.config.invidiousInstances.includes(urlObject.host)) {
|
if (Config.config && Config.config.invidiousInstances.includes(urlObject.host)) {
|
||||||
onInvidious = true;
|
onInvidious = true;
|
||||||
} else if (!["www.youtube.com", "www.youtube-nocookie.com"].includes(urlObject.host)) {
|
} 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
|
// 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
|
return false
|
||||||
@@ -533,7 +533,7 @@ function updatePreviewBar() {
|
|||||||
//checks if this channel is whitelisted, should be done only after the channelID has been loaded
|
//checks if this channel is whitelisted, should be done only after the channelID has been loaded
|
||||||
function whitelistCheck() {
|
function whitelistCheck() {
|
||||||
//see if this is a whitelisted channel
|
//see if this is a whitelisted channel
|
||||||
let whitelistedChannels = SB.config.whitelistedChannels;
|
let whitelistedChannels = Config.config.whitelistedChannels;
|
||||||
|
|
||||||
if (whitelistedChannels != undefined && whitelistedChannels.includes(channelURL)) {
|
if (whitelistedChannels != undefined && whitelistedChannels.includes(channelURL)) {
|
||||||
channelWhitelisted = true;
|
channelWhitelisted = true;
|
||||||
@@ -542,7 +542,7 @@ function whitelistCheck() {
|
|||||||
|
|
||||||
//video skipping
|
//video skipping
|
||||||
function sponsorCheck() {
|
function sponsorCheck() {
|
||||||
if (SB.config.disableSkipping) {
|
if (Config.config.disableSkipping) {
|
||||||
// Make sure this isn't called again
|
// Make sure this isn't called again
|
||||||
v.ontimeupdate = null;
|
v.ontimeupdate = null;
|
||||||
return;
|
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
|
//skip fromt he start time to the end time for a certain index sponsor time
|
||||||
function skipToTime(v, index, sponsorTimes, openNotice) {
|
function skipToTime(v, index, sponsorTimes, openNotice) {
|
||||||
if (!SB.config.disableAutoSkip) {
|
if (!Config.config.disableAutoSkip) {
|
||||||
v.currentTime = sponsorTimes[index][1];
|
v.currentTime = sponsorTimes[index][1];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -619,24 +619,24 @@ function skipToTime(v, index, sponsorTimes, openNotice) {
|
|||||||
|
|
||||||
if (openNotice) {
|
if (openNotice) {
|
||||||
//send out the message saying that a sponsor message was skipped
|
//send out the message saying that a sponsor message was skipped
|
||||||
if (!SB.config.dontShowNotice) {
|
if (!Config.config.dontShowNotice) {
|
||||||
let skipNotice = new SkipNotice(this, currentUUID, SB.config.disableAutoSkip, skipNoticeContentContainer);
|
let skipNotice = new SkipNotice(this, currentUUID, Config.config.disableAutoSkip, skipNoticeContentContainer);
|
||||||
|
|
||||||
//auto-upvote this sponsor
|
//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);
|
vote(1, currentUUID, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//send telemetry that a this sponsor was skipped
|
//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);
|
utils.sendRequestToServer("POST", "/api/viewedVideoSponsorTime?UUID=" + currentUUID);
|
||||||
|
|
||||||
if (!SB.config.disableAutoSkip) {
|
if (!Config.config.disableAutoSkip) {
|
||||||
// Count this as a skip
|
// Count this as a skip
|
||||||
SB.config.minutesSaved = SB.config.minutesSaved + (sponsorTimes[index][1] - sponsorTimes[index][0]) / 60;
|
Config.config.minutesSaved = Config.config.minutesSaved + (sponsorTimes[index][1] - sponsorTimes[index][0]) / 60;
|
||||||
SB.config.skipCount = SB.config.skipCount + 1;
|
Config.config.skipCount = Config.config.skipCount + 1;
|
||||||
sponsorSkipped[index] = true;
|
sponsorSkipped[index] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -713,7 +713,7 @@ async function updateVisibilityOfPlayerControlsButton() {
|
|||||||
|
|
||||||
await createButtons();
|
await createButtons();
|
||||||
|
|
||||||
if (SB.config.hideVideoPlayerControls || onInvidious) {
|
if (Config.config.hideVideoPlayerControls || onInvidious) {
|
||||||
document.getElementById("startSponsorButton").style.display = "none";
|
document.getElementById("startSponsorButton").style.display = "none";
|
||||||
document.getElementById("submitButton").style.display = "none";
|
document.getElementById("submitButton").style.display = "none";
|
||||||
} else {
|
} else {
|
||||||
@@ -721,13 +721,13 @@ async function updateVisibilityOfPlayerControlsButton() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//don't show the info button on embeds
|
//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";
|
document.getElementById("infoButton").style.display = "none";
|
||||||
} else {
|
} else {
|
||||||
document.getElementById("infoButton").style.removeProperty("display");
|
document.getElementById("infoButton").style.removeProperty("display");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SB.config.hideDeleteButtonPlayerControls || onInvidious) {
|
if (Config.config.hideDeleteButtonPlayerControls || onInvidious) {
|
||||||
document.getElementById("deleteButton").style.display = "none";
|
document.getElementById("deleteButton").style.display = "none";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -779,7 +779,7 @@ async function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) {
|
|||||||
await utils.wait(isSubmitButtonLoaded);
|
await utils.wait(isSubmitButtonLoaded);
|
||||||
|
|
||||||
//if it isn't visible, there is no data
|
//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;
|
document.getElementById("deleteButton").style.display = shouldHide;
|
||||||
|
|
||||||
if (showStartSponsor) {
|
if (showStartSponsor) {
|
||||||
@@ -787,7 +787,7 @@ async function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) {
|
|||||||
(<HTMLImageElement> document.getElementById("startSponsorImage")).src = chrome.extension.getURL("icons/PlayerStartIconSponsorBlocker256px.png");
|
(<HTMLImageElement> document.getElementById("startSponsorImage")).src = chrome.extension.getURL("icons/PlayerStartIconSponsorBlocker256px.png");
|
||||||
document.getElementById("startSponsorButton").setAttribute("title", chrome.i18n.getMessage("sponsorStart"));
|
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";
|
document.getElementById("submitButton").style.display = "unset";
|
||||||
} else if (!uploadButtonVisible) {
|
} else if (!uploadButtonVisible) {
|
||||||
//disable submit button
|
//disable submit button
|
||||||
@@ -882,7 +882,7 @@ function clearSponsorTimes() {
|
|||||||
|
|
||||||
let currentVideoID = sponsorVideoID;
|
let currentVideoID = sponsorVideoID;
|
||||||
|
|
||||||
let sponsorTimes = SB.config.sponsorTimes.get(currentVideoID);
|
let sponsorTimes = Config.config.sponsorTimes.get(currentVideoID);
|
||||||
|
|
||||||
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
|
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
|
||||||
let confirmMessage = chrome.i18n.getMessage("clearThis") + getSponsorTimesMessage(sponsorTimes)
|
let confirmMessage = chrome.i18n.getMessage("clearThis") + getSponsorTimesMessage(sponsorTimes)
|
||||||
@@ -890,7 +890,7 @@ function clearSponsorTimes() {
|
|||||||
if(!confirm(confirmMessage)) return;
|
if(!confirm(confirmMessage)) return;
|
||||||
|
|
||||||
//clear the sponsor times
|
//clear the sponsor times
|
||||||
SB.config.sponsorTimes.delete(currentVideoID);
|
Config.config.sponsorTimes.delete(currentVideoID);
|
||||||
|
|
||||||
//clear sponsor times submitting
|
//clear sponsor times submitting
|
||||||
sponsorTimesSubmitting = [];
|
sponsorTimesSubmitting = [];
|
||||||
@@ -922,11 +922,11 @@ function vote(type, UUID, skipNotice) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Count this as a skip
|
// 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({
|
chrome.runtime.sendMessage({
|
||||||
@@ -964,7 +964,7 @@ function closeAllSkipNotices(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function dontShowNoticeAgain() {
|
function dontShowNoticeAgain() {
|
||||||
SB.config.dontShowNotice = true;
|
Config.config.dontShowNotice = true;
|
||||||
closeAllSkipNotices();
|
closeAllSkipNotices();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -991,7 +991,7 @@ function submitSponsorTimes() {
|
|||||||
|
|
||||||
let currentVideoID = sponsorVideoID;
|
let currentVideoID = sponsorVideoID;
|
||||||
|
|
||||||
let sponsorTimes = SB.config.sponsorTimes.get(currentVideoID);
|
let sponsorTimes = Config.config.sponsorTimes.get(currentVideoID);
|
||||||
|
|
||||||
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
|
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
|
||||||
//check if a sponsor exceeds the duration of the video
|
//check if a sponsor exceeds the duration of the video
|
||||||
@@ -1001,7 +1001,7 @@ function submitSponsorTimes() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//update sponsorTimes
|
//update sponsorTimes
|
||||||
SB.config.sponsorTimes.set(currentVideoID, sponsorTimes);
|
Config.config.sponsorTimes.set(currentVideoID, sponsorTimes);
|
||||||
|
|
||||||
//update sponsorTimesSubmitting
|
//update sponsorTimesSubmitting
|
||||||
sponsorTimesSubmitting = sponsorTimes;
|
sponsorTimesSubmitting = sponsorTimes;
|
||||||
@@ -1046,7 +1046,7 @@ function sendSubmitMessage(){
|
|||||||
submitButton.addEventListener("animationend", animationEndListener);
|
submitButton.addEventListener("animationend", animationEndListener);
|
||||||
|
|
||||||
//clear the sponsor times
|
//clear the sponsor times
|
||||||
SB.config.sponsorTimes.delete(currentVideoID);
|
Config.config.sponsorTimes.delete(currentVideoID);
|
||||||
|
|
||||||
//add submissions to current sponsors list
|
//add submissions to current sponsors list
|
||||||
sponsorTimes = sponsorTimes.concat(sponsorTimesSubmitting);
|
sponsorTimes = sponsorTimes.concat(sponsorTimesSubmitting);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import SB from "./SB";
|
import Config from "./config";
|
||||||
|
|
||||||
import Utils from "./utils";
|
import Utils from "./utils";
|
||||||
var utils = new Utils();
|
var utils = new Utils();
|
||||||
@@ -8,11 +8,11 @@ window.addEventListener('DOMContentLoaded', init);
|
|||||||
async function init() {
|
async function init() {
|
||||||
utils.localizeHtmlPage();
|
utils.localizeHtmlPage();
|
||||||
|
|
||||||
if (!SB.configListeners.includes(optionsConfigUpdateListener)) {
|
if (!Config.configListeners.includes(optionsConfigUpdateListener)) {
|
||||||
SB.configListeners.push(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
|
// Set all of the toggle options to the correct option
|
||||||
let optionsContainer = document.getElementById("options");
|
let optionsContainer = document.getElementById("options");
|
||||||
@@ -22,7 +22,7 @@ async function init() {
|
|||||||
switch (optionsElements[i].getAttribute("option-type")) {
|
switch (optionsElements[i].getAttribute("option-type")) {
|
||||||
case "toggle":
|
case "toggle":
|
||||||
let option = optionsElements[i].getAttribute("sync-option");
|
let option = optionsElements[i].getAttribute("sync-option");
|
||||||
let optionResult = SB.config[option];
|
let optionResult = Config.config[option];
|
||||||
|
|
||||||
let checkbox = optionsElements[i].querySelector("input");
|
let checkbox = optionsElements[i].querySelector("input");
|
||||||
let reverse = optionsElements[i].getAttribute("toggle-type") === "reverse";
|
let reverse = optionsElements[i].getAttribute("toggle-type") === "reverse";
|
||||||
@@ -44,7 +44,7 @@ async function init() {
|
|||||||
|
|
||||||
// Add click listener
|
// Add click listener
|
||||||
checkbox.addEventListener("click", () => {
|
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
|
// See if anything extra must be run
|
||||||
switch (option) {
|
switch (option) {
|
||||||
@@ -104,7 +104,7 @@ function optionsConfigUpdateListener(changes) {
|
|||||||
*/
|
*/
|
||||||
function updateDisplayElement(element: HTMLElement) {
|
function updateDisplayElement(element: HTMLElement) {
|
||||||
let displayOption = element.getAttribute("sync-option")
|
let displayOption = element.getAttribute("sync-option")
|
||||||
let displayText = SB.config[displayOption];
|
let displayText = Config.config[displayOption];
|
||||||
element.innerText = displayText;
|
element.innerText = displayText;
|
||||||
|
|
||||||
// See if anything extra must be run
|
// See if anything extra must be run
|
||||||
@@ -131,12 +131,12 @@ function invidiousInstanceAddInit(element: HTMLElement, option: string) {
|
|||||||
alert(chrome.i18n.getMessage("addInvidiousInstanceError"));
|
alert(chrome.i18n.getMessage("addInvidiousInstanceError"));
|
||||||
} else {
|
} else {
|
||||||
// Add this
|
// Add this
|
||||||
let instanceList = SB.config[option];
|
let instanceList = Config.config[option];
|
||||||
if (!instanceList) instanceList = [];
|
if (!instanceList) instanceList = [];
|
||||||
|
|
||||||
instanceList.push(textBox.value);
|
instanceList.push(textBox.value);
|
||||||
|
|
||||||
SB.config[option] = instanceList;
|
Config.config[option] = instanceList;
|
||||||
|
|
||||||
let checkbox = <HTMLInputElement> document.querySelector("#support-invidious input");
|
let checkbox = <HTMLInputElement> document.querySelector("#support-invidious input");
|
||||||
checkbox.checked = true;
|
checkbox.checked = true;
|
||||||
@@ -155,7 +155,7 @@ function invidiousInstanceAddInit(element: HTMLElement, option: string) {
|
|||||||
resetButton.addEventListener("click", function(e) {
|
resetButton.addEventListener("click", function(e) {
|
||||||
if (confirm(chrome.i18n.getMessage("resetInvidiousInstanceAlert"))) {
|
if (confirm(chrome.i18n.getMessage("resetInvidiousInstanceAlert"))) {
|
||||||
// Set to a clone of the default
|
// 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
|
permissions: permissions
|
||||||
}, function (result) {
|
}, function (result) {
|
||||||
if (result != checkbox.checked) {
|
if (result != checkbox.checked) {
|
||||||
SB.config[option] = result;
|
Config.config[option] = result;
|
||||||
|
|
||||||
checkbox.checked = result;
|
checkbox.checked = result;
|
||||||
}
|
}
|
||||||
@@ -192,7 +192,7 @@ function invidiousOnClick(checkbox: HTMLInputElement, option: string) {
|
|||||||
if (checkbox.checked) {
|
if (checkbox.checked) {
|
||||||
utils.setupExtraSitePermissions(function (granted) {
|
utils.setupExtraSitePermissions(function (granted) {
|
||||||
if (!granted) {
|
if (!granted) {
|
||||||
SB.config[option] = false;
|
Config.config[option] = false;
|
||||||
checkbox.checked = false;
|
checkbox.checked = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -214,14 +214,14 @@ function activateKeybindChange(element: HTMLElement) {
|
|||||||
|
|
||||||
let option = element.getAttribute("sync-option");
|
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");
|
let status = <HTMLElement> element.querySelector(".option-hidden-section > .keybind-status");
|
||||||
status.innerText = chrome.i18n.getMessage("keybindDescription") + currentlySet;
|
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");
|
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");
|
element.querySelector(".option-hidden-section").classList.remove("hidden");
|
||||||
@@ -249,7 +249,7 @@ function keybindKeyPressed(element: HTMLElement, e: KeyboardEvent) {
|
|||||||
|
|
||||||
let option = element.getAttribute("sync-option");
|
let option = element.getAttribute("sync-option");
|
||||||
|
|
||||||
SB.config[option] = key;
|
Config.config[option] = key;
|
||||||
|
|
||||||
let status = <HTMLElement> element.querySelector(".option-hidden-section > .keybind-status");
|
let status = <HTMLElement> element.querySelector(".option-hidden-section > .keybind-status");
|
||||||
status.innerText = chrome.i18n.getMessage("keybindDescriptionComplete");
|
status.innerText = chrome.i18n.getMessage("keybindDescriptionComplete");
|
||||||
@@ -281,14 +281,14 @@ function activateTextChange(element: HTMLElement) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
textBox.value = SB.config[option];
|
textBox.value = Config.config[option];
|
||||||
|
|
||||||
let setButton = element.querySelector(".text-change-set");
|
let setButton = element.querySelector(".text-change-set");
|
||||||
setButton.addEventListener("click", () => {
|
setButton.addEventListener("click", () => {
|
||||||
let confirmMessage = element.getAttribute("confirm-message");
|
let confirmMessage = element.getAttribute("confirm-message");
|
||||||
|
|
||||||
if (confirmMessage === null || confirm(chrome.i18n.getMessage(confirmMessage))) {
|
if (confirmMessage === null || confirm(chrome.i18n.getMessage(confirmMessage))) {
|
||||||
SB.config[option] = textBox.value;
|
Config.config[option] = textBox.value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
62
src/popup.ts
62
src/popup.ts
@@ -1,4 +1,4 @@
|
|||||||
import SB from "./SB";
|
import Config from "./config";
|
||||||
|
|
||||||
import Utils from "./utils";
|
import Utils from "./utils";
|
||||||
var utils = new Utils();
|
var utils = new Utils();
|
||||||
@@ -42,7 +42,7 @@ async function runThePopup(messageListener?: MessageListener) {
|
|||||||
|
|
||||||
utils.localizeHtmlPage();
|
utils.localizeHtmlPage();
|
||||||
|
|
||||||
await utils.wait(() => SB.config !== null);
|
await utils.wait(() => Config.config !== null);
|
||||||
|
|
||||||
var PageElements: any = {};
|
var PageElements: any = {};
|
||||||
|
|
||||||
@@ -127,9 +127,9 @@ async function runThePopup(messageListener?: MessageListener) {
|
|||||||
let currentVideoID = null;
|
let currentVideoID = null;
|
||||||
|
|
||||||
//see if discord link can be shown
|
//see if discord link can be shown
|
||||||
let hideDiscordLink = SB.config.hideDiscordLink;
|
let hideDiscordLink = Config.config.hideDiscordLink;
|
||||||
if (hideDiscordLink == undefined || !hideDiscordLink) {
|
if (hideDiscordLink == undefined || !hideDiscordLink) {
|
||||||
let hideDiscordLaunches = SB.config.hideDiscordLaunches;
|
let hideDiscordLaunches = Config.config.hideDiscordLaunches;
|
||||||
//only if less than 10 launches
|
//only if less than 10 launches
|
||||||
if (hideDiscordLaunches == undefined || hideDiscordLaunches < 10) {
|
if (hideDiscordLaunches == undefined || hideDiscordLaunches < 10) {
|
||||||
PageElements.discordButtonContainer.style.display = null;
|
PageElements.discordButtonContainer.style.display = null;
|
||||||
@@ -137,12 +137,12 @@ async function runThePopup(messageListener?: MessageListener) {
|
|||||||
if (hideDiscordLaunches == undefined) {
|
if (hideDiscordLaunches == undefined) {
|
||||||
hideDiscordLaunches = 1;
|
hideDiscordLaunches = 1;
|
||||||
}
|
}
|
||||||
SB.config.hideDiscordLaunches = hideDiscordLaunches + 1;
|
Config.config.hideDiscordLaunches = hideDiscordLaunches + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//show proper disable skipping button
|
//show proper disable skipping button
|
||||||
let disableSkipping = SB.config.disableSkipping;
|
let disableSkipping = Config.config.disableSkipping;
|
||||||
if (disableSkipping != undefined && disableSkipping) {
|
if (disableSkipping != undefined && disableSkipping) {
|
||||||
PageElements.disableSkipping.style.display = "none";
|
PageElements.disableSkipping.style.display = "none";
|
||||||
PageElements.enableSkipping.style.display = "unset";
|
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
|
//if the don't show notice again variable is true, an option to
|
||||||
// disable should be available
|
// disable should be available
|
||||||
let dontShowNotice = SB.config.dontShowNotice;
|
let dontShowNotice = Config.config.dontShowNotice;
|
||||||
if (dontShowNotice != undefined && dontShowNotice) {
|
if (dontShowNotice != undefined && dontShowNotice) {
|
||||||
PageElements.showNoticeAgain.style.display = "unset";
|
PageElements.showNoticeAgain.style.display = "unset";
|
||||||
}
|
}
|
||||||
|
|
||||||
//get the amount of times this user has contributed and display it to thank them
|
//get the amount of times this user has contributed and display it to thank them
|
||||||
if (SB.config.sponsorTimesContributed != undefined) {
|
if (Config.config.sponsorTimesContributed != undefined) {
|
||||||
if (SB.config.sponsorTimesContributed > 1) {
|
if (Config.config.sponsorTimesContributed > 1) {
|
||||||
PageElements.sponsorTimesContributionsDisplayEndWord.innerText = chrome.i18n.getMessage("Sponsors");
|
PageElements.sponsorTimesContributionsDisplayEndWord.innerText = chrome.i18n.getMessage("Sponsors");
|
||||||
} else {
|
} else {
|
||||||
PageElements.sponsorTimesContributionsDisplayEndWord.innerText = chrome.i18n.getMessage("Sponsor");
|
PageElements.sponsorTimesContributionsDisplayEndWord.innerText = chrome.i18n.getMessage("Sponsor");
|
||||||
}
|
}
|
||||||
PageElements.sponsorTimesContributionsDisplay.innerText = SB.config.sponsorTimesContributed;
|
PageElements.sponsorTimesContributionsDisplay.innerText = Config.config.sponsorTimesContributed;
|
||||||
PageElements.sponsorTimesContributionsContainer.style.display = "unset";
|
PageElements.sponsorTimesContributionsContainer.style.display = "unset";
|
||||||
|
|
||||||
//get the userID
|
//get the userID
|
||||||
let userID = SB.config.userID;
|
let userID = Config.config.userID;
|
||||||
if (userID != undefined) {
|
if (userID != undefined) {
|
||||||
//there are probably some views on these submissions then
|
//there are probably some views on these submissions then
|
||||||
//get the amount of views from the sponsors submitted
|
//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
|
//get the amount of times this user has skipped a sponsor
|
||||||
if (SB.config.skipCount != undefined) {
|
if (Config.config.skipCount != undefined) {
|
||||||
if (SB.config.skipCount != 1) {
|
if (Config.config.skipCount != 1) {
|
||||||
PageElements.sponsorTimesSkipsDoneEndWord.innerText = chrome.i18n.getMessage("Sponsors");
|
PageElements.sponsorTimesSkipsDoneEndWord.innerText = chrome.i18n.getMessage("Sponsors");
|
||||||
} else {
|
} else {
|
||||||
PageElements.sponsorTimesSkipsDoneEndWord.innerText = chrome.i18n.getMessage("Sponsor");
|
PageElements.sponsorTimesSkipsDoneEndWord.innerText = chrome.i18n.getMessage("Sponsor");
|
||||||
}
|
}
|
||||||
|
|
||||||
PageElements.sponsorTimesSkipsDoneDisplay.innerText = SB.config.skipCount;
|
PageElements.sponsorTimesSkipsDoneDisplay.innerText = Config.config.skipCount;
|
||||||
PageElements.sponsorTimesSkipsDoneContainer.style.display = "unset";
|
PageElements.sponsorTimesSkipsDoneContainer.style.display = "unset";
|
||||||
}
|
}
|
||||||
|
|
||||||
//get the amount of time this user has saved.
|
//get the amount of time this user has saved.
|
||||||
if (SB.config.minutesSaved != undefined) {
|
if (Config.config.minutesSaved != undefined) {
|
||||||
if (SB.config.minutesSaved != 1) {
|
if (Config.config.minutesSaved != 1) {
|
||||||
PageElements.sponsorTimeSavedEndWord.innerText = chrome.i18n.getMessage("minsLower");
|
PageElements.sponsorTimeSavedEndWord.innerText = chrome.i18n.getMessage("minsLower");
|
||||||
} else {
|
} else {
|
||||||
PageElements.sponsorTimeSavedEndWord.innerText = chrome.i18n.getMessage("minLower");
|
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";
|
PageElements.sponsorTimeSavedContainer.style.display = "unset";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,7 +254,7 @@ async function runThePopup(messageListener?: MessageListener) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//load video times for this video
|
//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 != undefined && sponsorTimesStorage.length > 0) {
|
||||||
if (sponsorTimesStorage[sponsorTimesStorage.length - 1] != undefined && sponsorTimesStorage[sponsorTimesStorage.length - 1].length < 2) {
|
if (sponsorTimesStorage[sponsorTimesStorage.length - 1] != undefined && sponsorTimesStorage[sponsorTimesStorage.length - 1].length < 2) {
|
||||||
startTimeChosen = true;
|
startTimeChosen = true;
|
||||||
@@ -346,7 +346,7 @@ async function runThePopup(messageListener?: MessageListener) {
|
|||||||
sponsorTimes[sponsorTimesIndex][startTimeChosen ? 1 : 0] = response.time;
|
sponsorTimes[sponsorTimesIndex][startTimeChosen ? 1 : 0] = response.time;
|
||||||
|
|
||||||
let localStartTimeChosen = startTimeChosen;
|
let localStartTimeChosen = startTimeChosen;
|
||||||
SB.config.sponsorTimes.set(currentVideoID, sponsorTimes);
|
Config.config.sponsorTimes.set(currentVideoID, sponsorTimes);
|
||||||
|
|
||||||
//send a message to the client script
|
//send a message to the client script
|
||||||
if (localStartTimeChosen) {
|
if (localStartTimeChosen) {
|
||||||
@@ -679,7 +679,7 @@ async function runThePopup(messageListener?: MessageListener) {
|
|||||||
sponsorTimes[index][1] = getSponsorTimeEditTimes("endTime", index);
|
sponsorTimes[index][1] = getSponsorTimeEditTimes("endTime", index);
|
||||||
|
|
||||||
//save this
|
//save this
|
||||||
SB.config.sponsorTimes.set(currentVideoID, sponsorTimes);
|
Config.config.sponsorTimes.set(currentVideoID, sponsorTimes);
|
||||||
messageHandler.query({
|
messageHandler.query({
|
||||||
active: true,
|
active: true,
|
||||||
currentWindow: true
|
currentWindow: true
|
||||||
@@ -718,7 +718,7 @@ async function runThePopup(messageListener?: MessageListener) {
|
|||||||
sponsorTimes.splice(index, 1);
|
sponsorTimes.splice(index, 1);
|
||||||
|
|
||||||
//save this
|
//save this
|
||||||
SB.config.sponsorTimes.set(currentVideoID, sponsorTimes);
|
Config.config.sponsorTimes.set(currentVideoID, sponsorTimes);
|
||||||
messageHandler.query({
|
messageHandler.query({
|
||||||
active: true,
|
active: true,
|
||||||
currentWindow: true
|
currentWindow: true
|
||||||
@@ -769,7 +769,7 @@ async function runThePopup(messageListener?: MessageListener) {
|
|||||||
//reset sponsorTimes
|
//reset sponsorTimes
|
||||||
sponsorTimes = [];
|
sponsorTimes = [];
|
||||||
|
|
||||||
SB.config.sponsorTimes.set(currentVideoID, sponsorTimes);
|
Config.config.sponsorTimes.set(currentVideoID, sponsorTimes);
|
||||||
messageHandler.query({
|
messageHandler.query({
|
||||||
active: true,
|
active: true,
|
||||||
currentWindow: true
|
currentWindow: true
|
||||||
@@ -816,7 +816,7 @@ async function runThePopup(messageListener?: MessageListener) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function showNoticeAgain() {
|
function showNoticeAgain() {
|
||||||
SB.config.dontShowNotice = false;
|
Config.config.dontShowNotice = false;
|
||||||
|
|
||||||
PageElements.showNoticeAgain.style.display = "none";
|
PageElements.showNoticeAgain.style.display = "none";
|
||||||
}
|
}
|
||||||
@@ -857,7 +857,7 @@ async function runThePopup(messageListener?: MessageListener) {
|
|||||||
//make the options username setting option visible
|
//make the options username setting option visible
|
||||||
function setUsernameButton() {
|
function setUsernameButton() {
|
||||||
//get username from the server
|
//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) {
|
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
||||||
PageElements.usernameInput.value = JSON.parse(xmlhttp.responseText).userName;
|
PageElements.usernameInput.value = JSON.parse(xmlhttp.responseText).userName;
|
||||||
|
|
||||||
@@ -886,7 +886,7 @@ async function runThePopup(messageListener?: MessageListener) {
|
|||||||
PageElements.setUsernameStatus.innerText = "Loading...";
|
PageElements.setUsernameStatus.innerText = "Loading...";
|
||||||
|
|
||||||
//get the userID
|
//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) {
|
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
||||||
//submitted
|
//submitted
|
||||||
PageElements.submitUsername.style.display = "none";
|
PageElements.submitUsername.style.display = "none";
|
||||||
@@ -954,7 +954,7 @@ async function runThePopup(messageListener?: MessageListener) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function hideDiscordButton() {
|
function hideDiscordButton() {
|
||||||
SB.config.hideDiscordLink = true;
|
Config.config.hideDiscordLink = true;
|
||||||
PageElements.discordButtonContainer.style.display = "none";
|
PageElements.discordButtonContainer.style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -984,7 +984,7 @@ async function runThePopup(messageListener?: MessageListener) {
|
|||||||
{message: 'getChannelURL'},
|
{message: 'getChannelURL'},
|
||||||
function(response) {
|
function(response) {
|
||||||
//get whitelisted channels
|
//get whitelisted channels
|
||||||
let whitelistedChannels = SB.config.whitelistedChannels;
|
let whitelistedChannels = Config.config.whitelistedChannels;
|
||||||
if (whitelistedChannels == undefined) {
|
if (whitelistedChannels == undefined) {
|
||||||
whitelistedChannels = [];
|
whitelistedChannels = [];
|
||||||
}
|
}
|
||||||
@@ -1000,7 +1000,7 @@ async function runThePopup(messageListener?: MessageListener) {
|
|||||||
PageElements.downloadedSponsorMessageTimes.style.fontWeight = "bold";
|
PageElements.downloadedSponsorMessageTimes.style.fontWeight = "bold";
|
||||||
|
|
||||||
//save this
|
//save this
|
||||||
SB.config.whitelistedChannels = whitelistedChannels;
|
Config.config.whitelistedChannels = whitelistedChannels;
|
||||||
|
|
||||||
//send a message to the client
|
//send a message to the client
|
||||||
messageHandler.query({
|
messageHandler.query({
|
||||||
@@ -1030,7 +1030,7 @@ async function runThePopup(messageListener?: MessageListener) {
|
|||||||
{message: 'getChannelURL'},
|
{message: 'getChannelURL'},
|
||||||
function(response) {
|
function(response) {
|
||||||
//get whitelisted channels
|
//get whitelisted channels
|
||||||
let whitelistedChannels = SB.config.whitelistedChannels;
|
let whitelistedChannels = Config.config.whitelistedChannels;
|
||||||
if (whitelistedChannels == undefined) {
|
if (whitelistedChannels == undefined) {
|
||||||
whitelistedChannels = [];
|
whitelistedChannels = [];
|
||||||
}
|
}
|
||||||
@@ -1047,7 +1047,7 @@ async function runThePopup(messageListener?: MessageListener) {
|
|||||||
PageElements.downloadedSponsorMessageTimes.style.fontWeight = "unset";
|
PageElements.downloadedSponsorMessageTimes.style.fontWeight = "unset";
|
||||||
|
|
||||||
//save this
|
//save this
|
||||||
SB.config.whitelistedChannels = whitelistedChannels;
|
Config.config.whitelistedChannels = whitelistedChannels;
|
||||||
|
|
||||||
//send a message to the client
|
//send a message to the client
|
||||||
messageHandler.query({
|
messageHandler.query({
|
||||||
@@ -1070,7 +1070,7 @@ async function runThePopup(messageListener?: MessageListener) {
|
|||||||
* Should skipping be disabled (visuals stay)
|
* Should skipping be disabled (visuals stay)
|
||||||
*/
|
*/
|
||||||
function toggleSkipping(disabled) {
|
function toggleSkipping(disabled) {
|
||||||
SB.config.disableSkipping = disabled;
|
Config.config.disableSkipping = disabled;
|
||||||
|
|
||||||
let hiddenButton = PageElements.disableSkipping;
|
let hiddenButton = PageElements.disableSkipping;
|
||||||
let shownButton = PageElements.enableSkipping;
|
let shownButton = PageElements.enableSkipping;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import * as CompileConfig from "../config.json";
|
import * as CompileConfig from "../config.json";
|
||||||
import SB from "./SB";
|
import Config from "./config";
|
||||||
|
|
||||||
class Utils {
|
class Utils {
|
||||||
|
|
||||||
@@ -144,7 +144,8 @@ class Utils {
|
|||||||
id: id
|
id: id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else if (chrome.declarativeContent) {
|
||||||
|
// Only if we have permission
|
||||||
chrome.declarativeContent.onPageChanged.removeRules(["invidious"]);
|
chrome.declarativeContent.onPageChanged.removeRules(["invidious"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,7 +182,7 @@ class Utils {
|
|||||||
*/
|
*/
|
||||||
getInvidiousInstancesRegex() {
|
getInvidiousInstancesRegex() {
|
||||||
var invidiousInstancesRegex = [];
|
var invidiousInstancesRegex = [];
|
||||||
for (const url of SB.config.invidiousInstances) {
|
for (const url of Config.config.invidiousInstances) {
|
||||||
invidiousInstancesRegex.push("https://*." + url + "/*");
|
invidiousInstancesRegex.push("https://*." + url + "/*");
|
||||||
invidiousInstancesRegex.push("http://*." + url + "/*");
|
invidiousInstancesRegex.push("http://*." + url + "/*");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user