aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components/SponsorTimeEditComponent.tsx21
-rw-r--r--src/components/SubmissionNoticeComponent.tsx2
-rw-r--r--src/config.ts14
-rw-r--r--src/content.ts31
-rw-r--r--src/js-components/chat.ts7
-rw-r--r--src/messageTypes.ts8
-rw-r--r--src/options.ts16
-rw-r--r--src/popup.ts39
-rw-r--r--src/utils.ts2
9 files changed, 96 insertions, 44 deletions
diff --git a/src/components/SponsorTimeEditComponent.tsx b/src/components/SponsorTimeEditComponent.tsx
index 8044b920..c133883f 100644
--- a/src/components/SponsorTimeEditComponent.tsx
+++ b/src/components/SponsorTimeEditComponent.tsx
@@ -177,13 +177,14 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
{this.getCategoryOptions()}
</select>
- <img id={"sponsorTimeCategoriesHelpButton" + this.idSuffix}
- className="helpButton"
- src={chrome.extension.getURL("icons/help.svg")}
- title={chrome.i18n.getMessage("categoryGuidelines")}
- onClick={() => chrome.runtime.sendMessage({"message": "openConfig"})}>
-
- </img>
+ {/* open in new tab */}
+ <a href="https://wiki.sponsor.ajay.app/index.php/Segment_Categories"
+ target="_blank" rel="noreferrer">
+ <img id={"sponsorTimeCategoriesHelpButton" + this.idSuffix}
+ className="helpButton"
+ src={chrome.extension.getURL("icons/help.svg")}
+ title={chrome.i18n.getMessage("categoryGuidelines")} />
+ </a>
</div>
<br/>
@@ -245,7 +246,7 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
categorySelectionChange(event: React.ChangeEvent<HTMLSelectElement>): void {
// See if show more categories was pressed
- if (!Config.config.categorySelections.some((category) => category.name === event.target.value)) {
+ if (event.target.value !== DEFAULT_CATEGORY && !Config.config.categorySelections.some((category) => category.name === event.target.value)) {
const chosenCategory = event.target.value;
event.target.value = DEFAULT_CATEGORY;
@@ -350,7 +351,7 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
const skipTime = sponsorTimes[index].segment[0];
- this.props.contentContainer().previewTime(skipTime + 0.000001, false);
+ this.props.contentContainer().previewTime(skipTime + 0.0001, false);
}
deleteTime(): void {
@@ -385,4 +386,4 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
}
}
-export default SponsorTimeEditComponent; \ No newline at end of file
+export default SponsorTimeEditComponent;
diff --git a/src/components/SubmissionNoticeComponent.tsx b/src/components/SubmissionNoticeComponent.tsx
index 4c019bdc..7fdb0fb6 100644
--- a/src/components/SubmissionNoticeComponent.tsx
+++ b/src/components/SubmissionNoticeComponent.tsx
@@ -95,7 +95,7 @@ class SubmissionNoticeComponent extends React.Component<SubmissionNoticeProps, S
{/* Guidelines button */}
<button className="sponsorSkipObject sponsorSkipNoticeButton sponsorSkipNoticeRightButton"
- onClick={() => window.open("https://github.com/ajayyy/SponsorBlock/wiki/Guidelines")}>
+ onClick={() => window.open("https://wiki.sponsor.ajay.app/index.php/Guidelines")}>
{chrome.i18n.getMessage(Config.config.submissionCountSinceCategories > 3 ? "guidelines" : "readTheGuidelines")}
</button>
diff --git a/src/config.ts b/src/config.ts
index 12b8ab27..7baf2999 100644
--- a/src/config.ts
+++ b/src/config.ts
@@ -38,6 +38,7 @@ interface SBConfig {
ytInfoPermissionGranted: boolean,
allowExpirements: boolean,
autoHideInfoButton: boolean,
+ autoSkipOnMusicVideos: boolean,
// What categories should be skipped
categorySelections: CategorySelection[],
@@ -179,6 +180,7 @@ const Config: SBObject = {
ytInfoPermissionGranted: false,
allowExpirements: true,
autoHideInfoButton: true,
+ autoSkipOnMusicVideos: false,
categorySelections: [{
name: "sponsor" as Category,
@@ -365,6 +367,18 @@ function migrateOldFormats(config: SBConfig) {
chrome.storage.sync.remove("askAboutUnlistedVideos");
}
+ if (!config["autoSkipOnMusicVideosUpdate"]) {
+ config["autoSkipOnMusicVideosUpdate"] = true;
+ for (const selection of config.categorySelections) {
+ if (selection.name === "music_offtopic"
+ && selection.option === CategorySkipOption.AutoSkip) {
+
+ config.autoSkipOnMusicVideos = true;
+ break;
+ }
+ }
+ }
+
// Adding preview category
if (!config["previewCategoryUpdate"]) {
config["previewCategoryUpdate"] = true;
diff --git a/src/content.ts b/src/content.ts
index 88e2075f..df1fcb18 100644
--- a/src/content.ts
+++ b/src/content.ts
@@ -122,7 +122,7 @@ const manualSkipPercentCount = 0.5;
//get messages from the background script and the popup
chrome.runtime.onMessage.addListener(messageListener);
-function messageListener(request: Message, sender: unknown, sendResponse: (response: MessageResponse) => void): void {
+function messageListener(request: Message, sender: unknown, sendResponse: (response: MessageResponse) => void): void | boolean {
//messages from popup script
switch(request.message){
case "update":
@@ -143,7 +143,7 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
sponsorTimes: sponsorTimes
});
- if (popupInitialised && document.getElementById("sponsorBlockPopupContainer") != null) {
+ if (!request.updating && popupInitialised && document.getElementById("sponsorBlockPopupContainer") != null) {
//the popup should be closed now that another is opening
closeInfoMenu();
}
@@ -178,8 +178,12 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
submitSponsorTimes();
break;
case "refreshSegments":
- sponsorsLookup(sponsorVideoID, false).then(() => sendResponse({}));
- break;
+ sponsorsLookup(sponsorVideoID, false).then(() => sendResponse({
+ found: sponsorDataFound,
+ sponsorTimes: sponsorTimes
+ }));
+
+ return true;
}
}
@@ -425,7 +429,7 @@ function startSponsorSchedule(includeIntersectingSegments = false, currentTime?:
skippingSegments = [];
for (const segment of skipInfo.array) {
- if (utils.getCategorySelection(segment.category).option === CategorySkipOption.AutoSkip &&
+ if (shouldAutoSkip(segment) &&
segment.segment[0] >= skipTime[0] && segment.segment[1] <= skipTime[1]) {
skippingSegments.push(segment);
}
@@ -595,7 +599,8 @@ async function sponsorsLookup(id: string, keepOldSubmissions = true) {
// Check for hashPrefix setting
const hashPrefix = (await utils.getHash(id, 1)).substr(0, 4);
const response = await utils.asyncRequestToServer('GET', "/api/skipSegments/" + hashPrefix, {
- categories
+ categories,
+ userAgent: `${chrome.runtime.id}`
});
if (response?.ok) {
@@ -942,7 +947,7 @@ function getNextSkipIndex(currentTime: number, includeIntersectingSegments: bool
function getLatestEndTimeIndex(sponsorTimes: SponsorTime[], index: number, hideHiddenSponsors = true): number {
// Only combine segments for AutoSkip
if (index == -1 ||
- utils.getCategorySelection(sponsorTimes[index].category)?.option !== CategorySkipOption.AutoSkip) return index;
+ shouldAutoSkip(sponsorTimes[index])) return index;
// Default to the normal endTime
let latestEndTimeIndex = index;
@@ -953,7 +958,7 @@ function getLatestEndTimeIndex(sponsorTimes: SponsorTime[], index: number, hideH
if (currentSegment[0] <= latestEndTime && currentSegment[1] > latestEndTime
&& (!hideHiddenSponsors || sponsorTimes[i].hidden === SponsorHideType.Visible)
- && utils.getCategorySelection(sponsorTimes[i].category).option === CategorySkipOption.AutoSkip) {
+ && shouldAutoSkip(sponsorTimes[i])) {
// Overlapping segment
latestEndTimeIndex = i;
}
@@ -1035,7 +1040,7 @@ function sendTelemetryAndCount(skippingSegments: SponsorTime[], secondsSkipped:
//skip from the start time to the end time for a certain index sponsor time
function skipToTime(v: HTMLVideoElement, skipTime: number[], skippingSegments: SponsorTime[], openNotice: boolean) {
// There will only be one submission if it is manual skip
- const autoSkip: boolean = utils.getCategorySelection(skippingSegments[0].category)?.option === CategorySkipOption.AutoSkip;
+ const autoSkip: boolean = shouldAutoSkip(skippingSegments[0]);
if ((autoSkip || sponsorTimesSubmitting.includes(skippingSegments[0])) && v.currentTime !== skipTime[1]) {
// Fix for looped videos not working when skipping to the end #426
@@ -1112,6 +1117,11 @@ function createButton(baseID: string, title: string, callback: () => void, image
return newButton;
}
+function shouldAutoSkip(segment: SponsorTime): boolean {
+ return utils.getCategorySelection(segment.category)?.option === CategorySkipOption.AutoSkip ||
+ (Config.config.autoSkipOnMusicVideos && sponsorTimes.some((s) => s.category === "music_offtopic"));
+}
+
function getControls(): HTMLElement | false {
const controlsSelectors = [
// YouTube
@@ -1552,7 +1562,8 @@ async function sendSubmitMessage() {
videoID: sponsorVideoID,
userID: Config.config.userID,
segments: sponsorTimesSubmitting,
- videoDuration: video?.duration
+ videoDuration: video?.duration,
+ userAgent: `${chrome.runtime.id}/v${chrome.runtime.getManifest().version}`
});
if (response.status === 200) {
diff --git a/src/js-components/chat.ts b/src/js-components/chat.ts
index 4bbb4a2b..bb7028d2 100644
--- a/src/js-components/chat.ts
+++ b/src/js-components/chat.ts
@@ -34,11 +34,12 @@ export async function openWarningChat(warningMessage: string): Promise<void> {
const userNameData = await utils.asyncRequestToServer("GET", "/api/getUsername?userID=" + Config.config.userID);
const userName = userNameData.ok ? JSON.parse(userNameData.responseText).userName : "";
const publicUserID = await utils.getHash(Config.config.userID);
+ const warningReasonMatch = warningMessage.match(/Warning reason: '(.+)'/);
openChat({
- displayName: `${userName ? `${userName} | `: ``}${userName !== publicUserID ? publicUserID : ``}`,
- composerInitialValue: `I got a warning and want to know what I need to do to improve. ` +
- `Warning reason: ${warningMessage.match(/Warning reason: '(.+)'/)[1]}`,
+ displayName: `${userName ? userName : ``}${userName !== publicUserID ? ` | ${publicUserID}` : ``}`,
+ composerInitialValue: `I got a warning and want to know what I need to do to improve.` +
+ warningReasonMatch ? ` Warning reason: ${warningReasonMatch[1]}` : ``,
customDescription: chrome.i18n.getMessage("warningChatInfo")
});
} \ No newline at end of file
diff --git a/src/messageTypes.ts b/src/messageTypes.ts
index 9e0da461..49a5ad92 100644
--- a/src/messageTypes.ts
+++ b/src/messageTypes.ts
@@ -12,7 +12,6 @@ interface DefaultMessage {
message:
"update"
| "sponsorStart"
- | "isInfoFound"
| "getVideoID"
| "getChannelID"
| "isChannelWhitelisted"
@@ -25,7 +24,12 @@ interface BoolValueMessage {
value: boolean;
}
-export type Message = BaseMessage & (DefaultMessage | BoolValueMessage);
+interface IsInfoFoundMessage {
+ message: "isInfoFound";
+ updating: boolean;
+}
+
+export type Message = BaseMessage & (DefaultMessage | BoolValueMessage | IsInfoFoundMessage);
interface IsInfoFoundMessageResponse {
found: boolean;
diff --git a/src/options.ts b/src/options.ts
index 50436b4f..ee04f1a5 100644
--- a/src/options.ts
+++ b/src/options.ts
@@ -492,6 +492,22 @@ function activatePrivateTextChange(element: HTMLElement) {
}
});
+ // See if anything extra must be done
+ switch (option) {
+ case "userID":
+ utils.asyncRequestToServer("GET", "/api/userInfo", {
+ userID: Config.config[option],
+ values: ["warnings", "banned"]
+ }).then((result) => {
+ const userInfo = JSON.parse(result.responseText);
+ if (userInfo.warnings > 0 || userInfo.banned) {
+ setButton.classList.add("hidden");
+ }
+ });
+
+ break;
+ }
+
element.querySelector(".option-hidden-section").classList.remove("hidden");
}
diff --git a/src/popup.ts b/src/popup.ts
index b5ca8235..092b7db2 100644
--- a/src/popup.ts
+++ b/src/popup.ts
@@ -234,19 +234,15 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
// Must be delayed so it only happens once loaded
setTimeout(() => PageElements.sponsorblockPopup.classList.remove("preload"), 250);
- messageHandler.query({
- active: true,
- currentWindow: true
- }, onTabs);
+ getSegmentsFromContentScript(false);
- function onTabs(tabs) {
+ function onTabs(tabs, updating: boolean): void {
messageHandler.sendMessage(tabs[0].id, {message: 'getVideoID'}, function(result) {
- console.log(result)
if (result !== undefined && result.videoID) {
currentVideoID = result.videoID;
creatingSegment = result.creatingSegment;
- loadTabData(tabs);
+ loadTabData(tabs, updating);
} else if (result === undefined && chrome.runtime.lastError) {
//this isn't a YouTube video then, or at least the content script is not loaded
displayNoVideo();
@@ -254,29 +250,30 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
});
}
- function loadTabData(tabs) {
+ function loadTabData(tabs, updating: boolean): void {
if (!currentVideoID) {
//this isn't a YouTube video then
displayNoVideo();
return;
}
- //load video times for this video
- const sponsorTimesStorage = Config.config.segmentTimes.get(currentVideoID);
- if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) {
- sponsorTimes = sponsorTimesStorage;
- }
-
+ sponsorTimes = Config.config.segmentTimes.get(currentVideoID) ?? [];
updateSegmentEditingUI();
- //check if this video's sponsors are known
messageHandler.sendMessage(
tabs[0].id,
- {message: 'isInfoFound'},
+ {message: 'isInfoFound', updating},
infoFound
);
}
+ function getSegmentsFromContentScript(updating: boolean): void {
+ messageHandler.query({
+ active: true,
+ currentWindow: true
+ }, (tabs) => onTabs(tabs, updating));
+ }
+
function infoFound(request: {found: boolean, sponsorTimes: SponsorTime[]}) {
if(chrome.runtime.lastError) {
//This page doesn't have the injected content script, or at least not yet
@@ -369,7 +366,6 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
//display the video times from the array at the top, in a different section
function displayDownloadedSponsorTimes(request: {found: boolean, sponsorTimes: SponsorTime[]}) {
if (request.sponsorTimes != undefined) {
-
// Sort list by start time
const segmentTimes = request.sponsorTimes
.sort((a, b) => a.segment[1] - b.segment[1])
@@ -377,6 +373,10 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
//add them as buttons to the issue reporting container
const container = document.getElementById("issueReporterTimeButtons");
+ while (container.firstChild) {
+ container.removeChild(container.firstChild);
+ }
+
for (let i = 0; i < segmentTimes.length; i++) {
const UUID = segmentTimes[i].UUID;
@@ -695,7 +695,10 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
messageHandler.sendMessage(
tabs[0].id,
{message: 'refreshSegments'},
- () => stopAnimation()
+ (response) => {
+ infoFound(response);
+ stopAnimation();
+ }
)}
);
}
diff --git a/src/utils.ts b/src/utils.ts
index 6d7e6e89..29a8ef38 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -438,6 +438,8 @@ export default class Utils {
}
getFormattedTime(seconds: number, precise?: boolean): string {
+ seconds = Math.max(seconds, 0);
+
const hours = Math.floor(seconds / 60 / 60);
const minutes = Math.floor(seconds / 60) % 60;
let minutesDisplay = String(minutes);