mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-10 13:37:04 +03:00
Add indicator where current player is for segments in popup
This commit is contained in:
@@ -219,6 +219,15 @@
|
|||||||
.segmentSummary > div {
|
.segmentSummary > div {
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.segmentActive {
|
||||||
|
color: #bdfffb;
|
||||||
|
}
|
||||||
|
|
||||||
|
.segmentPassed {
|
||||||
|
color: #adadad;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Category dot in segment
|
* Category dot in segment
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ const utils = new Utils({
|
|||||||
unregisterFirefoxContentScript
|
unregisterFirefoxContentScript
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const popupPort: Record<string, chrome.runtime.Port> = {};
|
||||||
|
|
||||||
// Used only on Firefox, which does not support non persistent background pages.
|
// Used only on Firefox, which does not support non persistent background pages.
|
||||||
const contentScriptRegistrations = {};
|
const contentScriptRegistrations = {};
|
||||||
|
|
||||||
@@ -53,7 +55,7 @@ if (!Config.configSyncListeners.includes(onNavigationApiAvailableChange)) {
|
|||||||
Config.configSyncListeners.push(onNavigationApiAvailableChange);
|
Config.configSyncListeners.push(onNavigationApiAvailableChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.runtime.onMessage.addListener(function (request, _, callback) {
|
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
||||||
switch(request.message) {
|
switch(request.message) {
|
||||||
case "openConfig":
|
case "openConfig":
|
||||||
chrome.tabs.create({url: chrome.runtime.getURL('options/options.html' + (request.hash ? '#' + request.hash : ''))});
|
chrome.tabs.create({url: chrome.runtime.getURL('options/options.html' + (request.hash ? '#' + request.hash : ''))});
|
||||||
@@ -100,6 +102,22 @@ chrome.runtime.onMessage.addListener(function (request, _, callback) {
|
|||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
case "time":
|
||||||
|
if (sender.tab) {
|
||||||
|
popupPort[sender.tab.id].postMessage(request);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
chrome.runtime.onConnect.addListener((port) => {
|
||||||
|
if (port.name === "popup") {
|
||||||
|
chrome.tabs.query({
|
||||||
|
active: true,
|
||||||
|
currentWindow: true
|
||||||
|
}, tabs => {
|
||||||
|
popupPort[tabs[0].id] = port;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ interface SBConfig {
|
|||||||
categoryPillUpdate: boolean,
|
categoryPillUpdate: boolean,
|
||||||
darkMode: boolean,
|
darkMode: boolean,
|
||||||
showCategoryGuidelines: boolean,
|
showCategoryGuidelines: boolean,
|
||||||
chaptersActivated: boolean,
|
chaptersAvailable: boolean,
|
||||||
|
|
||||||
// Used to cache calculated text color info
|
// Used to cache calculated text color info
|
||||||
categoryPillColors: {
|
categoryPillColors: {
|
||||||
@@ -175,7 +175,7 @@ const Config: SBObject = {
|
|||||||
categoryPillUpdate: false,
|
categoryPillUpdate: false,
|
||||||
darkMode: true,
|
darkMode: true,
|
||||||
showCategoryGuidelines: true,
|
showCategoryGuidelines: true,
|
||||||
chaptersActivated: true,
|
chaptersAvailable: true,
|
||||||
|
|
||||||
categoryPillColors: {},
|
categoryPillColors: {},
|
||||||
|
|
||||||
|
|||||||
@@ -167,6 +167,7 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
|
|||||||
sendResponse({
|
sendResponse({
|
||||||
found: sponsorDataFound,
|
found: sponsorDataFound,
|
||||||
sponsorTimes: sponsorTimes,
|
sponsorTimes: sponsorTimes,
|
||||||
|
time: video.currentTime,
|
||||||
onMobileYouTube
|
onMobileYouTube
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -208,6 +209,7 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
|
|||||||
sponsorsLookup(false).then(() => sendResponse({
|
sponsorsLookup(false).then(() => sendResponse({
|
||||||
found: sponsorDataFound,
|
found: sponsorDataFound,
|
||||||
sponsorTimes: sponsorTimes,
|
sponsorTimes: sponsorTimes,
|
||||||
|
time: video.currentTime,
|
||||||
onMobileYouTube
|
onMobileYouTube
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -532,7 +534,7 @@ function startSponsorSchedule(includeIntersectingSegments = false, currentTime?:
|
|||||||
}
|
}
|
||||||
lastTimeFromWaitingEvent = null;
|
lastTimeFromWaitingEvent = null;
|
||||||
|
|
||||||
previewBar?.updateChapterText(sponsorTimes, sponsorTimesSubmitting, currentTime);
|
updateActiveSegment(currentTime);
|
||||||
|
|
||||||
if (video.paused) return;
|
if (video.paused) return;
|
||||||
if (videoMuted && !inMuteSegment(currentTime)) {
|
if (videoMuted && !inMuteSegment(currentTime)) {
|
||||||
@@ -783,7 +785,7 @@ function setupVideoListeners() {
|
|||||||
|
|
||||||
startSponsorSchedule();
|
startSponsorSchedule();
|
||||||
} else {
|
} else {
|
||||||
previewBar?.updateChapterText(sponsorTimes, sponsorTimesSubmitting, video.currentTime);
|
updateActiveSegment(video.currentTime);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
video.addEventListener('ratechange', () => startSponsorSchedule());
|
video.addEventListener('ratechange', () => startSponsorSchedule());
|
||||||
@@ -2069,6 +2071,14 @@ function getSegmentsMessage(sponsorTimes: SponsorTime[]): string {
|
|||||||
return sponsorTimesMessage;
|
return sponsorTimesMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateActiveSegment(currentTime: number): void {
|
||||||
|
previewBar?.updateChapterText(sponsorTimes, sponsorTimesSubmitting, currentTime);
|
||||||
|
chrome.runtime.sendMessage({
|
||||||
|
message: "time",
|
||||||
|
time: currentTime
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function addPageListeners(): void {
|
function addPageListeners(): void {
|
||||||
const refreshListners = () => {
|
const refreshListners = () => {
|
||||||
if (!isVisible(video)) {
|
if (!isVisible(video)) {
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ export type Message = BaseMessage & (DefaultMessage | BoolValueMessage | IsInfoF
|
|||||||
export interface IsInfoFoundMessageResponse {
|
export interface IsInfoFoundMessageResponse {
|
||||||
found: boolean;
|
found: boolean;
|
||||||
sponsorTimes: SponsorTime[];
|
sponsorTimes: SponsorTime[];
|
||||||
|
time: number;
|
||||||
onMobileYouTube: boolean;
|
onMobileYouTube: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,3 +113,10 @@ export interface VoteResponse {
|
|||||||
export interface ImportSegmentsResponse {
|
export interface ImportSegmentsResponse {
|
||||||
importedSegments: SponsorTime[];
|
importedSegments: SponsorTime[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface TimeUpdateMessage {
|
||||||
|
message: "time";
|
||||||
|
time: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type PopupMessage = TimeUpdateMessage;
|
||||||
|
|||||||
41
src/popup.ts
41
src/popup.ts
@@ -2,7 +2,7 @@ import Config from "./config";
|
|||||||
|
|
||||||
import Utils from "./utils";
|
import Utils from "./utils";
|
||||||
import { SponsorTime, SponsorHideType, ActionType, SegmentUUID, SponsorSourceType, StorageChangesObject, CategorySkipOption } from "./types";
|
import { SponsorTime, SponsorHideType, ActionType, SegmentUUID, SponsorSourceType, StorageChangesObject, CategorySkipOption } from "./types";
|
||||||
import { Message, MessageResponse, IsInfoFoundMessageResponse, ImportSegmentsResponse } from "./messageTypes";
|
import { Message, MessageResponse, IsInfoFoundMessageResponse, ImportSegmentsResponse, PopupMessage } from "./messageTypes";
|
||||||
import { showDonationLink } from "./utils/configUtils";
|
import { showDonationLink } from "./utils/configUtils";
|
||||||
import { AnimationUtils } from "./utils/animationUtils";
|
import { AnimationUtils } from "./utils/animationUtils";
|
||||||
import { GenericUtils } from "./utils/genericUtils";
|
import { GenericUtils } from "./utils/genericUtils";
|
||||||
@@ -81,6 +81,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
|||||||
Chapters
|
Chapters
|
||||||
}
|
}
|
||||||
let segmentTab = SegmentTab.Segments;
|
let segmentTab = SegmentTab.Segments;
|
||||||
|
let port: chrome.runtime.Port = null;
|
||||||
|
|
||||||
const PageElements: PageElements = {};
|
const PageElements: PageElements = {};
|
||||||
|
|
||||||
@@ -237,6 +238,8 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupComPort();
|
||||||
|
|
||||||
//show proper disable skipping button
|
//show proper disable skipping button
|
||||||
const disableSkipping = Config.config.disableSkipping;
|
const disableSkipping = Config.config.disableSkipping;
|
||||||
if (disableSkipping != undefined && disableSkipping) {
|
if (disableSkipping != undefined && disableSkipping) {
|
||||||
@@ -403,10 +406,13 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
|||||||
PageElements.whitelistButton.classList.remove("hidden");
|
PageElements.whitelistButton.classList.remove("hidden");
|
||||||
PageElements.loadingIndicator.style.display = "none";
|
PageElements.loadingIndicator.style.display = "none";
|
||||||
|
|
||||||
|
downloadedTimes = request.sponsorTimes ?? [];
|
||||||
if (request.found) {
|
if (request.found) {
|
||||||
PageElements.videoFound.innerHTML = chrome.i18n.getMessage("sponsorFound");
|
PageElements.videoFound.innerHTML = chrome.i18n.getMessage("sponsorFound");
|
||||||
|
|
||||||
displayDownloadedSponsorTimes(request);
|
if (request.sponsorTimes) {
|
||||||
|
displayDownloadedSponsorTimes(request.sponsorTimes, request.time);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
PageElements.videoFound.innerHTML = chrome.i18n.getMessage("sponsor404");
|
PageElements.videoFound.innerHTML = chrome.i18n.getMessage("sponsor404");
|
||||||
}
|
}
|
||||||
@@ -477,10 +483,9 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//display the video times from the array at the top, in a different section
|
//display the video times from the array at the top, in a different section
|
||||||
function displayDownloadedSponsorTimes(request: { found: boolean, sponsorTimes: SponsorTime[] }) {
|
function displayDownloadedSponsorTimes(sponsorTimes: SponsorTime[], time: number) {
|
||||||
if (request.sponsorTimes != undefined) {
|
|
||||||
let currentSegmentTab = segmentTab;
|
let currentSegmentTab = segmentTab;
|
||||||
if (!request.sponsorTimes.some((segment) => segment.actionType === ActionType.Chapter)) {
|
if (!sponsorTimes.some((segment) => segment.actionType === ActionType.Chapter)) {
|
||||||
PageElements.issueReporterTabs.classList.add("hidden");
|
PageElements.issueReporterTabs.classList.add("hidden");
|
||||||
currentSegmentTab = SegmentTab.Segments;
|
currentSegmentTab = SegmentTab.Segments;
|
||||||
} else {
|
} else {
|
||||||
@@ -488,7 +493,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sort list by start time
|
// Sort list by start time
|
||||||
downloadedTimes = request.sponsorTimes
|
const downloadedTimes = sponsorTimes
|
||||||
.filter((segment) => {
|
.filter((segment) => {
|
||||||
if (currentSegmentTab === SegmentTab.Segments) {
|
if (currentSegmentTab === SegmentTab.Segments) {
|
||||||
return segment.actionType !== ActionType.Chapter;
|
return segment.actionType !== ActionType.Chapter;
|
||||||
@@ -525,7 +530,14 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
|||||||
const actionType = downloadedTimes[i].actionType;
|
const actionType = downloadedTimes[i].actionType;
|
||||||
|
|
||||||
const segmentSummary = document.createElement("summary");
|
const segmentSummary = document.createElement("summary");
|
||||||
segmentSummary.className = "segmentSummary";
|
segmentSummary.classList.add("segmentSummary");
|
||||||
|
if (time >= downloadedTimes[i].segment[0]) {
|
||||||
|
if (time < downloadedTimes[i].segment[1]) {
|
||||||
|
segmentSummary.classList.add("segmentActive");
|
||||||
|
} else {
|
||||||
|
segmentSummary.classList.add("segmentPassed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const categoryColorCircle = document.createElement("span");
|
const categoryColorCircle = document.createElement("span");
|
||||||
categoryColorCircle.id = "sponsorTimesCategoryColorCircle" + UUID;
|
categoryColorCircle.id = "sponsorTimesCategoryColorCircle" + UUID;
|
||||||
@@ -675,7 +687,6 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
|||||||
container.appendChild(votingButtons);
|
container.appendChild(votingButtons);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function submitTimes() {
|
function submitTimes() {
|
||||||
if (sponsorTimes.length > 0) {
|
if (sponsorTimes.length > 0) {
|
||||||
@@ -1076,6 +1087,20 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setupComPort(): void {
|
||||||
|
port = chrome.runtime.connect({ name: "popup" });
|
||||||
|
port.onDisconnect.addListener(() => setupComPort());
|
||||||
|
port.onMessage.addListener((msg) => onMessage(msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
function onMessage(msg: PopupMessage) {
|
||||||
|
switch (msg.message) {
|
||||||
|
case "time":
|
||||||
|
displayDownloadedSponsorTimes(downloadedTimes, msg.time);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
runThePopup();
|
runThePopup();
|
||||||
|
|||||||
Reference in New Issue
Block a user