mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 09:07:45 +01:00
Merge branch 'master' of https://github.com/ajayyy/SponsorBlock into add-invidious
# Conflicts: # background.js # content.js # options/options.js
This commit is contained in:
commit
0481943737
10 changed files with 519 additions and 523 deletions
175
SB.js
Normal file
175
SB.js
Normal file
|
@ -0,0 +1,175 @@
|
|||
SB = {};
|
||||
|
||||
// Function setup
|
||||
|
||||
Map.prototype.toJSON = function() {
|
||||
return Array.from(this.entries());
|
||||
};
|
||||
|
||||
class MapIO {
|
||||
constructor(id) {
|
||||
this.id = id;
|
||||
this.map = SB.localConfig[this.id];
|
||||
}
|
||||
|
||||
set(key, value) {
|
||||
this.map.set(key, value);
|
||||
|
||||
SB.config.handler.set(undefined, this.id, encodeStoredItem(this.map));
|
||||
|
||||
return this.map;
|
||||
}
|
||||
|
||||
get(key) {
|
||||
return this.map.get(key);
|
||||
}
|
||||
|
||||
has(key) {
|
||||
return this.map.has(key);
|
||||
}
|
||||
|
||||
deleteProperty(key) {
|
||||
if (this.map.has(key)) {
|
||||
this.map.delete(key);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
size() {
|
||||
return this.map.size;
|
||||
}
|
||||
|
||||
delete(key) {
|
||||
this.map.delete(key);
|
||||
|
||||
SB.config.handler.set(undefined, this.id, encodeStoredItem(this.map));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A Map cannot be stored in the chrome storage.
|
||||
* This data will be encoded into an array instead as specified by the toJSON function.
|
||||
*
|
||||
* @param {*} data
|
||||
*/
|
||||
function encodeStoredItem(data) {
|
||||
if(!(data instanceof Map)) return data;
|
||||
return JSON.stringify(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Map cannot be stored in the chrome storage.
|
||||
* This data will be decoded from the array it is stored in
|
||||
*
|
||||
* @param {*} data
|
||||
*/
|
||||
function decodeStoredItem(data) {
|
||||
if(typeof data !== "string") return data;
|
||||
|
||||
try {
|
||||
let str = JSON.parse(data);
|
||||
|
||||
if(!Array.isArray(str)) return data;
|
||||
return new Map(str);
|
||||
} catch(e) {
|
||||
|
||||
// If all else fails, return the data
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
function configProxy() {
|
||||
chrome.storage.onChanged.addListener((changes, namespace) => {
|
||||
for (key in changes) {
|
||||
SB.localConfig[key] = decodeStoredItem(changes[key].newValue);
|
||||
}
|
||||
});
|
||||
|
||||
var handler = {
|
||||
set: function(obj, prop, value) {
|
||||
SB.localConfig[prop] = value;
|
||||
|
||||
chrome.storage.sync.set({
|
||||
[prop]: encodeStoredItem(value)
|
||||
});
|
||||
},
|
||||
get: function(obj, prop) {
|
||||
let data = SB.localConfig[prop];
|
||||
if(data instanceof Map) data = new MapIO(prop);
|
||||
|
||||
return obj[prop] || data;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
return new Proxy({handler}, handler);
|
||||
}
|
||||
|
||||
function fetchConfig() {
|
||||
return new Promise((resolve, reject) => {
|
||||
chrome.storage.sync.get(null, function(items) {
|
||||
SB.localConfig = items; // Data is ready
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function migrateOldFormats() { // Convert sponsorTimes format
|
||||
for (key in SB.localConfig) {
|
||||
if (key.startsWith("sponsorTimes") && key !== "sponsorTimes" && key !== "sponsorTimesContributed") {
|
||||
SB.config.sponsorTimes.set(key.substr(12), SB.config[key]);
|
||||
delete SB.config[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function setupConfig() {
|
||||
await fetchConfig();
|
||||
addDefaults();
|
||||
convertJSON();
|
||||
SB.config = configProxy();
|
||||
migrateOldFormats();
|
||||
}
|
||||
|
||||
SB.defaults = {
|
||||
"sponsorTimes": new Map(),
|
||||
"startSponsorKeybind": ";",
|
||||
"submitKeybind": "'",
|
||||
"minutesSaved": 0,
|
||||
"skipCount": 0,
|
||||
"sponsorTimesContributed": 0,
|
||||
"disableSkipping": false,
|
||||
"disableAutoSkip": false,
|
||||
"trackViewCount": true,
|
||||
"dontShowNotice": false,
|
||||
"hideVideoPlayerControls": false,
|
||||
"hideInfoButtonPlayerControls": false,
|
||||
"hideDeleteButtonPlayerControls": false,
|
||||
"hideDiscordLaunches": 0,
|
||||
"hideDiscordLink": false
|
||||
}
|
||||
|
||||
// Reset config
|
||||
function resetConfig() {
|
||||
SB.config = SB.defaults;
|
||||
};
|
||||
|
||||
function convertJSON() {
|
||||
Object.keys(SB.defaults).forEach(key => {
|
||||
SB.localConfig[key] = decodeStoredItem(SB.localConfig[key], key);
|
||||
});
|
||||
}
|
||||
|
||||
// Add defaults
|
||||
function addDefaults() {
|
||||
Object.keys(SB.defaults).forEach(key => {
|
||||
if(!SB.localConfig.hasOwnProperty(key)) {
|
||||
SB.localConfig[key] = SB.defaults[key];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Sync config
|
||||
setupConfig();
|
173
background.js
173
background.js
|
@ -7,7 +7,9 @@ chrome.tabs.onUpdated.addListener(function(tabId) {
|
|||
}, () => void chrome.runtime.lastError ); // Suppress error on Firefox
|
||||
});
|
||||
|
||||
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
||||
chrome.runtime.onMessage.addListener(async function (request, sender, callback) {
|
||||
await wait(() => SB.config !== undefined);
|
||||
|
||||
switch(request.message) {
|
||||
case "submitTimes":
|
||||
submitTimes(request.videoID, callback);
|
||||
|
@ -18,7 +20,8 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
|||
addSponsorTime(request.time, request.videoID, callback);
|
||||
|
||||
//this allows the callback to be called later
|
||||
return true;
|
||||
return true;
|
||||
|
||||
case "getSponsorTimes":
|
||||
getSponsorTimes(request.videoID, function(sponsorTimes) {
|
||||
callback({
|
||||
|
@ -40,7 +43,6 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
|||
message: chrome.i18n.getMessage("leftTimes"),
|
||||
iconUrl: "./icons/LogoSponsorBlocker256px.png"
|
||||
});
|
||||
return false;
|
||||
case "registerContentScript":
|
||||
browser.contentScripts.register({
|
||||
allFrames: request.allFrames,
|
||||
|
@ -55,43 +57,37 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
|||
delete contentScriptRegistrations[request.id];
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//add help page on install
|
||||
chrome.runtime.onInstalled.addListener(function (object) {
|
||||
setTimeout(function() {
|
||||
chrome.storage.sync.get(["userID"], function(result) {
|
||||
const userID = result.userID;
|
||||
const userID = SB.config.userID;
|
||||
|
||||
// If there is no userID, then it is the first install.
|
||||
if (!userID){
|
||||
//open up the install page
|
||||
chrome.tabs.create({url: chrome.extension.getURL("/help/index_en.html")});
|
||||
// If there is no userID, then it is the first install.
|
||||
if (!userID){
|
||||
//open up the install page
|
||||
chrome.tabs.create({url: chrome.extension.getURL("/help/index_en.html")});
|
||||
|
||||
//generate a userID
|
||||
const newUserID = generateUserID();
|
||||
//save this UUID
|
||||
chrome.storage.sync.set({
|
||||
"userID": newUserID
|
||||
});
|
||||
}
|
||||
});
|
||||
//generate a userID
|
||||
const newUserID = generateUserID();
|
||||
//save this UUID
|
||||
SB.config.userID = newUserID;
|
||||
}
|
||||
}, 1500);
|
||||
});
|
||||
|
||||
//gets the sponsor times from memory
|
||||
function getSponsorTimes(videoID, callback) {
|
||||
let sponsorTimes = [];
|
||||
let sponsorTimeKey = "sponsorTimes" + videoID;
|
||||
chrome.storage.sync.get([sponsorTimeKey], function(result) {
|
||||
let sponsorTimesStorage = result[sponsorTimeKey];
|
||||
if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) {
|
||||
sponsorTimes = sponsorTimesStorage;
|
||||
}
|
||||
|
||||
callback(sponsorTimes)
|
||||
});
|
||||
let sponsorTimesStorage = SB.config.sponsorTimes.get(videoID);
|
||||
|
||||
if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) {
|
||||
sponsorTimes = sponsorTimesStorage;
|
||||
}
|
||||
|
||||
callback(sponsorTimes);
|
||||
}
|
||||
|
||||
function addSponsorTime(time, videoID, callback) {
|
||||
|
@ -109,21 +105,18 @@ function addSponsorTime(time, videoID, callback) {
|
|||
}
|
||||
|
||||
//save this info
|
||||
let sponsorTimeKey = "sponsorTimes" + videoID;
|
||||
chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}, callback);
|
||||
SB.config.sponsorTimes.set(videoID, sponsorTimes);
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
function submitVote(type, UUID, callback) {
|
||||
chrome.storage.sync.get(["userID"], function(result) {
|
||||
let userID = result.userID;
|
||||
let userID = SB.config.userID;
|
||||
|
||||
if (userID == undefined || userID === "undefined") {
|
||||
//generate one
|
||||
userID = generateUserID();
|
||||
chrome.storage.sync.set({
|
||||
"userID": userID
|
||||
});
|
||||
SB.config.userID = userID;
|
||||
}
|
||||
|
||||
//publish this vote
|
||||
|
@ -146,74 +139,62 @@ function submitVote(type, UUID, callback) {
|
|||
});
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function submitTimes(videoID, callback) {
|
||||
async function submitTimes(videoID, callback) {
|
||||
//get the video times from storage
|
||||
let sponsorTimeKey = 'sponsorTimes' + videoID;
|
||||
chrome.storage.sync.get([sponsorTimeKey, "userID"], async function(result) {
|
||||
let sponsorTimes = result[sponsorTimeKey];
|
||||
let userID = result.userID;
|
||||
|
||||
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
|
||||
let durationResult = await new Promise((resolve, reject) => {
|
||||
chrome.tabs.query({
|
||||
active: true,
|
||||
currentWindow: true
|
||||
}, function(tabs) {
|
||||
chrome.tabs.sendMessage(tabs[0].id, {
|
||||
message: "getVideoDuration"
|
||||
}, (response) => resolve(response));
|
||||
});
|
||||
let sponsorTimes = SB.config.sponsorTimes.get(videoID);
|
||||
let userID = SB.config.userID;
|
||||
|
||||
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
|
||||
let durationResult = await new Promise((resolve, reject) => {
|
||||
chrome.tabs.query({
|
||||
active: true,
|
||||
currentWindow: true
|
||||
}, function(tabs) {
|
||||
chrome.tabs.sendMessage(tabs[0].id, {
|
||||
message: "getVideoDuration"
|
||||
}, (response) => resolve(response));
|
||||
});
|
||||
});
|
||||
|
||||
//check if a sponsor exceeds the duration of the video
|
||||
for (let i = 0; i < sponsorTimes.length; i++) {
|
||||
if (sponsorTimes[i][1] > durationResult.duration) {
|
||||
sponsorTimes[i][1] = durationResult.duration;
|
||||
}
|
||||
}
|
||||
|
||||
//submit these times
|
||||
for (let i = 0; i < sponsorTimes.length; i++) {
|
||||
//to prevent it from happeneing twice
|
||||
let increasedContributionAmount = false;
|
||||
|
||||
//submit the sponsorTime
|
||||
sendRequestToServer("GET", "/api/postVideoSponsorTimes?videoID=" + videoID + "&startTime=" + sponsorTimes[i][0] + "&endTime=" + sponsorTimes[i][1]
|
||||
+ "&userID=" + userID, function(xmlhttp, error) {
|
||||
if (xmlhttp.readyState == 4 && !error) {
|
||||
callback({
|
||||
statusCode: xmlhttp.status
|
||||
});
|
||||
|
||||
if (xmlhttp.status == 200) {
|
||||
//add these to the storage log
|
||||
chrome.storage.sync.get(["sponsorTimesContributed"], function(result) {
|
||||
let currentContributionAmount = 0;
|
||||
if (result.sponsorTimesContributed != undefined) {
|
||||
//current contribution amount is known
|
||||
currentContributionAmount = result.sponsorTimesContributed;
|
||||
}
|
||||
|
||||
//save the amount contributed
|
||||
if (!increasedContributionAmount) {
|
||||
increasedContributionAmount = true;
|
||||
|
||||
chrome.storage.sync.set({"sponsorTimesContributed": currentContributionAmount + sponsorTimes.length});
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (error) {
|
||||
callback({
|
||||
statusCode: -1
|
||||
});
|
||||
}
|
||||
});
|
||||
//check if a sponsor exceeds the duration of the video
|
||||
for (let i = 0; i < sponsorTimes.length; i++) {
|
||||
if (sponsorTimes[i][1] > durationResult.duration) {
|
||||
sponsorTimes[i][1] = durationResult.duration;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//submit these times
|
||||
for (let i = 0; i < sponsorTimes.length; i++) {
|
||||
//to prevent it from happeneing twice
|
||||
let increasedContributionAmount = false;
|
||||
|
||||
//submit the sponsorTime
|
||||
sendRequestToServer("GET", "/api/postVideoSponsorTimes?videoID=" + videoID + "&startTime=" + sponsorTimes[i][0] + "&endTime=" + sponsorTimes[i][1]
|
||||
+ "&userID=" + userID, function(xmlhttp, error) {
|
||||
if (xmlhttp.readyState == 4 && !error) {
|
||||
callback({
|
||||
statusCode: xmlhttp.status
|
||||
});
|
||||
|
||||
if (xmlhttp.status == 200) {
|
||||
//add these to the storage log
|
||||
currentContributionAmount = SB.config.sponsorTimesContributed;
|
||||
//save the amount contributed
|
||||
if (!increasedContributionAmount) {
|
||||
increasedContributionAmount = true;
|
||||
SB.config.sponsorTimesContributed = currentContributionAmount + sponsorTimes.length;
|
||||
}
|
||||
}
|
||||
} else if (error) {
|
||||
callback({
|
||||
statusCode: -1
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function sendRequestToServer(type, address, callback) {
|
||||
|
@ -233,4 +214,4 @@ function sendRequestToServer(type, address, callback) {
|
|||
|
||||
//submit this request
|
||||
xmlhttp.send();
|
||||
}
|
||||
}
|
||||
|
|
271
content.js
271
content.js
|
@ -71,54 +71,6 @@ var sponsorTimesSubmitting = [];
|
|||
//this is used to close the popup on YouTube when the other popup opens
|
||||
var popupInitialised = false;
|
||||
|
||||
//should skips happen at all
|
||||
var disableSkipping = false;
|
||||
chrome.storage.sync.get(["disableSkipping"], function(result) {
|
||||
let disableSkippingStorage = result.disableSkipping;
|
||||
if (disableSkippingStorage != undefined) {
|
||||
disableSkipping = disableSkippingStorage;
|
||||
}
|
||||
});
|
||||
|
||||
//should skips be manual
|
||||
var disableAutoSkip = false;
|
||||
chrome.storage.sync.get(["disableAutoSkip"], function(result) {
|
||||
let disableAutoSkipStorage = result.disableAutoSkip;
|
||||
if (disableAutoSkipStorage != undefined) {
|
||||
disableAutoSkip = disableAutoSkipStorage;
|
||||
}
|
||||
});
|
||||
|
||||
//should view counts be tracked
|
||||
var trackViewCount = false;
|
||||
chrome.storage.sync.get(["trackViewCount"], function(result) {
|
||||
let trackViewCountStorage = result.trackViewCount;
|
||||
if (trackViewCountStorage != undefined) {
|
||||
trackViewCount = trackViewCountStorage;
|
||||
} else {
|
||||
trackViewCount = true;
|
||||
}
|
||||
});
|
||||
|
||||
//if the notice should not be shown
|
||||
//happens when the user click's the "Don't show notice again" button
|
||||
//option renamed when new notice was made
|
||||
var dontShowNotice = false;
|
||||
chrome.storage.sync.get(["dontShowNotice"], function(result) {
|
||||
let dontShowNoticeAgain = result.dontShowNotice;
|
||||
if (dontShowNoticeAgain != undefined) {
|
||||
dontShowNotice = dontShowNoticeAgain;
|
||||
}
|
||||
});
|
||||
//load the legacy option to hide the notice
|
||||
var dontShowNoticeOld = false;
|
||||
chrome.storage.sync.get(["dontShowNoticeAgain"], function(result) {
|
||||
let dontShowNoticeAgain = result.dontShowNoticeAgain;
|
||||
if (dontShowNoticeAgain != undefined) {
|
||||
dontShowNoticeOld = dontShowNoticeAgain;
|
||||
}
|
||||
});
|
||||
|
||||
//get messages from the background script and the popup
|
||||
chrome.runtime.onMessage.addListener(messageListener);
|
||||
|
||||
|
@ -127,7 +79,6 @@ function messageListener(request, sender, sendResponse) {
|
|||
switch(request.message){
|
||||
case "update":
|
||||
videoIDChange(getYouTubeVideoID(document.URL));
|
||||
|
||||
break;
|
||||
case "sponsorStart":
|
||||
sponsorMessageStarted(sendResponse);
|
||||
|
@ -192,35 +143,35 @@ function messageListener(request, sender, sendResponse) {
|
|||
|
||||
break;
|
||||
case "dontShowNotice":
|
||||
dontShowNotice = false;
|
||||
SB.config.dontShowNotice = true;
|
||||
|
||||
break;
|
||||
case "changeStartSponsorButton":
|
||||
changeStartSponsorButton(request.showStartSponsor, request.uploadButtonVisible);
|
||||
|
||||
break;
|
||||
|
||||
case "showNoticeAgain":
|
||||
dontShowNotice = false;
|
||||
|
||||
SB.config.dontShowNotice = true;
|
||||
break;
|
||||
|
||||
case "changeVideoPlayerControlsVisibility":
|
||||
hideVideoPlayerControls = request.value;
|
||||
SB.config.hideVideoPlayerControls = request.value;
|
||||
updateVisibilityOfPlayerControlsButton();
|
||||
|
||||
break;
|
||||
case "changeInfoButtonPlayerControlsVisibility":
|
||||
hideInfoButtonPlayerControls = request.value;
|
||||
SB.config.hideInfoButtonPlayerControls = request.value;
|
||||
updateVisibilityOfPlayerControlsButton();
|
||||
|
||||
break;
|
||||
case "changeDeleteButtonPlayerControlsVisibility":
|
||||
hideDeleteButtonPlayerControls = request.value;
|
||||
SB.config.hideDeleteButtonPlayerControls = request.value;
|
||||
updateVisibilityOfPlayerControlsButton();
|
||||
|
||||
break;
|
||||
case "trackViewCount":
|
||||
trackViewCount = request.value;
|
||||
|
||||
SB.config.trackViewCount = request.value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -232,19 +183,9 @@ document.onkeydown = async function(e){
|
|||
|
||||
let video = document.getElementById("movie_player");
|
||||
|
||||
let startSponsorKey = await new Promise((resolve, reject) => {
|
||||
chrome.storage.sync.get(["startSponsorKeybind"], (result) => resolve(result));
|
||||
});
|
||||
let submitKey = await new Promise((resolve, reject) => {
|
||||
chrome.storage.sync.get(["submitKeybind"], (result) => resolve(result));
|
||||
});
|
||||
let startSponsorKey = SB.config.startSponsorKeybind;
|
||||
|
||||
if (startSponsorKey.startSponsorKeybind === undefined) {
|
||||
startSponsorKey.startSponsorKeybind = ";"
|
||||
}
|
||||
if (submitKey.submitKeybind === undefined) {
|
||||
submitKey.submitKeybind = "'"
|
||||
}
|
||||
let submitKey = SB.config.submitKeybind;
|
||||
|
||||
//is the video in focus, otherwise they could be typing a comment
|
||||
if (document.activeElement === video) {
|
||||
|
@ -317,21 +258,17 @@ function videoIDChange(id) {
|
|||
//warn them if they had unsubmitted times
|
||||
if (previousVideoID != null) {
|
||||
//get the sponsor times from storage
|
||||
let sponsorTimeKey = 'sponsorTimes' + previousVideoID;
|
||||
chrome.storage.sync.get([sponsorTimeKey], function(result) {
|
||||
let sponsorTimes = result[sponsorTimeKey];
|
||||
let sponsorTimes = SB.config.sponsorTimes.get(previousVideoID);
|
||||
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
|
||||
//warn them that they have unsubmitted sponsor times
|
||||
chrome.runtime.sendMessage({
|
||||
message: "alertPrevious",
|
||||
previousVideoID: previousVideoID
|
||||
})
|
||||
}
|
||||
|
||||
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
|
||||
//warn them that they have unsubmitted sponsor times
|
||||
chrome.runtime.sendMessage({
|
||||
message: "alertPrevious",
|
||||
previousVideoID: previousVideoID
|
||||
})
|
||||
}
|
||||
|
||||
//set the previous video id to the currentID
|
||||
previousVideoID = id;
|
||||
});
|
||||
//set the previous video id to the currentID
|
||||
previousVideoID = id;
|
||||
} else {
|
||||
//set the previous id now, don't wait for chrome.storage.get
|
||||
previousVideoID = id;
|
||||
|
@ -373,30 +310,9 @@ function videoIDChange(id) {
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
//see if video controls buttons should be added
|
||||
if (!onInvidious) {
|
||||
chrome.storage.sync.get(["hideVideoPlayerControls"], function(result) {
|
||||
if (result.hideVideoPlayerControls != undefined) {
|
||||
hideVideoPlayerControls = result.hideVideoPlayerControls;
|
||||
}
|
||||
|
||||
updateVisibilityOfPlayerControlsButton();
|
||||
});
|
||||
chrome.storage.sync.get(["hideInfoButtonPlayerControls"], function(result) {
|
||||
if (result.hideInfoButtonPlayerControls != undefined) {
|
||||
hideInfoButtonPlayerControls = result.hideInfoButtonPlayerControls;
|
||||
}
|
||||
|
||||
updateVisibilityOfPlayerControlsButton();
|
||||
});
|
||||
chrome.storage.sync.get(["hideDeleteButtonPlayerControls"], function(result) {
|
||||
if (result.hideDeleteButtonPlayerControls != undefined) {
|
||||
hideDeleteButtonPlayerControls = result.hideDeleteButtonPlayerControls;
|
||||
}
|
||||
|
||||
updateVisibilityOfPlayerControlsButton(false);
|
||||
});
|
||||
updateVisibilityOfPlayerControlsButton();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -479,7 +395,7 @@ function sponsorsLookup(id, channelIDPromise) {
|
|||
});
|
||||
|
||||
//add the event to run on the videos "ontimeupdate"
|
||||
if (!disableSkipping) {
|
||||
if (!SB.config.disableSkipping) {
|
||||
v.ontimeupdate = function () {
|
||||
sponsorCheck();
|
||||
};
|
||||
|
@ -564,20 +480,18 @@ function getChannelID() {
|
|||
//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
|
||||
chrome.storage.sync.get(["whitelistedChannels"], function(result) {
|
||||
let whitelistedChannels = result.whitelistedChannels;
|
||||
let whitelistedChannels = SB.config.whitelistedChannels;
|
||||
|
||||
console.log(channelURL)
|
||||
|
||||
if (whitelistedChannels != undefined && whitelistedChannels.includes(channelURL)) {
|
||||
channelWhitelisted = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//video skipping
|
||||
function sponsorCheck() {
|
||||
if (disableSkipping) {
|
||||
if (SB.config.disableSkipping) {
|
||||
// Make sure this isn't called again
|
||||
v.ontimeupdate = null;
|
||||
return;
|
||||
|
@ -643,7 +557,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 (!disableAutoSkip) {
|
||||
if (!SB.config.disableAutoSkip) {
|
||||
v.currentTime = sponsorTimes[index][1];
|
||||
}
|
||||
|
||||
|
@ -654,42 +568,23 @@ function skipToTime(v, index, sponsorTimes, openNotice) {
|
|||
|
||||
if (openNotice) {
|
||||
//send out the message saying that a sponsor message was skipped
|
||||
if (!dontShowNotice) {
|
||||
let skipNotice = new SkipNotice(this, currentUUID, disableAutoSkip);
|
||||
|
||||
if (dontShowNoticeOld) {
|
||||
//show why this notice is showing
|
||||
skipNotice.addNoticeInfoMessage(chrome.i18n.getMessage("noticeUpdate"), chrome.i18n.getMessage("noticeUpdate2"));
|
||||
|
||||
//remove this setting
|
||||
chrome.storage.sync.remove(["dontShowNoticeAgain"]);
|
||||
dontShowNoticeOld = false;
|
||||
}
|
||||
|
||||
if (!SB.config.dontShowNotice) {
|
||||
let skipNotice = new SkipNotice(this, currentUUID, SB.config.disableAutoSkip);
|
||||
//auto-upvote this sponsor
|
||||
if (trackViewCount && !disableAutoSkip) {
|
||||
if (SB.config.trackViewCount && !SB.config.disableAutoSkip) {
|
||||
vote(1, currentUUID, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//send telemetry that a this sponsor was skipped
|
||||
if (trackViewCount && !sponsorSkipped[index]) {
|
||||
if (SB.config.trackViewCount && !sponsorSkipped[index]) {
|
||||
sendRequestToServer("POST", "/api/viewedVideoSponsorTime?UUID=" + currentUUID);
|
||||
|
||||
if (!disableAutoSkip) {
|
||||
if (!SB.config.disableAutoSkip) {
|
||||
// Count this as a skip
|
||||
chrome.storage.sync.get(["minutesSaved"], function(result) {
|
||||
if (result.minutesSaved === undefined) result.minutesSaved = 0;
|
||||
|
||||
chrome.storage.sync.set({"minutesSaved": result.minutesSaved + (sponsorTimes[index][1] - sponsorTimes[index][0]) / 60 });
|
||||
});
|
||||
chrome.storage.sync.get(["skipCount"], function(result) {
|
||||
if (result.skipCount === undefined) result.skipCount = 0;
|
||||
|
||||
chrome.storage.sync.set({"skipCount": result.skipCount + 1 });
|
||||
});
|
||||
|
||||
SB.config.minutesSaved = SB.config.minutesSaved + (sponsorTimes[index][1] - sponsorTimes[index][0]) / 60;
|
||||
SB.config.skipCount = SB.config.skipCount + 1;
|
||||
sponsorSkipped[index] = true;
|
||||
}
|
||||
}
|
||||
|
@ -773,14 +668,14 @@ async function updateVisibilityOfPlayerControlsButton() {
|
|||
|
||||
await createButtons();
|
||||
|
||||
if (hideVideoPlayerControls) {
|
||||
if (SB.config.hideDeleteButtonPlayerControls) {
|
||||
removePlayerControlsButton();
|
||||
}
|
||||
//don't show the info button on embeds
|
||||
if (hideInfoButtonPlayerControls || document.URL.includes("/embed/")) {
|
||||
if (SB.config.hideInfoButtonPlayerControls || document.URL.includes("/embed/")) {
|
||||
document.getElementById("infoButton").style.display = "none";
|
||||
}
|
||||
if (hideDeleteButtonPlayerControls) {
|
||||
if (SB.config.hideDeleteButtonPlayerControls) {
|
||||
document.getElementById("deleteButton").style.display = "none";
|
||||
}
|
||||
}
|
||||
|
@ -832,7 +727,7 @@ async function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) {
|
|||
await wait(isSubmitButtonLoaded);
|
||||
|
||||
//if it isn't visible, there is no data
|
||||
let shouldHide = (uploadButtonVisible && !hideDeleteButtonPlayerControls) ? "unset" : "none"
|
||||
let shouldHide = (uploadButtonVisible && !SB.config.hideDeleteButtonPlayerControls) ? "unset" : "none"
|
||||
document.getElementById("deleteButton").style.display = shouldHide;
|
||||
|
||||
if (showStartSponsor) {
|
||||
|
@ -840,7 +735,7 @@ async function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) {
|
|||
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 && !hideVideoPlayerControls) {
|
||||
if (document.getElementById("startSponsorImage").style.display != "none" && uploadButtonVisible && !SB.config.hideInfoButtonPlayerControls) {
|
||||
document.getElementById("submitButton").style.display = "unset";
|
||||
} else if (!uploadButtonVisible) {
|
||||
//disable submit button
|
||||
|
@ -935,28 +830,24 @@ function clearSponsorTimes() {
|
|||
|
||||
let currentVideoID = sponsorVideoID;
|
||||
|
||||
let sponsorTimeKey = 'sponsorTimes' + currentVideoID;
|
||||
chrome.storage.sync.get([sponsorTimeKey], function(result) {
|
||||
let sponsorTimes = result[sponsorTimeKey];
|
||||
let sponsorTimes = SB.config.sponsorTimes.get(currentVideoID);
|
||||
|
||||
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
|
||||
let confirmMessage = chrome.i18n.getMessage("clearThis") + getSponsorTimesMessage(sponsorTimes);
|
||||
confirmMessage += chrome.i18n.getMessage("confirmMSG")
|
||||
if(!confirm(confirmMessage)) return;
|
||||
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
|
||||
let confirmMessage = chrome.i18n.getMessage("clearThis") + getSponsorTimesMessage(sponsorTimes);
|
||||
confirmMessage += chrome.i18n.getMessage("confirmMSG")
|
||||
if(!confirm(confirmMessage)) return;
|
||||
|
||||
//clear the sponsor times
|
||||
let sponsorTimeKey = "sponsorTimes" + currentVideoID;
|
||||
chrome.storage.sync.set({[sponsorTimeKey]: []});
|
||||
//clear the sponsor times
|
||||
SB.config.sponsorTimes.delete(currentVideoID);
|
||||
|
||||
//clear sponsor times submitting
|
||||
sponsorTimesSubmitting = [];
|
||||
//clear sponsor times submitting
|
||||
sponsorTimesSubmitting = [];
|
||||
|
||||
updatePreviewBar();
|
||||
updatePreviewBar();
|
||||
|
||||
//set buttons to be correct
|
||||
changeStartSponsorButton(true, false);
|
||||
}
|
||||
});
|
||||
//set buttons to be correct
|
||||
changeStartSponsorButton(true, false);
|
||||
}
|
||||
}
|
||||
|
||||
//if skipNotice is null, it will not affect the UI
|
||||
|
@ -978,17 +869,12 @@ function vote(type, UUID, skipNotice) {
|
|||
sponsorSkipped[sponsorIndex] = false;
|
||||
}
|
||||
|
||||
// Count this as a skip
|
||||
chrome.storage.sync.get(["minutesSaved"], function(result) {
|
||||
if (result.minutesSaved === undefined) result.minutesSaved = 0;
|
||||
// Count this as a skip
|
||||
SB.config.minutesSaved = SB.config.minutesSaved + factor * (sponsorTimes[sponsorIndex][1] - sponsorTimes[sponsorIndex][0]) / 60;
|
||||
|
||||
SB.config.skipCount = 0;
|
||||
|
||||
chrome.storage.sync.set({"minutesSaved": result.minutesSaved + factor * (sponsorTimes[sponsorIndex][1] - sponsorTimes[sponsorIndex][0]) / 60 });
|
||||
});
|
||||
chrome.storage.sync.get(["skipCount"], function(result) {
|
||||
if (result.skipCount === undefined) result.skipCount = 0;
|
||||
|
||||
chrome.storage.sync.set({"skipCount": result.skipCount + factor * 1 });
|
||||
});
|
||||
SB.config.skipCount = SB.config.skipCount + factor * 1;
|
||||
}
|
||||
|
||||
chrome.runtime.sendMessage({
|
||||
|
@ -1026,10 +912,7 @@ function closeAllSkipNotices(){
|
|||
}
|
||||
|
||||
function dontShowNoticeAgain() {
|
||||
chrome.storage.sync.set({"dontShowNotice": true});
|
||||
|
||||
dontShowNotice = true;
|
||||
|
||||
SB.config.dontShowNotice = true;
|
||||
closeAllSkipNotices();
|
||||
}
|
||||
|
||||
|
@ -1056,30 +939,27 @@ function submitSponsorTimes() {
|
|||
|
||||
let currentVideoID = sponsorVideoID;
|
||||
|
||||
let sponsorTimeKey = 'sponsorTimes' + currentVideoID;
|
||||
chrome.storage.sync.get([sponsorTimeKey], function(result) {
|
||||
let sponsorTimes = result[sponsorTimeKey];
|
||||
let sponsorTimes = SB.config.sponsorTimes.get(currentVideoID);
|
||||
|
||||
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
|
||||
//check if a sponsor exceeds the duration of the video
|
||||
for (let i = 0; i < sponsorTimes.length; i++) {
|
||||
if (sponsorTimes[i][1] > v.duration) {
|
||||
sponsorTimes[i][1] = v.duration;
|
||||
}
|
||||
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
|
||||
//check if a sponsor exceeds the duration of the video
|
||||
for (let i = 0; i < sponsorTimes.length; i++) {
|
||||
if (sponsorTimes[i][1] > v.duration) {
|
||||
sponsorTimes[i][1] = v.duration;
|
||||
}
|
||||
//update sponsorTimes
|
||||
chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes});
|
||||
|
||||
//update sponsorTimesSubmitting
|
||||
sponsorTimesSubmitting = sponsorTimes;
|
||||
|
||||
let confirmMessage = chrome.i18n.getMessage("submitCheck") + "\n\n" + getSponsorTimesMessage(sponsorTimes)
|
||||
+ "\n\n" + chrome.i18n.getMessage("confirmMSG") + "\n\n" + chrome.i18n.getMessage("guildlinesSummary");
|
||||
if(!confirm(confirmMessage)) return;
|
||||
|
||||
sendSubmitMessage();
|
||||
}
|
||||
});
|
||||
//update sponsorTimes
|
||||
SB.config.sponsorTimes.set(currentVideoID, sponsorTimes);
|
||||
|
||||
//update sponsorTimesSubmitting
|
||||
sponsorTimesSubmitting = sponsorTimes;
|
||||
|
||||
let confirmMessage = chrome.i18n.getMessage("submitCheck") + "\n\n" + getSponsorTimesMessage(sponsorTimes)
|
||||
+ "\n\n" + chrome.i18n.getMessage("confirmMSG") + "\n\n" + chrome.i18n.getMessage("guildlinesSummary");
|
||||
if(!confirm(confirmMessage)) return;
|
||||
|
||||
sendSubmitMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1114,8 +994,7 @@ function sendSubmitMessage(){
|
|||
submitButton.addEventListener("animationend", animationEndListener);
|
||||
|
||||
//clear the sponsor times
|
||||
let sponsorTimeKey = "sponsorTimes" + currentVideoID;
|
||||
chrome.storage.sync.set({[sponsorTimeKey]: []});
|
||||
SB.config.sponsorTimes.delete(currentVideoID);
|
||||
|
||||
//add submissions to current sponsors list
|
||||
sponsorTimes = sponsorTimes.concat(sponsorTimesSubmitting);
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
{
|
||||
"browser_specific_settings": {
|
||||
"gecko": {
|
||||
"id": "sponsorBlocker@ajay.app",
|
||||
"strict_min_version": "57.0"
|
||||
"id": "sponsorBlocker@ajay.app"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
"description": "__MSG_Description__",
|
||||
"content_scripts": [
|
||||
{
|
||||
"run_at": "document_start",
|
||||
"matches": [
|
||||
"https://*.youtube.com/*",
|
||||
"https://www.youtube-nocookie.com/embed/*"
|
||||
|
@ -13,6 +14,7 @@
|
|||
"all_frames": true,
|
||||
"js": [
|
||||
"config.js",
|
||||
"SB.js",
|
||||
"utils/previewBar.js",
|
||||
"utils/skipNotice.js",
|
||||
"utils.js",
|
||||
|
@ -56,6 +58,7 @@
|
|||
},
|
||||
"background": {
|
||||
"scripts":[
|
||||
"SB.js",
|
||||
"utils.js",
|
||||
"config.js",
|
||||
"background.js"
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
<link href="options.css" rel="stylesheet"/>
|
||||
|
||||
<script src="../utils.js"></script>
|
||||
<script src="../SB.js"></script>
|
||||
<script src="options.js"></script>
|
||||
</head>
|
||||
|
||||
|
|
|
@ -9,54 +9,47 @@ for (const url of supportedInvidiousInstances) {
|
|||
async function init() {
|
||||
localizeHtmlPage();
|
||||
|
||||
await wait(() => SB.config !== undefined);
|
||||
|
||||
// Set all of the toggle options to the correct option
|
||||
let optionsContainer = document.getElementById("options");
|
||||
let optionsElements = optionsContainer.children;
|
||||
|
||||
// How many checks are left to be done
|
||||
let checksLeft = 0;
|
||||
|
||||
for (let i = 0; i < optionsElements.length; i++) {
|
||||
switch (optionsElements[i].getAttribute("option-type")) {
|
||||
case "toggle":
|
||||
let option = optionsElements[i].getAttribute("sync-option");
|
||||
let optionResult = SB.config[option];
|
||||
|
||||
chrome.storage.sync.get([option], function(result) {
|
||||
let optionResult = result[option];
|
||||
let checkbox = optionsElements[i].querySelector("input");
|
||||
let reverse = optionsElements[i].getAttribute("toggle-type") === "reverse";
|
||||
let checkbox = optionsElements[i].querySelector("input");
|
||||
let reverse = optionsElements[i].getAttribute("toggle-type") === "reverse";
|
||||
|
||||
if (optionResult != undefined) {
|
||||
checkbox.checked = optionResult;
|
||||
if (optionResult != undefined) {
|
||||
checkbox.checked = optionResult;
|
||||
|
||||
if (reverse) {
|
||||
optionsElements[i].querySelector("input").checked = !optionResult;
|
||||
}
|
||||
if (reverse) {
|
||||
optionsElements[i].querySelector("input").checked = !optionResult;
|
||||
}
|
||||
}
|
||||
|
||||
// See if anything extra should be run first time
|
||||
// See if anything extra should be run first time
|
||||
switch (option) {
|
||||
case "supportInvidious":
|
||||
invidiousInit(checkbox, option);
|
||||
break;
|
||||
}
|
||||
|
||||
// Add click listener
|
||||
checkbox.addEventListener("click", () => {
|
||||
setOptionValue(option, reverse ? !checkbox.checked : checkbox.checked);
|
||||
|
||||
// See if anything extra must be run
|
||||
switch (option) {
|
||||
case "supportInvidious":
|
||||
invidiousInit(checkbox, option);
|
||||
invidiousOnClick(checkbox, option);
|
||||
break;
|
||||
}
|
||||
|
||||
// Add click listener
|
||||
checkbox.addEventListener("click", () =>{
|
||||
setOptionValue(option, reverse ? !checkbox.checked : checkbox.checked);
|
||||
|
||||
// See if anything extra must be run
|
||||
switch (option) {
|
||||
case "supportInvidious":
|
||||
invidiousOnClick(checkbox, option);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
checksLeft--;
|
||||
});
|
||||
|
||||
checksLeft++;
|
||||
break;
|
||||
case "text-change":
|
||||
let button = optionsElements[i].querySelector(".trigger-button");
|
||||
|
@ -71,11 +64,6 @@ async function init() {
|
|||
}
|
||||
}
|
||||
|
||||
// Don't wait on chrome
|
||||
if (isFirefox()) {
|
||||
await wait(() => checksLeft == 0, 1000, 50);
|
||||
}
|
||||
|
||||
optionsContainer.classList.remove("hidden");
|
||||
optionsContainer.classList.add("animated");
|
||||
}
|
||||
|
@ -209,21 +197,19 @@ function activateKeybindChange(element) {
|
|||
|
||||
let option = element.getAttribute("sync-option");
|
||||
|
||||
chrome.storage.sync.get([option], function(result) {
|
||||
let currentlySet = result[option] !== null ? chrome.i18n.getMessage("keybindCurrentlySet") : "";
|
||||
|
||||
let status = element.querySelector(".option-hidden-section > .keybind-status");
|
||||
status.innerText = chrome.i18n.getMessage("keybindDescription") + currentlySet;
|
||||
|
||||
if (result[option] !== null) {
|
||||
let statusKey = element.querySelector(".option-hidden-section > .keybind-status-key");
|
||||
statusKey.innerText = result[option];
|
||||
}
|
||||
let currentlySet = SB.config[option] !== null ? chrome.i18n.getMessage("keybindCurrentlySet") : "";
|
||||
|
||||
element.querySelector(".option-hidden-section").classList.remove("hidden");
|
||||
|
||||
document.addEventListener("keydown", (e) => keybindKeyPressed(element, e), {once: true});
|
||||
});
|
||||
let status = element.querySelector(".option-hidden-section > .keybind-status");
|
||||
status.innerText = chrome.i18n.getMessage("keybindDescription") + currentlySet;
|
||||
|
||||
if (SB.config[option] !== null) {
|
||||
let statusKey = element.querySelector(".option-hidden-section > .keybind-status-key");
|
||||
statusKey.innerText = SB.config[option];
|
||||
}
|
||||
|
||||
element.querySelector(".option-hidden-section").classList.remove("hidden");
|
||||
|
||||
document.addEventListener("keydown", (e) => keybindKeyPressed(element, e), {once: true});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -238,7 +224,7 @@ function keybindKeyPressed(element, e) {
|
|||
|
||||
let option = element.getAttribute("sync-option");
|
||||
|
||||
chrome.storage.sync.set({[option]: key});
|
||||
SB.config[option] = key;
|
||||
|
||||
let status = element.querySelector(".option-hidden-section > .keybind-status");
|
||||
status.innerText = chrome.i18n.getMessage("keybindDescriptionComplete");
|
||||
|
@ -264,7 +250,10 @@ function activateTextChange(element) {
|
|||
|
||||
let textBox = element.querySelector(".option-text-box");
|
||||
let option = element.getAttribute("sync-option");
|
||||
|
||||
textBox.value = SB.config[option];
|
||||
|
||||
<<<<<<< HEAD
|
||||
// See if anything extra must be done
|
||||
switch (option) {
|
||||
case "invidiousInstances":
|
||||
|
@ -332,4 +321,11 @@ function activateTextChange(element) {
|
|||
*/
|
||||
function setOptionValue(option, value, callback) {
|
||||
chrome.storage.sync.set({[option]: value}, callback);
|
||||
}
|
||||
}
|
||||
=======
|
||||
let setButton = element.querySelector(".text-change-set");
|
||||
setButton.addEventListener("click", () => {SB.config[option] = textBox.value});
|
||||
|
||||
element.querySelector(".option-hidden-section").classList.remove("hidden");
|
||||
}
|
||||
>>>>>>> c53bc202941f8dbf2f5481a891ca28a69825304b
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"dev": "web-ext run",
|
||||
"build": "web-ext build --overwrite-dest -i \"*(package-lock.json|README.md|package.json|config.js.example|firefox_manifest-extra.json|manifest.json.original|ignored/*|crowdin.yml)\""
|
||||
"build": "web-ext build --overwrite-dest -i \"*(package-lock.json|README.md|package.json|config.js.example|firefox_manifest-extra.json|manifest.json.original|ignored|crowdin.yml)\""
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>__MSG_openPopup__</title>
|
||||
<script src="SB.js"></script>
|
||||
<link id="sponorBlockPopupFont" rel="stylesheet" type="text/css" href="/libs/Source+Sans+Pro.css"/>
|
||||
<link id="sponorBlockStyleSheet" rel="stylesheet" type="text/css" href="popup.css"/>
|
||||
</head>
|
||||
|
|
315
popup.js
315
popup.js
|
@ -1,29 +1,27 @@
|
|||
|
||||
//make this a function to allow this to run on the content page
|
||||
function runThePopup() {
|
||||
async function runThePopup() {
|
||||
localizeHtmlPage();
|
||||
|
||||
//is it in the popup or content script
|
||||
var inPopup = true;
|
||||
if (chrome.tabs == undefined) {
|
||||
//this is on the content script, use direct communication
|
||||
chrome.tabs = {};
|
||||
chrome.tabs.sendMessage = function(id, request, callback) {
|
||||
messageListener(request, null, callback);
|
||||
}
|
||||
|
||||
//add a dummy query method
|
||||
chrome.tabs.query = function(config, callback) {
|
||||
callback([{
|
||||
url: document.URL,
|
||||
id: -1
|
||||
}]);
|
||||
}
|
||||
|
||||
inPopup = false;
|
||||
//this is on the content script, use direct communication
|
||||
chrome.tabs = {};
|
||||
chrome.tabs.sendMessage = function(id, request, callback) {
|
||||
messageListener(request, null, callback);
|
||||
}
|
||||
|
||||
//add a dummy query method
|
||||
chrome.tabs.query = function(config, callback) {
|
||||
callback([{
|
||||
url: document.URL,
|
||||
id: -1
|
||||
}]);
|
||||
}
|
||||
|
||||
inPopup = false;
|
||||
}
|
||||
|
||||
var SB = {};
|
||||
|
||||
await wait(() => SB.config !== undefined);
|
||||
|
||||
["sponsorStart",
|
||||
// Top toggles
|
||||
|
@ -95,7 +93,7 @@ function runThePopup() {
|
|||
SB.optionsButton.addEventListener("click", openOptions);
|
||||
SB.reportAnIssue.addEventListener("click", reportAnIssue);
|
||||
SB.hideDiscordButton.addEventListener("click", hideDiscordButton);
|
||||
|
||||
|
||||
//if true, the button now selects the end time
|
||||
let startTimeChosen = false;
|
||||
|
||||
|
@ -106,130 +104,113 @@ function runThePopup() {
|
|||
let currentVideoID = null;
|
||||
|
||||
//see if discord link can be shown
|
||||
chrome.storage.sync.get(["hideDiscordLink"], function(result) {
|
||||
let hideDiscordLink = result.hideDiscordLink;
|
||||
if (hideDiscordLink == undefined || !hideDiscordLink) {
|
||||
chrome.storage.sync.get(["hideDiscordLaunches"], function(result) {
|
||||
let hideDiscordLaunches = result.hideDiscordLaunches;
|
||||
//only if less than 10 launches
|
||||
if (hideDiscordLaunches == undefined || hideDiscordLaunches < 10) {
|
||||
SB.discordButtonContainer.style.display = null;
|
||||
|
||||
if (hideDiscordLaunches == undefined) {
|
||||
hideDiscordLaunches = 1;
|
||||
}
|
||||
|
||||
chrome.storage.sync.set({"hideDiscordLaunches": hideDiscordLaunches + 1});
|
||||
let hideDiscordLink = SB.config.hideDiscordLink;
|
||||
if (hideDiscordLink == undefined || !hideDiscordLink) {
|
||||
let hideDiscordLaunches = SB.config.hideDiscordLaunches;
|
||||
//only if less than 10 launches
|
||||
if (hideDiscordLaunches == undefined || hideDiscordLaunches < 10) {
|
||||
SB.discordButtonContainer.style.display = null;
|
||||
|
||||
if (hideDiscordLaunches == undefined) {
|
||||
hideDiscordLaunches = 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
SB.config.hideDiscordLaunches = hideDiscordLaunches + 1;
|
||||
}
|
||||
}
|
||||
|
||||
//show proper disable skipping button
|
||||
chrome.storage.sync.get(["disableSkipping"], function(result) {
|
||||
let disableSkipping = result.disableSkipping;
|
||||
if (disableSkipping != undefined && disableSkipping) {
|
||||
SB.disableSkipping.style.display = "none";
|
||||
SB.enableSkipping.style.display = "unset";
|
||||
}
|
||||
});
|
||||
let disableSkipping = SB.config.disableSkipping;
|
||||
if (disableSkipping != undefined && disableSkipping) {
|
||||
SB.disableSkipping.style.display = "none";
|
||||
SB.enableSkipping.style.display = "unset";
|
||||
}
|
||||
|
||||
//if the don't show notice again variable is true, an option to
|
||||
// disable should be available
|
||||
chrome.storage.sync.get(["dontShowNotice"], function(result) {
|
||||
let dontShowNotice = result.dontShowNotice;
|
||||
if (dontShowNotice != undefined && dontShowNotice) {
|
||||
SB.showNoticeAgain.style.display = "unset";
|
||||
}
|
||||
});
|
||||
let dontShowNotice = SB.config.dontShowNotice;
|
||||
if (dontShowNotice != undefined && dontShowNotice) {
|
||||
SB.showNoticeAgain.style.display = "unset";
|
||||
}
|
||||
|
||||
//get the amount of times this user has contributed and display it to thank them
|
||||
chrome.storage.sync.get(["sponsorTimesContributed"], function(result) {
|
||||
if (result.sponsorTimesContributed != undefined) {
|
||||
if (result.sponsorTimesContributed > 1) {
|
||||
SB.sponsorTimesContributionsDisplayEndWord.innerText = chrome.i18n.getMessage("Sponsors");
|
||||
} else {
|
||||
SB.sponsorTimesContributionsDisplayEndWord.innerText = chrome.i18n.getMessage("Sponsor");
|
||||
}
|
||||
SB.sponsorTimesContributionsDisplay.innerText = result.sponsorTimesContributed;
|
||||
SB.sponsorTimesContributionsContainer.style.display = "unset";
|
||||
|
||||
//get the userID
|
||||
chrome.storage.sync.get(["userID"], function(result) {
|
||||
let userID = result.userID;
|
||||
if (userID != undefined) {
|
||||
//there are probably some views on these submissions then
|
||||
//get the amount of views from the sponsors submitted
|
||||
sendRequestToServer("GET", "/api/getViewsForUser?userID=" + userID, function(xmlhttp) {
|
||||
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
||||
let viewCount = JSON.parse(xmlhttp.responseText).viewCount;
|
||||
if (viewCount != 0) {
|
||||
if (viewCount > 1) {
|
||||
SB.sponsorTimesViewsDisplayEndWord.innerText = chrome.i18n.getMessage("Segments");
|
||||
} else {
|
||||
SB.sponsorTimesViewsDisplayEndWord.innerText = chrome.i18n.getMessage("Segment");
|
||||
}
|
||||
|
||||
SB.sponsorTimesViewsDisplay.innerText = viewCount;
|
||||
SB.sponsorTimesViewsContainer.style.display = "unset";
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//get this time in minutes
|
||||
sendRequestToServer("GET", "/api/getSavedTimeForUser?userID=" + userID, function(xmlhttp) {
|
||||
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
||||
let minutesSaved = JSON.parse(xmlhttp.responseText).timeSaved;
|
||||
if (minutesSaved != 0) {
|
||||
if (minutesSaved != 1) {
|
||||
SB.sponsorTimesOthersTimeSavedEndWord.innerText = chrome.i18n.getMessage("minsLower");
|
||||
} else {
|
||||
SB.sponsorTimesOthersTimeSavedEndWord.innerText = chrome.i18n.getMessage("minLower");
|
||||
}
|
||||
|
||||
SB.sponsorTimesOthersTimeSavedDisplay.innerText = getFormattedHours(minutesSaved);
|
||||
SB.sponsorTimesOthersTimeSavedContainer.style.display = "unset";
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
if (SB.config.sponsorTimesContributed != undefined) {
|
||||
if (SB.config.sponsorTimesContributed > 1) {
|
||||
SB.sponsorTimesContributionsDisplayEndWord.innerText = chrome.i18n.getMessage("Sponsors");
|
||||
} else {
|
||||
SB.sponsorTimesContributionsDisplayEndWord.innerText = chrome.i18n.getMessage("Sponsor");
|
||||
}
|
||||
});
|
||||
SB.sponsorTimesContributionsDisplay.innerText = SB.config.sponsorTimesContributed;
|
||||
SB.sponsorTimesContributionsContainer.style.display = "unset";
|
||||
|
||||
//get the userID
|
||||
let userID = SB.config.userID;
|
||||
if (userID != undefined) {
|
||||
//there are probably some views on these submissions then
|
||||
//get the amount of views from the sponsors submitted
|
||||
sendRequestToServer("GET", "/api/getViewsForUser?userID=" + userID, function(xmlhttp) {
|
||||
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
||||
let viewCount = JSON.parse(xmlhttp.responseText).viewCount;
|
||||
if (viewCount != 0) {
|
||||
if (viewCount > 1) {
|
||||
SB.sponsorTimesViewsDisplayEndWord.innerText = chrome.i18n.getMessage("Segments");
|
||||
} else {
|
||||
SB.sponsorTimesViewsDisplayEndWord.innerText = chrome.i18n.getMessage("Segment");
|
||||
}
|
||||
|
||||
SB.sponsorTimesViewsDisplay.innerText = viewCount;
|
||||
SB.sponsorTimesViewsContainer.style.display = "unset";
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//get this time in minutes
|
||||
sendRequestToServer("GET", "/api/getSavedTimeForUser?userID=" + userID, function(xmlhttp) {
|
||||
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
||||
let minutesSaved = JSON.parse(xmlhttp.responseText).timeSaved;
|
||||
if (minutesSaved != 0) {
|
||||
if (minutesSaved != 1) {
|
||||
SB.sponsorTimesOthersTimeSavedEndWord.innerText = chrome.i18n.getMessage("minsLower");
|
||||
} else {
|
||||
SB.sponsorTimesOthersTimeSavedEndWord.innerText = chrome.i18n.getMessage("minLower");
|
||||
}
|
||||
|
||||
SB.sponsorTimesOthersTimeSavedDisplay.innerText = getFormattedHours(minutesSaved);
|
||||
SB.sponsorTimesOthersTimeSavedContainer.style.display = "unset";
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//get the amount of times this user has skipped a sponsor
|
||||
chrome.storage.sync.get(["skipCount"], function(result) {
|
||||
if (result.skipCount != undefined) {
|
||||
if (result.skipCount != 1) {
|
||||
SB.sponsorTimesSkipsDoneEndWord.innerText = chrome.i18n.getMessage("Sponsors");
|
||||
} else {
|
||||
SB.sponsorTimesSkipsDoneEndWord.innerText = chrome.i18n.getMessage("Sponsor");
|
||||
}
|
||||
|
||||
SB.sponsorTimesSkipsDoneDisplay.innerText = result.skipCount;
|
||||
SB.sponsorTimesSkipsDoneContainer.style.display = "unset";
|
||||
if (SB.config.skipCount != undefined) {
|
||||
if (SB.config.skipCount != 1) {
|
||||
SB.sponsorTimesSkipsDoneEndWord.innerText = chrome.i18n.getMessage("Sponsors");
|
||||
} else {
|
||||
SB.sponsorTimesSkipsDoneEndWord.innerText = chrome.i18n.getMessage("Sponsor");
|
||||
}
|
||||
});
|
||||
|
||||
SB.sponsorTimesSkipsDoneDisplay.innerText = SB.config.skipCount;
|
||||
SB.sponsorTimesSkipsDoneContainer.style.display = "unset";
|
||||
}
|
||||
|
||||
//get the amount of time this user has saved.
|
||||
chrome.storage.sync.get(["minutesSaved"], function(result) {
|
||||
if (result.minutesSaved != undefined) {
|
||||
if (result.minutesSaved != 1) {
|
||||
SB.sponsorTimeSavedEndWord.innerText = chrome.i18n.getMessage("minsLower");
|
||||
} else {
|
||||
SB.sponsorTimeSavedEndWord.innerText = chrome.i18n.getMessage("minLower");
|
||||
}
|
||||
|
||||
SB.sponsorTimeSavedDisplay.innerText = getFormattedHours(result.minutesSaved);
|
||||
SB.sponsorTimeSavedContainer.style.display = "unset";
|
||||
if (SB.config.minutesSaved != undefined) {
|
||||
if (SB.config.minutesSaved != 1) {
|
||||
SB.sponsorTimeSavedEndWord.innerText = chrome.i18n.getMessage("minsLower");
|
||||
} else {
|
||||
SB.sponsorTimeSavedEndWord.innerText = chrome.i18n.getMessage("minLower");
|
||||
}
|
||||
});
|
||||
|
||||
SB.sponsorTimeSavedDisplay.innerText = getFormattedHours(SB.config.minutesSaved);
|
||||
SB.sponsorTimeSavedContainer.style.display = "unset";
|
||||
}
|
||||
|
||||
chrome.tabs.query({
|
||||
active: true,
|
||||
currentWindow: true
|
||||
}, onTabs);
|
||||
|
||||
|
||||
function onTabs(tabs) {
|
||||
chrome.tabs.sendMessage(tabs[0].id, {message: 'getVideoID'}, function(result) {
|
||||
if (result != undefined && result.videoID) {
|
||||
|
@ -250,25 +231,24 @@ function runThePopup() {
|
|||
}
|
||||
|
||||
//load video times for this video
|
||||
let sponsorTimeKey = "sponsorTimes" + currentVideoID;
|
||||
chrome.storage.sync.get([sponsorTimeKey], function(result) {
|
||||
let sponsorTimesStorage = result[sponsorTimeKey];
|
||||
if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) {
|
||||
if (sponsorTimesStorage[sponsorTimesStorage.length - 1] != undefined && sponsorTimesStorage[sponsorTimesStorage.length - 1].length < 2) {
|
||||
startTimeChosen = true;
|
||||
SB.sponsorStart.innerHTML = chrome.i18n.getMessage("sponsorEnd");
|
||||
}
|
||||
|
||||
sponsorTimes = sponsorTimesStorage;
|
||||
|
||||
displaySponsorTimes();
|
||||
|
||||
//show submission section
|
||||
SB.submissionSection.style.display = "unset";
|
||||
|
||||
showSubmitTimesIfNecessary();
|
||||
console.log( SB.config.sponsorTimes.set)
|
||||
setTimeout(()=> console.log( SB.config.sponsorTimes.set), 200 )
|
||||
let sponsorTimesStorage = SB.config.sponsorTimes.get(currentVideoID);
|
||||
if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) {
|
||||
if (sponsorTimesStorage[sponsorTimesStorage.length - 1] != undefined && sponsorTimesStorage[sponsorTimesStorage.length - 1].length < 2) {
|
||||
startTimeChosen = true;
|
||||
SB.sponsorStart.innerHTML = chrome.i18n.getMessage("sponsorEnd");
|
||||
}
|
||||
});
|
||||
|
||||
sponsorTimes = sponsorTimesStorage;
|
||||
|
||||
displaySponsorTimes();
|
||||
|
||||
//show submission section
|
||||
SB.submissionSection.style.display = "unset";
|
||||
|
||||
showSubmitTimesIfNecessary();
|
||||
}
|
||||
|
||||
//check if this video's sponsors are known
|
||||
chrome.tabs.sendMessage(
|
||||
|
@ -347,10 +327,9 @@ function runThePopup() {
|
|||
}
|
||||
|
||||
sponsorTimes[sponsorTimesIndex][startTimeChosen ? 1 : 0] = response.time;
|
||||
|
||||
let sponsorTimeKey = "sponsorTimes" + currentVideoID;
|
||||
|
||||
let localStartTimeChosen = startTimeChosen;
|
||||
chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}, function() {
|
||||
SB.config.sponsorTimes.set(currentVideoID, sponsorTimes);
|
||||
//send a message to the client script
|
||||
if (localStartTimeChosen) {
|
||||
chrome.tabs.query({
|
||||
|
@ -363,7 +342,6 @@ function runThePopup() {
|
|||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
updateStartTimeChosen();
|
||||
|
||||
|
@ -683,8 +661,7 @@ function runThePopup() {
|
|||
sponsorTimes[index][1] = getSponsorTimeEditTimes("endTime", index);
|
||||
|
||||
//save this
|
||||
let sponsorTimeKey = "sponsorTimes" + currentVideoID;
|
||||
chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}, function() {
|
||||
SB.config.sponsorTimes.set(currentVideoID, sponsorTimes);
|
||||
chrome.tabs.query({
|
||||
active: true,
|
||||
currentWindow: true
|
||||
|
@ -694,7 +671,6 @@ function runThePopup() {
|
|||
{message: "sponsorDataChanged"}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
if (closeEditMode) {
|
||||
displaySponsorTimes();
|
||||
|
@ -724,8 +700,7 @@ function runThePopup() {
|
|||
sponsorTimes.splice(index, 1);
|
||||
|
||||
//save this
|
||||
let sponsorTimeKey = "sponsorTimes" + currentVideoID;
|
||||
chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}, function() {
|
||||
SB.config.sponsorTimes.set(currentVideoID, sponsorTimes);
|
||||
chrome.tabs.query({
|
||||
active: true,
|
||||
currentWindow: true
|
||||
|
@ -735,7 +710,6 @@ function runThePopup() {
|
|||
{message: "sponsorDataChanged"}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
//update display
|
||||
displaySponsorTimes();
|
||||
|
@ -776,9 +750,8 @@ function runThePopup() {
|
|||
|
||||
//reset sponsorTimes
|
||||
sponsorTimes = [];
|
||||
|
||||
let sponsorTimeKey = "sponsorTimes" + currentVideoID;
|
||||
chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}, function() {
|
||||
|
||||
SB.config.sponsorTimes.set(currentVideoID, sponsorTimes);
|
||||
chrome.tabs.query({
|
||||
active: true,
|
||||
currentWindow: true
|
||||
|
@ -788,7 +761,6 @@ function runThePopup() {
|
|||
{message: "sponsorDataChanged"}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
displaySponsorTimes();
|
||||
|
||||
|
@ -826,7 +798,7 @@ function runThePopup() {
|
|||
}
|
||||
|
||||
function showNoticeAgain() {
|
||||
chrome.storage.sync.set({"dontShowNotice": false});
|
||||
SB.config.dontShowNotice = false;
|
||||
|
||||
chrome.tabs.query({
|
||||
active: true,
|
||||
|
@ -875,10 +847,8 @@ function runThePopup() {
|
|||
|
||||
//make the options username setting option visible
|
||||
function setUsernameButton() {
|
||||
//get the userID
|
||||
chrome.storage.sync.get(["userID"], function(result) {
|
||||
//get username from the server
|
||||
sendRequestToServer("GET", "/api/getUsername?userID=" + result.userID, function (xmlhttp, error) {
|
||||
sendRequestToServer("GET", "/api/getUsername?userID=" + SB.config.userID, function (xmlhttp, error) {
|
||||
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
||||
SB.usernameInput.value = JSON.parse(xmlhttp.responseText).userName;
|
||||
|
||||
|
@ -898,7 +868,6 @@ function runThePopup() {
|
|||
SB.setUsernameStatus.innerText = getErrorMessage(xmlhttp.status);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//submit the new username
|
||||
|
@ -908,8 +877,7 @@ function runThePopup() {
|
|||
SB.setUsernameStatus.innerText = "Loading...";
|
||||
|
||||
//get the userID
|
||||
chrome.storage.sync.get(["userID"], function(result) {
|
||||
sendRequestToServer("POST", "/api/setUsername?userID=" + result.userID + "&username=" + SB.usernameInput.value, function (xmlhttp, error) {
|
||||
sendRequestToServer("POST", "/api/setUsername?userID=" + SB.config.userID + "&username=" + SB.usernameInput.value, function (xmlhttp, error) {
|
||||
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
||||
//submitted
|
||||
SB.submitUsername.style.display = "none";
|
||||
|
@ -920,7 +888,6 @@ function runThePopup() {
|
|||
SB.setUsernameStatus.innerText = getErrorMessageI(xmlhttp.status);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
SB.setUsernameContainer.style.display = "none";
|
||||
|
@ -980,8 +947,7 @@ function runThePopup() {
|
|||
}
|
||||
|
||||
function hideDiscordButton() {
|
||||
chrome.storage.sync.set({"hideDiscordLink": true});
|
||||
|
||||
SB.config.hideDiscordLink = true;
|
||||
SB.discordButtonContainer.style.display = "none";
|
||||
}
|
||||
|
||||
|
@ -1010,8 +976,7 @@ function runThePopup() {
|
|||
{message: 'getChannelURL'},
|
||||
function(response) {
|
||||
//get whitelisted channels
|
||||
chrome.storage.sync.get(["whitelistedChannels"], function(result) {
|
||||
let whitelistedChannels = result.whitelistedChannels;
|
||||
let whitelistedChannels = SB.config.whitelistedChannels;
|
||||
if (whitelistedChannels == undefined) {
|
||||
whitelistedChannels = [];
|
||||
}
|
||||
|
@ -1027,7 +992,7 @@ function runThePopup() {
|
|||
SB.downloadedSponsorMessageTimes.style.fontWeight = "bold";
|
||||
|
||||
//save this
|
||||
chrome.storage.sync.set({whitelistedChannels: whitelistedChannels});
|
||||
SB.config.whitelistedChannels = whitelistedChannels;
|
||||
|
||||
//send a message to the client
|
||||
chrome.tabs.query({
|
||||
|
@ -1041,7 +1006,6 @@ function runThePopup() {
|
|||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -1058,8 +1022,7 @@ function runThePopup() {
|
|||
{message: 'getChannelURL'},
|
||||
function(response) {
|
||||
//get whitelisted channels
|
||||
chrome.storage.sync.get(["whitelistedChannels"], function(result) {
|
||||
let whitelistedChannels = result.whitelistedChannels;
|
||||
let whitelistedChannels = SB.config.whitelistedChannels;
|
||||
if (whitelistedChannels == undefined) {
|
||||
whitelistedChannels = [];
|
||||
}
|
||||
|
@ -1076,7 +1039,7 @@ function runThePopup() {
|
|||
SB.downloadedSponsorMessageTimes.style.fontWeight = "unset";
|
||||
|
||||
//save this
|
||||
chrome.storage.sync.set({whitelistedChannels: whitelistedChannels});
|
||||
SB.config.whitelistedChannels = whitelistedChannels;
|
||||
|
||||
//send a message to the client
|
||||
chrome.tabs.query({
|
||||
|
@ -1090,7 +1053,6 @@ function runThePopup() {
|
|||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -1100,7 +1062,7 @@ function runThePopup() {
|
|||
* Should skipping be disabled (visuals stay)
|
||||
*/
|
||||
function toggleSkipping(disabled) {
|
||||
chrome.storage.sync.set({"disableSkipping": disabled});
|
||||
SB.config.disableSkipping = disabled;
|
||||
|
||||
let hiddenButton = SB.disableSkipping;
|
||||
let shownButton = SB.enableSkipping;
|
||||
|
@ -1169,7 +1131,6 @@ function runThePopup() {
|
|||
if (chrome.tabs != undefined) {
|
||||
//add the width restriction (because Firefox)
|
||||
document.getElementById("sponorBlockStyleSheet").sheet.insertRule('.popupBody { width: 325 }', 0);
|
||||
|
||||
//this means it is actually opened in the popup
|
||||
runThePopup();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue