diff options
author | Ajay Ramachandran <[email protected]> | 2021-07-04 16:12:41 -0400 |
---|---|---|
committer | Ajay Ramachandran <[email protected]> | 2021-07-04 16:12:41 -0400 |
commit | 7f8947dd0ae9ff66e5bb975d2d24aef7d633032f (patch) | |
tree | 5b5d7a356a39ccaa5d15b8595eeb2e80007a5093 /src | |
parent | 0ae34c960333a167c8ea2b6d27b066ba3f1c249e (diff) | |
download | SponsorBlock-7f8947dd0ae9ff66e5bb975d2d24aef7d633032f.tar.gz SponsorBlock-7f8947dd0ae9ff66e5bb975d2d24aef7d633032f.zip |
Add refresh segments button
Diffstat (limited to 'src')
-rw-r--r-- | src/content.ts | 28 | ||||
-rw-r--r-- | src/messageTypes.ts | 3 | ||||
-rw-r--r-- | src/popup.ts | 14 |
3 files changed, 32 insertions, 13 deletions
diff --git a/src/content.ts b/src/content.ts index c6adf03b..8f98edaa 100644 --- a/src/content.ts +++ b/src/content.ts @@ -178,6 +178,9 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo case "submitTimes": submitSponsorTimes(); break; + case "refreshSegments": + sponsorsLookup(sponsorVideoID, false); + break; } } @@ -209,6 +212,7 @@ function resetValues() { //reset sponsor times sponsorTimes = null; sponsorLookupRetries = 0; + sponsorSkipped = []; videoInfo = null; channelWhitelisted = false; @@ -569,7 +573,7 @@ function setupVideoListeners() { } } -async function sponsorsLookup(id: string) { +async function sponsorsLookup(id: string, keepOldSubmissions = true) { if (!video) refreshVideoAttachments(); //there is still no video here if (!video) { @@ -606,7 +610,7 @@ async function sponsorsLookup(id: string) { sponsorDataFound = true; // Check if any old submissions should be kept - if (sponsorTimes !== null) { + if (sponsorTimes !== null && keepOldSubmissions) { for (let i = 0; i < sponsorTimes.length; i++) { if (sponsorTimes[i].source === SponsorSourceType.Local) { // This is a user submission, keep it @@ -627,20 +631,19 @@ async function sponsorsLookup(id: string) { } } - for (const segment of oldSegments) { - const otherSegment = sponsorTimes.find((other) => segment.UUID === other.UUID); - if (otherSegment) { - // If they downvoted it, or changed the category, keep it - otherSegment.hidden = segment.hidden; - otherSegment.category = segment.category; + if (keepOldSubmissions) { + for (const segment of oldSegments) { + const otherSegment = sponsorTimes.find((other) => segment.UUID === other.UUID); + if (otherSegment) { + // If they downvoted it, or changed the category, keep it + otherSegment.hidden = segment.hidden; + otherSegment.category = segment.category; + } } } startSkipScheduleCheckingForStartSponsors(); - // Reset skip save - sponsorSkipped = []; - //update the preview bar //leave the type blank for now until categories are added if (lastPreviewBarUpdate == id || (lastPreviewBarUpdate == null && !isNaN(video.duration))) { @@ -1408,11 +1411,12 @@ function openInfoMenu() { const settings = <HTMLImageElement> popup.querySelector("#sbPopupIconSettings"); const edit = <HTMLImageElement> popup.querySelector("#sbPopupIconEdit"); const check = <HTMLImageElement> popup.querySelector("#sbPopupIconCheck"); + const refreshSegments = <HTMLImageElement> popup.querySelector("#refreshSegments"); logo.src = chrome.extension.getURL("icons/IconSponsorBlocker256px.png"); settings.src = chrome.extension.getURL("icons/settings.svg"); edit.src = chrome.extension.getURL("icons/pencil.svg"); check.src = chrome.extension.getURL("icons/check.svg"); - check.src = chrome.extension.getURL("icons/thumb.svg"); + refreshSegments.src = chrome.extension.getURL("icons/refresh.svg"); parentNode.insertBefore(popup, parentNode.firstChild); diff --git a/src/messageTypes.ts b/src/messageTypes.ts index 1c69388a..525ec513 100644 --- a/src/messageTypes.ts +++ b/src/messageTypes.ts @@ -16,7 +16,8 @@ interface DefaultMessage { | "getVideoID" | "getChannelID" | "isChannelWhitelisted" - | "submitTimes"; + | "submitTimes" + | "refreshSegments"; } interface BoolValueMessage { diff --git a/src/popup.ts b/src/popup.ts index ea752620..9efa790f 100644 --- a/src/popup.ts +++ b/src/popup.ts @@ -102,6 +102,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> { "videoFound", "sponsorMessageTimes", //"downloadedSponsorMessageTimes", + "refreshSegmentsButton", "whitelistButton", "sbDonate" ].forEach(id => PageElements[id] = document.getElementById(id)); @@ -131,6 +132,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> { PageElements.submitUsername.addEventListener("click", submitUsername); PageElements.optionsButton.addEventListener("click", openOptions); PageElements.helpButton.addEventListener("click", openHelp); + PageElements.refreshSegmentsButton.addEventListener("click", refreshSegments); /** If true, the content script is in the process of creating a new segment. */ let creatingSegment = false; @@ -676,6 +678,18 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> { }); } + function refreshSegments() { + messageHandler.query({ + active: true, + currentWindow: true + }, tabs => { + messageHandler.sendMessage( + tabs[0].id, + {message: 'refreshSegments'} + )} + ); + } + /** * Should skipping be disabled (visuals stay) */ |