diff options
author | Michael C <[email protected]> | 2022-01-26 17:54:58 -0500 |
---|---|---|
committer | Michael C <[email protected]> | 2022-01-26 17:54:58 -0500 |
commit | 9457aff44f7a6d42ad9be47254ae882c8fe4a686 (patch) | |
tree | 7412a2e38baa70238c1b6ddb1cb126910378851a | |
parent | 193374db30b93cb2fe015680df9c82e5215c8fdd (diff) | |
download | SponsorBlock-9457aff44f7a6d42ad9be47254ae882c8fe4a686.tar.gz SponsorBlock-9457aff44f7a6d42ad9be47254ae882c8fe4a686.zip |
linting + audio override
-rw-r--r-- | package-lock.json | 17 | ||||
-rw-r--r-- | package.json | 3 | ||||
-rw-r--r-- | src/content.ts | 28 | ||||
-rw-r--r-- | webpack/webpack.common.js | 5 |
4 files changed, 35 insertions, 18 deletions
diff --git a/package-lock.json b/package-lock.json index 9788d111..76f339c0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,10 +21,11 @@ "react-dom": "^17.0.2" }, "devDependencies": { - "@types/chrome": "0.0.91", + "@types/chrome": "^0.0.91", "@types/firefox-webext-browser": "70.0.1", "@types/jest": "^24.0.23", "@types/jquery": "^3.3.31", + "@types/wicg-mediasession": "^1.1.3", "@typescript-eslint/eslint-plugin": "^4.9.1", "@typescript-eslint/parser": "^4.9.1", "chromedriver": "^92.0.0", @@ -1890,6 +1891,7 @@ }, "node_modules/@types/chrome": { "version": "0.0.91", + "resolved": "https://registry.npmjs.org/@types/chrome/-/chrome-0.0.91.tgz", "integrity": "sha512-vNvo9lJkp1AvViWrUwe1bxhoMwr5dRZWlgr1DTuaNkz97LsG56lDX1sceWeZir2gRACJ5vdHtoRdVAvm8C75Ug==", "dev": true, "dependencies": { @@ -2043,6 +2045,12 @@ "integrity": "sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==", "dev": true }, + "node_modules/@types/wicg-mediasession": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@types/wicg-mediasession/-/wicg-mediasession-1.1.3.tgz", + "integrity": "sha512-lzoszzJJfW9vcaIxf6tDx3lCJq/4oaD+mplA7sCV7W21PGdR6yUPwErN047ziIcwFx61w8WMURIwUyj1V7KJIQ==", + "dev": true + }, "node_modules/@types/yargs": { "version": "13.0.7", "integrity": "sha512-Sg9kNeJz+V+W+0fugcVhHC+mNHnydDR1RJrW5Qn2jVrDQARF8wfPVqIqwEzZp+bneuEBIm2ClsJ1/je42ZBzSg==", @@ -20389,6 +20397,7 @@ }, "@types/chrome": { "version": "0.0.91", + "resolved": "https://registry.npmjs.org/@types/chrome/-/chrome-0.0.91.tgz", "integrity": "sha512-vNvo9lJkp1AvViWrUwe1bxhoMwr5dRZWlgr1DTuaNkz97LsG56lDX1sceWeZir2gRACJ5vdHtoRdVAvm8C75Ug==", "dev": true, "requires": { @@ -20542,6 +20551,12 @@ "integrity": "sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==", "dev": true }, + "@types/wicg-mediasession": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@types/wicg-mediasession/-/wicg-mediasession-1.1.3.tgz", + "integrity": "sha512-lzoszzJJfW9vcaIxf6tDx3lCJq/4oaD+mplA7sCV7W21PGdR6yUPwErN047ziIcwFx61w8WMURIwUyj1V7KJIQ==", + "dev": true + }, "@types/yargs": { "version": "13.0.7", "integrity": "sha512-Sg9kNeJz+V+W+0fugcVhHC+mNHnydDR1RJrW5Qn2jVrDQARF8wfPVqIqwEzZp+bneuEBIm2ClsJ1/je42ZBzSg==", diff --git a/package.json b/package.json index 3801193a..d897a13d 100644 --- a/package.json +++ b/package.json @@ -16,10 +16,11 @@ "react-dom": "^17.0.2" }, "devDependencies": { - "@types/chrome": "0.0.91", + "@types/chrome": "^0.0.91", "@types/firefox-webext-browser": "70.0.1", "@types/jest": "^24.0.23", "@types/jquery": "^3.3.31", + "@types/wicg-mediasession": "^1.1.3", "@typescript-eslint/eslint-plugin": "^4.9.1", "@typescript-eslint/parser": "^4.9.1", "chromedriver": "^92.0.0", diff --git a/src/content.ts b/src/content.ts index b321df38..00ac6034 100644 --- a/src/content.ts +++ b/src/content.ts @@ -682,17 +682,14 @@ async function sponsorsLookup(id: string, keepOldSubmissions = true) { setupVideoMutationListener(); // Create categories list - const categories: string[] = []; - for (const categorySelection of Config.config.categorySelections) { - categories.push(categorySelection.name); - } + const categories: string[] = Config.config.categorySelections.map((category) => category.name); const extraRequestData: Record<string, unknown> = {}; const hashParams = getHashParams(); if (hashParams.requiredSegment) extraRequestData.requiredSegment = hashParams.requiredSegment; // Check for hashPrefix setting - const hashPrefix = (await utils.getHash(id, 1)).substr(0, 4); + const hashPrefix = (await utils.getHash(id, 1)).slice(0, 4); const response = await utils.asyncRequestToServer('GET', "/api/skipSegments/" + hashPrefix, { categories, actionTypes: getEnabledActionTypes(), @@ -727,11 +724,10 @@ async function sponsorsLookup(id: string, keepOldSubmissions = true) { // Hide all submissions smaller than the minimum duration if (Config.config.minDuration !== 0) { - for (let i = 0; i < sponsorTimes.length; i++) { - if (sponsorTimes[i].segment[1] - sponsorTimes[i].segment[0] < Config.config.minDuration - && sponsorTimes[i].actionType !== ActionType.Poi) { - sponsorTimes[i].hidden = SponsorHideType.MinimumDuration; - } + for (const segment of sponsorTimes) { + if (segment.segment[1] - segment.segment[0] < Config.config.minDuration + && segment.actionType !== ActionType.Poi) + segment.hidden = SponsorHideType.MinimumDuration; } } @@ -808,7 +804,7 @@ async function updateVipInfo(): Promise<boolean> { } async function lockedCategoriesLookup(id: string): Promise<void> { - const hashPrefix = (await utils.getHash(id, 1)).substr(0, 4); + const hashPrefix = (await utils.getHash(id, 1)).slice(0, 4); const response = await utils.asyncRequestToServer("GET", "/api/lockCategories/" + hashPrefix); if (response.ok) { @@ -971,8 +967,7 @@ function getYouTubeVideoIDFromURL(url: string): string | boolean { return id.length == 11 ? id : false; } else if (urlObject.pathname.startsWith("/embed/") || urlObject.pathname.startsWith("/shorts/")) { try { - const id = urlObject.pathname.split("/")[2]; - if (id && id.length >= 11) return id.substr(0, 11); + return urlObject.pathname.split("/")[2].slice(0, 11); } catch (e) { console.error("[SB] Video ID not valid for " + url); return false; @@ -1044,7 +1039,8 @@ async function whitelistCheck() { const getChannelID = () => videoInfo?.videoDetails?.channelId ?? document.querySelector(".ytd-channel-name a")?.getAttribute("href")?.replace(/\/.+\//, "") // YouTube ?? document.querySelector(".ytp-title-channel-logo")?.getAttribute("href")?.replace(/https:\/.+\//, "") // YouTube Embed - ?? document.querySelector("a > .channel-profile")?.parentElement?.getAttribute("href")?.replace(/\/.+\//, ""); // Invidious + ?? document.querySelector("a > .channel-profile")?.parentElement?.getAttribute("href")?.replace(/\/.+\//, "") // Invidious + ?? document.querySelector("a.slim-owner-icon-and-title")?.getAttribute("href")?.replace(/\/.+\//, ""); // Mobile YouTube try { await utils.wait(() => !!getChannelID(), 6000, 20); @@ -1277,6 +1273,10 @@ function skipToTime({v, skipTime, skippingSegments, openNotice, forceAutoSkip, u const beep = new Audio(chrome.runtime.getURL("icons/beep.ogg")); beep.volume = video.volume * 0.1; beep.play(); + beep.controls = false; + // hijack media function + navigator.mediaSession.setActionHandler('play', () => video.play()) + navigator.mediaSession.setActionHandler("pause", () => video.pause()) } if (!autoSkip diff --git a/webpack/webpack.common.js b/webpack/webpack.common.js index cacb07ba..6e0dd56f 100644 --- a/webpack/webpack.common.js +++ b/webpack/webpack.common.js @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ const webpack = require("webpack"); const path = require('path'); const CopyPlugin = require('copy-webpack-plugin'); @@ -84,12 +85,12 @@ module.exports = env => ({ if (env.browser.toLowerCase() === "safari") { parsed.fullName.message = parsed.fullName.message.match(/^.+(?= -)/)?.[0] || parsed.fullName.message; if (parsed.fullName.message.length > 50) { - parsed.fullName.message = parsed.fullName.message.substr(0, 47) + "..."; + parsed.fullName.message = parsed.fullName.message.slice(0, 47) + "..."; } parsed.Description.message = parsed.Description.message.match(/^.+(?=\. )/)?.[0] || parsed.Description.message; if (parsed.Description.message.length > 80) { - parsed.Description.message = parsed.Description.message.substr(0, 77) + "..."; + parsed.Description.message = parsed.Description.message.slice(0, 77) + "..."; } } |