Use SB.config

This commit is contained in:
Official Noob
2019-12-31 20:56:30 +00:00
committed by GitHub
parent 25672a6496
commit 7bbbe0dcf3

View File

@@ -72,51 +72,42 @@ var popupInitialised = false;
//should skips happen at all //should skips happen at all
var disableSkipping = false; var disableSkipping = false;
chrome.storage.sync.get(["disableSkipping"], function(result) { let disableSkippingStorage = SB.config.disableSkipping;
let disableSkippingStorage = result.disableSkipping; if (disableSkippingStorage != undefined) {
if (disableSkippingStorage != undefined) {
disableSkipping = disableSkippingStorage; disableSkipping = disableSkippingStorage;
} }
});
//should skips be manual //should skips be manual
var disableAutoSkip = false; var disableAutoSkip = false;
chrome.storage.sync.get(["disableAutoSkip"], function(result) { let disableAutoSkipStorage = SB.config.disableAutoSkip;
let disableAutoSkipStorage = result.disableAutoSkip; if (disableAutoSkipStorage != undefined) {
if (disableAutoSkipStorage != undefined) {
disableAutoSkip = disableAutoSkipStorage; disableAutoSkip = disableAutoSkipStorage;
} }
});
//should view counts be tracked //should view counts be tracked
var trackViewCount = false; var trackViewCount = false;
chrome.storage.sync.get(["trackViewCount"], function(result) { let trackViewCountStorage = SB.config.trackViewCount;
let trackViewCountStorage = result.trackViewCount; if (trackViewCountStorage != undefined) {
if (trackViewCountStorage != undefined) {
trackViewCount = trackViewCountStorage; trackViewCount = trackViewCountStorage;
} else { } else {
trackViewCount = true; trackViewCount = true;
} }
});
//if the notice should not be shown //if the notice should not be shown
//happens when the user click's the "Don't show notice again" button //happens when the user click's the "Don't show notice again" button
//option renamed when new notice was made //option renamed when new notice was made
var dontShowNotice = false; var dontShowNotice = false;
chrome.storage.sync.get(["dontShowNotice"], function(result) { let dontShowNoticeAgain = SB.config.dontShowNotice;
let dontShowNoticeAgain = result.dontShowNotice; if (dontShowNoticeAgain != undefined) {
if (dontShowNoticeAgain != undefined) {
dontShowNotice = dontShowNoticeAgain; dontShowNotice = dontShowNoticeAgain;
} }
});
//load the legacy option to hide the notice //load the legacy option to hide the notice
var dontShowNoticeOld = false; var dontShowNoticeOld = false;
chrome.storage.sync.get(["dontShowNoticeAgain"], function(result) { let dontShowNoticeAgain = SB.config.dontShowNoticeAgain;
let dontShowNoticeAgain = result.dontShowNoticeAgain; if (dontShowNoticeAgain != undefined) {
if (dontShowNoticeAgain != undefined) {
dontShowNoticeOld = dontShowNoticeAgain; dontShowNoticeOld = dontShowNoticeAgain;
} }
});
//get messages from the background script and the popup //get messages from the background script and the popup
chrome.runtime.onMessage.addListener(messageListener); chrome.runtime.onMessage.addListener(messageListener);
@@ -231,12 +222,9 @@ document.onkeydown = async function(e){
let video = document.getElementById("movie_player"); let video = document.getElementById("movie_player");
let startSponsorKey = await new Promise((resolve, reject) => { let startSponsorKey = SB.config.startSponsorKeybind;
chrome.storage.sync.get(["startSponsorKeybind"], (result) => resolve(result));
}); let submitKey = SB.config.submitKeybind;
let submitKey = await new Promise((resolve, reject) => {
chrome.storage.sync.get(["submitKeybind"], (result) => resolve(result));
});
if (startSponsorKey.startSponsorKeybind === undefined) { if (startSponsorKey.startSponsorKeybind === undefined) {
startSponsorKey.startSponsorKeybind = ";" startSponsorKey.startSponsorKeybind = ";"
@@ -303,9 +291,7 @@ function videoIDChange(id) {
if (previousVideoID != null) { if (previousVideoID != null) {
//get the sponsor times from storage //get the sponsor times from storage
let sponsorTimeKey = 'sponsorTimes' + previousVideoID; let sponsorTimeKey = 'sponsorTimes' + previousVideoID;
chrome.storage.sync.get([sponsorTimeKey], function(result) { let sponsorTimes = SB.config.sponsorTimeKey[sponsorTimeKey];
let sponsorTimes = result[sponsorTimeKey];
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({
@@ -316,7 +302,6 @@ function videoIDChange(id) {
//set the previous video id to the currentID //set the previous video id to the currentID
previousVideoID = id; previousVideoID = id;
});
} else { } else {
//set the previous id now, don't wait for chrome.storage.get //set the previous id now, don't wait for chrome.storage.get
previousVideoID = id; previousVideoID = id;
@@ -360,28 +345,23 @@ function videoIDChange(id) {
}); });
//see if video controls buttons should be added //see if video controls buttons should be added
chrome.storage.sync.get(["hideVideoPlayerControls"], function(result) { if (SB.config.hideVideoPlayerControls != undefined) {
if (result.hideVideoPlayerControls != undefined) { hideVideoPlayerControls = SB.config.hideVideoPlayerControls;
hideVideoPlayerControls = result.hideVideoPlayerControls;
} }
updateVisibilityOfPlayerControlsButton(); updateVisibilityOfPlayerControlsButton();
});
chrome.storage.sync.get(["hideInfoButtonPlayerControls"], function(result) { if (SB.config.hideInfoButtonPlayerControls != undefined) {
if (result.hideInfoButtonPlayerControls != undefined) { hideInfoButtonPlayerControls = SB.config.hideInfoButtonPlayerControls;
hideInfoButtonPlayerControls = result.hideInfoButtonPlayerControls;
} }
updateVisibilityOfPlayerControlsButton(); updateVisibilityOfPlayerControlsButton();
});
chrome.storage.sync.get(["hideDeleteButtonPlayerControls"], function(result) { if (SB.config.hideDeleteButtonPlayerControls != undefined) {
if (result.hideDeleteButtonPlayerControls != undefined) { hideDeleteButtonPlayerControls = SB.config.hideDeleteButtonPlayerControls;
hideDeleteButtonPlayerControls = result.hideDeleteButtonPlayerControls;
} }
updateVisibilityOfPlayerControlsButton(false); updateVisibilityOfPlayerControlsButton(false);
});
} }
function sponsorsLookup(id, channelIDPromise) { function sponsorsLookup(id, channelIDPromise) {
@@ -542,15 +522,13 @@ function getChannelID() {
//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
chrome.storage.sync.get(["whitelistedChannels"], function(result) { let whitelistedChannels = SB.config.whitelistedChannels;
let whitelistedChannels = result.whitelistedChannels;
console.log(channelURL) console.log(channelURL)
if (whitelistedChannels != undefined && whitelistedChannels.includes(channelURL)) { if (whitelistedChannels != undefined && whitelistedChannels.includes(channelURL)) {
channelWhitelisted = true; channelWhitelisted = true;
} }
});
} }
//video skipping //video skipping
@@ -640,7 +618,7 @@ function skipToTime(v, index, sponsorTimes, openNotice) {
skipNotice.addNoticeInfoMessage(chrome.i18n.getMessage("noticeUpdate"), chrome.i18n.getMessage("noticeUpdate2")); skipNotice.addNoticeInfoMessage(chrome.i18n.getMessage("noticeUpdate"), chrome.i18n.getMessage("noticeUpdate2"));
//remove this setting //remove this setting
chrome.storage.sync.remove(["dontShowNoticeAgain"]); delete SB.config["dontShowNoticeAgain"];
dontShowNoticeOld = false; dontShowNoticeOld = false;
} }
@@ -657,17 +635,12 @@ function skipToTime(v, index, sponsorTimes, openNotice) {
if (!disableAutoSkip) { if (!disableAutoSkip) {
// Count this as a skip // Count this as a skip
chrome.storage.sync.get(["minutesSaved"], function(result) { if (SB.config.minutesSaved === undefined) SB.config.minutesSaved = 0;
if (result.minutesSaved === undefined) result.minutesSaved = 0;
chrome.storage.sync.set({"minutesSaved": result.minutesSaved + (sponsorTimes[index][1] - sponsorTimes[index][0]) / 60 }); SB.config.minutesSaved = SB.config.minutesSaved + (sponsorTimes[index][1] - sponsorTimes[index][0]) / 60;
}); if (SB.config.skipCount === undefined) SB.config.skipCount = 0;
chrome.storage.sync.get(["skipCount"], function(result) {
if (result.skipCount === undefined) result.skipCount = 0;
chrome.storage.sync.set({"skipCount": result.skipCount + 1 });
});
SB.config.skipCount = SB.config.skipCount + 1;
sponsorSkipped[index] = true; sponsorSkipped[index] = true;
} }
} }
@@ -907,8 +880,7 @@ function clearSponsorTimes() {
let currentVideoID = sponsorVideoID; let currentVideoID = sponsorVideoID;
let sponsorTimeKey = 'sponsorTimes' + currentVideoID; let sponsorTimeKey = 'sponsorTimes' + currentVideoID;
chrome.storage.sync.get([sponsorTimeKey], function(result) { let sponsorTimes = SB.config.sponsorTimeKey[sponsorTimeKey];
let sponsorTimes = result[sponsorTimeKey];
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);
@@ -917,7 +889,7 @@ function clearSponsorTimes() {
//clear the sponsor times //clear the sponsor times
let sponsorTimeKey = "sponsorTimes" + currentVideoID; let sponsorTimeKey = "sponsorTimes" + currentVideoID;
chrome.storage.sync.set({[sponsorTimeKey]: []}); SB.config.sponsorTimeKey = [];
//clear sponsor times submitting //clear sponsor times submitting
sponsorTimesSubmitting = []; sponsorTimesSubmitting = [];
@@ -927,7 +899,6 @@ function clearSponsorTimes() {
//set buttons to be correct //set buttons to be correct
changeStartSponsorButton(true, false); changeStartSponsorButton(true, false);
} }
});
} }
//if skipNotice is null, it will not affect the UI //if skipNotice is null, it will not affect the UI
@@ -950,16 +921,13 @@ function vote(type, UUID, skipNotice) {
} }
// Count this as a skip // Count this as a skip
chrome.storage.sync.get(["minutesSaved"], function(result) { if (SB.config.minutesSaved === undefined) SB.config.minutesSaved = 0;
if (result.minutesSaved === undefined) result.minutesSaved = 0;
chrome.storage.sync.set({"minutesSaved": result.minutesSaved + factor * (sponsorTimes[sponsorIndex][1] - sponsorTimes[sponsorIndex][0]) / 60 }); SB.config.minutesSaved = SB.config.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 }); if (SB.config.skipCount === undefined) SB.config.skipCount = 0;
});
SB.config.skipCount = SB.config.skipCount + factor * 1;
} }
chrome.runtime.sendMessage({ chrome.runtime.sendMessage({
@@ -997,7 +965,7 @@ function closeAllSkipNotices(){
} }
function dontShowNoticeAgain() { function dontShowNoticeAgain() {
chrome.storage.sync.set({"dontShowNotice": true}); SB.config.dontShowNotice = true;
dontShowNotice = true; dontShowNotice = true;
@@ -1028,8 +996,7 @@ function submitSponsorTimes() {
let currentVideoID = sponsorVideoID; let currentVideoID = sponsorVideoID;
let sponsorTimeKey = 'sponsorTimes' + currentVideoID; let sponsorTimeKey = 'sponsorTimes' + currentVideoID;
chrome.storage.sync.get([sponsorTimeKey], function(result) { let sponsorTimes = SB.config.sponsorTimeKey[sponsorTimeKey];
let sponsorTimes = result[sponsorTimeKey];
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
@@ -1039,7 +1006,7 @@ function submitSponsorTimes() {
} }
} }
//update sponsorTimes //update sponsorTimes
chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}); SB.config.sponsorTimeKey[sponsorTimeKey] = sponsorTimes;
//update sponsorTimesSubmitting //update sponsorTimesSubmitting
sponsorTimesSubmitting = sponsorTimes; sponsorTimesSubmitting = sponsorTimes;
@@ -1050,7 +1017,6 @@ function submitSponsorTimes() {
sendSubmitMessage(); sendSubmitMessage();
} }
});
} }
@@ -1086,7 +1052,7 @@ function sendSubmitMessage(){
//clear the sponsor times //clear the sponsor times
let sponsorTimeKey = "sponsorTimes" + currentVideoID; let sponsorTimeKey = "sponsorTimes" + currentVideoID;
chrome.storage.sync.set({[sponsorTimeKey]: []}); SB.config.sponsorTimeKey[sponsorTimeKey] = [];
//add submissions to current sponsors list //add submissions to current sponsors list
sponsorTimes = sponsorTimes.concat(sponsorTimesSubmitting); sponsorTimes = sponsorTimes.concat(sponsorTimesSubmitting);