mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-06 19:47:04 +03:00
Merge pull request #226 from ajayyy/ajay-config-listener
Config callback updating
This commit is contained in:
15
SB.js
15
SB.js
@@ -1,4 +1,11 @@
|
||||
SB = {};
|
||||
SB = {
|
||||
/**
|
||||
* Callback function when an option is updated
|
||||
*
|
||||
* @type {CallableFunction}
|
||||
*/
|
||||
configListeners: []
|
||||
};
|
||||
|
||||
// Function setup
|
||||
|
||||
@@ -82,9 +89,13 @@ function decodeStoredItem(data) {
|
||||
|
||||
function configProxy() {
|
||||
chrome.storage.onChanged.addListener((changes, namespace) => {
|
||||
for (key in changes) {
|
||||
for (const key in changes) {
|
||||
SB.localConfig[key] = decodeStoredItem(changes[key].newValue);
|
||||
}
|
||||
|
||||
for (const callback of SB.configListeners) {
|
||||
callback(changes);
|
||||
}
|
||||
});
|
||||
|
||||
var handler = {
|
||||
|
||||
@@ -35,10 +35,10 @@ chrome.runtime.onMessage.addListener(async function (request, sender, callback)
|
||||
return true;
|
||||
case "alertPrevious":
|
||||
chrome.notifications.create("stillThere" + Math.random(), {
|
||||
type: "basic",
|
||||
title: chrome.i18n.getMessage("wantToSubmit") + " " + request.previousVideoID + "?",
|
||||
message: chrome.i18n.getMessage("leftTimes"),
|
||||
iconUrl: "./icons/LogoSponsorBlocker256px.png"
|
||||
type: "basic",
|
||||
title: chrome.i18n.getMessage("wantToSubmit") + " " + request.previousVideoID + "?",
|
||||
message: chrome.i18n.getMessage("leftTimes"),
|
||||
iconUrl: "./icons/LogoSponsorBlocker256px.png"
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
72
content.js
72
content.js
@@ -135,39 +135,33 @@ function messageListener(request, sender, sendResponse) {
|
||||
channelWhitelisted = request.value;
|
||||
sponsorsLookup(sponsorVideoID);
|
||||
|
||||
break;
|
||||
case "dontShowNotice":
|
||||
SB.config.dontShowNotice = true;
|
||||
|
||||
break;
|
||||
case "changeStartSponsorButton":
|
||||
changeStartSponsorButton(request.showStartSponsor, request.uploadButtonVisible);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
case "showNoticeAgain":
|
||||
SB.config.dontShowNotice = true;
|
||||
break;
|
||||
|
||||
case "changeVideoPlayerControlsVisibility":
|
||||
SB.config.hideVideoPlayerControls = request.value;
|
||||
updateVisibilityOfPlayerControlsButton();
|
||||
|
||||
break;
|
||||
case "changeInfoButtonPlayerControlsVisibility":
|
||||
SB.config.hideInfoButtonPlayerControls = request.value;
|
||||
updateVisibilityOfPlayerControlsButton();
|
||||
|
||||
break;
|
||||
case "changeDeleteButtonPlayerControlsVisibility":
|
||||
SB.config.hideDeleteButtonPlayerControls = request.value;
|
||||
updateVisibilityOfPlayerControlsButton();
|
||||
|
||||
break;
|
||||
case "trackViewCount":
|
||||
SB.config.trackViewCount = request.value;
|
||||
/**
|
||||
* Called when the config is updated
|
||||
*
|
||||
* @param {String} changes
|
||||
*/
|
||||
function configUpdateListener(changes) {
|
||||
for (const key in changes) {
|
||||
switch(key) {
|
||||
case "hideVideoPlayerControls":
|
||||
case "hideInfoButtonPlayerControls":
|
||||
case "hideDeleteButtonPlayerControls":
|
||||
updateVisibilityOfPlayerControlsButton()
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!SB.configListeners.includes(configUpdateListener)) {
|
||||
SB.configListeners.push(configUpdateListener);
|
||||
}
|
||||
|
||||
//check for hotkey pressed
|
||||
@@ -452,13 +446,11 @@ 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
|
||||
let whitelistedChannels = SB.config.whitelistedChannels;
|
||||
let whitelistedChannels = SB.config.whitelistedChannels;
|
||||
|
||||
console.log(channelURL)
|
||||
|
||||
if (whitelistedChannels != undefined && whitelistedChannels.includes(channelURL)) {
|
||||
channelWhitelisted = true;
|
||||
}
|
||||
if (whitelistedChannels != undefined && whitelistedChannels.includes(channelURL)) {
|
||||
channelWhitelisted = true;
|
||||
}
|
||||
}
|
||||
|
||||
//video skipping
|
||||
@@ -576,13 +568,6 @@ function reskipSponsorTime(UUID) {
|
||||
}
|
||||
}
|
||||
|
||||
function removePlayerControlsButton() {
|
||||
if (!sponsorVideoID) return;
|
||||
|
||||
document.getElementById("startSponsorButton").style.display = "none";
|
||||
document.getElementById("submitButton").style.display = "none";
|
||||
}
|
||||
|
||||
function createButton(baseID, title, callback, imageName, isDraggable=false) {
|
||||
if (document.getElementById(baseID + "Button") != null) return;
|
||||
|
||||
@@ -633,13 +618,20 @@ async function updateVisibilityOfPlayerControlsButton() {
|
||||
|
||||
await createButtons();
|
||||
|
||||
if (SB.config.hideDeleteButtonPlayerControls) {
|
||||
removePlayerControlsButton();
|
||||
if (SB.config.hideVideoPlayerControls) {
|
||||
document.getElementById("startSponsorButton").style.display = "none";
|
||||
document.getElementById("submitButton").style.display = "none";
|
||||
} else {
|
||||
document.getElementById("startSponsorButton").style.removeProperty("display");
|
||||
}
|
||||
|
||||
//don't show the info button on embeds
|
||||
if (SB.config.hideInfoButtonPlayerControls || document.URL.includes("/embed/")) {
|
||||
document.getElementById("infoButton").style.display = "none";
|
||||
} else {
|
||||
document.getElementById("infoButton").style.removeProperty("display");
|
||||
}
|
||||
|
||||
if (SB.config.hideDeleteButtonPlayerControls) {
|
||||
document.getElementById("deleteButton").style.display = "none";
|
||||
}
|
||||
|
||||
9
popup.js
9
popup.js
@@ -800,15 +800,6 @@ async function runThePopup() {
|
||||
function showNoticeAgain() {
|
||||
SB.config.dontShowNotice = false;
|
||||
|
||||
chrome.tabs.query({
|
||||
active: true,
|
||||
currentWindow: true
|
||||
}, function(tabs) {
|
||||
chrome.tabs.sendMessage(tabs[0].id, {
|
||||
message: "showNoticeAgain"
|
||||
});
|
||||
});
|
||||
|
||||
SB.showNoticeAgain.style.display = "none";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user