aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormini-bomba <[email protected]>2022-11-04 22:02:54 +0100
committerGitHub <[email protected]>2022-11-04 17:02:54 -0400
commit89e87cd74de4583ead073fae9f7ed2cb9747380e (patch)
treede2c9b60816df7161c76fbaf29222197118009cc
parent311c4caf2be26f6bd1e92efc89839f8f6f058810 (diff)
downloadSponsorBlock-89e87cd74de4583ead073fae9f7ed2cb9747380e.tar.gz
SponsorBlock-89e87cd74de4583ead073fae9f7ed2cb9747380e.zip
Don't update the whole segment list on time update (#1569)
Update segment element classes instead. This probably is more efficient than what we're doing currently. Also, this seems to fix a bug where the vote confirmation/error msg is removed immediately
-rw-r--r--src/popup.ts30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/popup.ts b/src/popup.ts
index 526b6381..ddfff407 100644
--- a/src/popup.ts
+++ b/src/popup.ts
@@ -614,6 +614,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
const votingButtons = document.createElement("details");
votingButtons.classList.add("votingButtons");
votingButtons.id = "votingButtons" + UUID;
+ votingButtons.setAttribute("data-uuid", UUID);
votingButtons.addEventListener("toggle", () => {
if (votingButtons.open) {
openedUUIDs.push(UUID);
@@ -1068,10 +1069,37 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
port.onMessage.addListener((msg) => onMessage(msg));
}
+ function updateCurrentTime(currentTime: number) {
+ // Create a map of segment UUID -> segment object for easy access
+ const segmentMap: Record<string, SponsorTime> = {};
+ for (const segment of downloadedTimes)
+ segmentMap[segment.UUID] = segment
+
+ // Iterate over segment elements and update their classes
+ const segmentList = document.getElementById("issueReporterTimeButtons");
+ for (const segmentElement of segmentList.children) {
+ const UUID = segmentElement.getAttribute("data-uuid");
+ if (UUID == null || segmentMap[UUID] == undefined) continue;
+
+ const summaryElement = segmentElement.querySelector("summary")
+ if (summaryElement == null) continue;
+
+ const segment = segmentMap[UUID]
+ summaryElement.classList.remove("segmentActive", "segmentPassed")
+ if (currentTime >= segment.segment[0]) {
+ if (currentTime < segment.segment[1]) {
+ summaryElement.classList.add("segmentActive");
+ } else {
+ summaryElement.classList.add("segmentPassed");
+ }
+ }
+ }
+ }
+
function onMessage(msg: PopupMessage) {
switch (msg.message) {
case "time":
- displayDownloadedSponsorTimes(downloadedTimes, msg.time);
+ updateCurrentTime(msg.time);
break;
case "infoUpdated":
infoFound(msg);