From d010555bb2320d8ece83f6164c5af2b0b98beaea Mon Sep 17 00:00:00 2001 From: hanyd Date: Thu, 5 Dec 2024 13:03:33 +0800 Subject: [PATCH 01/19] update category name and description --- public/_locales/en/messages.json | 6 +++--- public/_locales/zh_CN/messages.json | 6 +++--- public/_locales/zh_TW/messages.json | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/public/_locales/en/messages.json b/public/_locales/en/messages.json index ccb95f3f..ed033741 100644 --- a/public/_locales/en/messages.json +++ b/public/_locales/en/messages.json @@ -579,7 +579,7 @@ "message": "跳过后的视频仍然流畅,就好像跳过的片段不存在一样" }, "category_sponsor": { - "message": "赞助广告" + "message": "广告" }, "category_sponsor_description": { "message": "付费推广、付费推荐和直接广告。不是自我推广或免费提及他们喜欢的商品/创作者/网站/产品。" @@ -606,13 +606,13 @@ "message": "不是公司设计的产品和周边" }, "category_exclusive_access": { - "message": "品牌合作" + "message": "柔性推广/品牌合作" }, "category_exclusive_access_description": { "message": "仅用于对整个视频进行标记。适用于展示UP主免费或获得补贴后使用的产品、服务或场地的视频。" }, "category_exclusive_access_pill": { - "message": "此视频展示了UP主免费或获得后补贴使用的产品、服务或场地", + "message": "此视频展示了UP主免费或获得后补贴使用的产品或者服务,包括软广、产品推广或者品牌推广", "description": "此类别的简短描述" }, "category_exclusive_access_guideline1": { diff --git a/public/_locales/zh_CN/messages.json b/public/_locales/zh_CN/messages.json index ccb95f3f..ed033741 100644 --- a/public/_locales/zh_CN/messages.json +++ b/public/_locales/zh_CN/messages.json @@ -579,7 +579,7 @@ "message": "跳过后的视频仍然流畅,就好像跳过的片段不存在一样" }, "category_sponsor": { - "message": "赞助广告" + "message": "广告" }, "category_sponsor_description": { "message": "付费推广、付费推荐和直接广告。不是自我推广或免费提及他们喜欢的商品/创作者/网站/产品。" @@ -606,13 +606,13 @@ "message": "不是公司设计的产品和周边" }, "category_exclusive_access": { - "message": "品牌合作" + "message": "柔性推广/品牌合作" }, "category_exclusive_access_description": { "message": "仅用于对整个视频进行标记。适用于展示UP主免费或获得补贴后使用的产品、服务或场地的视频。" }, "category_exclusive_access_pill": { - "message": "此视频展示了UP主免费或获得后补贴使用的产品、服务或场地", + "message": "此视频展示了UP主免费或获得后补贴使用的产品或者服务,包括软广、产品推广或者品牌推广", "description": "此类别的简短描述" }, "category_exclusive_access_guideline1": { diff --git a/public/_locales/zh_TW/messages.json b/public/_locales/zh_TW/messages.json index fd36dbff..69fcb567 100644 --- a/public/_locales/zh_TW/messages.json +++ b/public/_locales/zh_TW/messages.json @@ -579,7 +579,7 @@ "message": "跳過後的影片仍然流暢,就好像跳過的片段不存在一樣" }, "category_sponsor": { - "message": "贊助廣告" + "message": "廣告" }, "category_sponsor_description": { "message": "付費推廣、付費推薦和直接廣告。不是自我推廣或免費提及他們喜歡的商品/創作者/網站/產品。" @@ -606,10 +606,10 @@ "message": "不是公司設計的產品和周邊" }, "category_exclusive_access": { - "message": "品牌合作" + "message": "柔性推廣/品牌合作" }, "category_exclusive_access_description": { - "message": "僅用於標記整個影片。適用於影片展示創作者免費或獲得補助使用的產品、服務或場地。" + "message": "僅用於標記整個影片。適用於影片展示創作者免費或獲得補助使用的產品或者服務,包括軟廣、產品推廣或者品牌推廣。" }, "category_exclusive_access_pill": { "message": "此影片展示了創作者免費或獲得補助使用的產品、服務或場地", From e9d82962a5581bc7031eaa91d6205136b08918f1 Mon Sep 17 00:00:00 2001 From: hanyd Date: Thu, 5 Dec 2024 17:09:04 +0800 Subject: [PATCH 02/19] fix skip to highlight button --- public/content.css | 10 +---- src/content.ts | 8 ++-- src/js-components/skipButtonControlBar.ts | 50 +++++++++++++---------- 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/public/content.css b/public/content.css index 01bf18f2..4559717c 100644 --- a/public/content.css +++ b/public/content.css @@ -33,7 +33,7 @@ width: 100%; height: 100%; z-index: 1; - + transition: transform 0.1s cubic-bezier(0, 0, 0.2, 1); } @@ -655,14 +655,6 @@ input::-webkit-inner-spin-button { display: none !important; } -#sbSkipIconControlBarImage { - height: 60%; - top: 0px; - bottom: 0px; - display: block; - margin: auto; -} - .sponsorBlockTooltip { position: absolute; background-color: rgba(28, 28, 28, 0.7); diff --git a/src/content.ts b/src/content.ts index e8ede1af..89be6d56 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1566,9 +1566,11 @@ function videoElementChange(newVideo: boolean): void { waitFor(() => Config.isReady() && !document.hidden, 24 * 60 * 60, 500).then(() => { if (newVideo) { setupVideoListeners(); - setupSkipButtonControlBar(); - setupCategoryPill(); - setupDescriptionPill(); + waitFor(getPageLoaded, 20000, 10).then(() => { + setupSkipButtonControlBar(); + setupCategoryPill(); + setupDescriptionPill(); + }); } updatePreviewBar(); diff --git a/src/js-components/skipButtonControlBar.ts b/src/js-components/skipButtonControlBar.ts index 88352c58..b1e4e270 100644 --- a/src/js-components/skipButtonControlBar.ts +++ b/src/js-components/skipButtonControlBar.ts @@ -1,8 +1,10 @@ import Config from "../config"; +import { keybindToString } from "../config/config"; +import { getPageLoaded } from "../content"; import { SegmentUUID, SponsorTime } from "../types"; -import { getSkippingText } from "../utils/categoryUtils"; import { AnimationUtils } from "../utils/animationUtils"; -import { keybindToString } from "../config/config"; +import { getSkippingText } from "../utils/categoryUtils"; +import { waitFor } from "../utils/index"; export interface SkipButtonControlBarProps { skip: (segment: SponsorTime) => void; @@ -12,8 +14,8 @@ export interface SkipButtonControlBarProps { export class SkipButtonControlBar { container: HTMLElement; skipIcon: HTMLImageElement; - textContainer: HTMLElement; - chapterText: HTMLElement; + // textContainer: HTMLElement; + // chapterText: HTMLElement; segment: SponsorTime; showKeybindHint = true; @@ -30,17 +32,22 @@ export class SkipButtonControlBar { this.container = document.createElement("div"); this.container.classList.add("skipButtonControlBarContainer"); - this.container.classList.add("sbhidden"); + // this.container.classList.add("sbhidden"); + + const button = document.createElement("button"); + button.classList.add("bpx-player-ctrl-btn", "playerButton"); + button.id = "sbSkipIconControlBarButton"; this.skipIcon = document.createElement("img"); this.skipIcon.src = chrome.runtime.getURL("icons/skipIcon.svg"); - this.skipIcon.classList.add("ytp-button"); + this.skipIcon.classList.add("bpx-player-ctrl-btn-icon", "playerButtonImage"); this.skipIcon.id = "sbSkipIconControlBarImage"; - this.textContainer = document.createElement("div"); + // this.textContainer = document.createElement("div"); - this.container.appendChild(this.skipIcon); - this.container.appendChild(this.textContainer); + button.appendChild(this.skipIcon); + this.container.appendChild(button); + // this.container.appendChild(this.textContainer); this.container.addEventListener("click", () => this.toggleSkip()); this.container.addEventListener("mouseenter", () => { this.stopTimer(); @@ -60,18 +67,19 @@ export class SkipButtonControlBar { return this.container; } - attachToPage(): void { + async attachToPage(): Promise { + await waitFor(getPageLoaded, 10000, 10); const mountingContainer = this.getMountingContainer(); - this.chapterText = document.querySelector(".ytp-chapter-container"); + // this.chapterText = document.querySelector(".ytp-chapter-container"); if (mountingContainer && !mountingContainer.contains(this.container)) { - mountingContainer.insertBefore(this.container, this.chapterText); - AnimationUtils.setupAutoHideAnimation(this.skipIcon, mountingContainer, false, false); + mountingContainer.append(this.container); + AnimationUtils.setupAutoHideAnimation(this.skipIcon, mountingContainer, true, false); } } private getMountingContainer(): HTMLElement { - return document.querySelector(".ytp-left-controls"); + return document.querySelector(".bpx-player-control-bottom-left"); } enable(segment: SponsorTime, duration?: number): void { @@ -81,7 +89,7 @@ export class SkipButtonControlBar { this.refreshText(); this.container?.classList?.remove("textDisabled"); - this.textContainer?.classList?.remove("sbhidden"); + // this.textContainer?.classList?.remove("sbhidden"); AnimationUtils.disableAutoHideAnimation(this.skipIcon); this.startTimer(); @@ -89,9 +97,9 @@ export class SkipButtonControlBar { refreshText(): void { if (this.segment) { - this.chapterText?.classList?.add("sbhidden"); + // this.chapterText?.classList?.add("sbhidden"); this.container.classList.remove("sbhidden"); - this.textContainer.innerText = this.getTitle(); + // this.textContainer.innerText = this.getTitle(); this.skipIcon.setAttribute("title", this.getTitle()); } } @@ -117,8 +125,8 @@ export class SkipButtonControlBar { disable(): void { this.container.classList.add("sbhidden"); - this.chapterText?.classList?.remove("sbhidden"); - this.getChapterPrefix()?.classList?.remove("sbhidden"); + // this.chapterText?.classList?.remove("sbhidden"); + // this.getChapterPrefix()?.classList?.remove("sbhidden"); this.enabled = false; } @@ -141,8 +149,8 @@ export class SkipButtonControlBar { } this.container.classList.add("textDisabled"); - this.textContainer?.classList?.add("sbhidden"); - this.chapterText?.classList?.remove("sbhidden"); + // this.textContainer?.classList?.add("sbhidden"); + // this.chapterText?.classList?.remove("sbhidden"); this.getChapterPrefix()?.classList?.add("sbhidden"); From bfe799401fd11c0ca1cdd046e8de26145a818581 Mon Sep 17 00:00:00 2001 From: hanyd Date: Thu, 5 Dec 2024 18:56:25 +0800 Subject: [PATCH 03/19] Get framerate from window object --- src/document.ts | 31 ++++++++++++++++++------------- src/document/frameRateUtils.ts | 28 ++++++++++++++++++++++++++++ src/globals.d.ts | 9 ++++++++- 3 files changed, 54 insertions(+), 14 deletions(-) create mode 100644 src/document/frameRateUtils.ts diff --git a/src/document.ts b/src/document.ts index 5e64e7ae..7c3c08c0 100644 --- a/src/document.ts +++ b/src/document.ts @@ -1,3 +1,4 @@ +import { getFrameRate } from "./document/frameRateUtils"; import { InjectedScriptMessageSend, sourceId } from "./utils/injectedScriptMessageUtils"; const sendMessageToContent = (messageData: InjectedScriptMessageSend, payload): void => { @@ -11,26 +12,28 @@ const sendMessageToContent = (messageData: InjectedScriptMessageSend, payload): "/" ); }; -let frameRate: number = 30; -(function () { +let frameRate: number; +function overwriteFetch() { const originalFetch = window.fetch; window.fetch = async function (input, init) { - const url = typeof input === 'string' ? input : (input as Request).url; - + const url = typeof input === "string" ? input : (input as Request).url; const response = await originalFetch(input, init); - if (url.includes('/player/wbi/playurl') && url.includes(window.__INITIAL_STATE__.cid.toString())) { - response.clone().json().then(data => { - frameRate = data.data.dash.video - .filter((v) => v.id === data.data.quality && v.codecid === data.data.video_codecid)[0]?.frameRate; - }).catch(() => { - frameRate = 30; - }); + + if (url.includes("/player/wbi/playurl") && url.includes(window?.__INITIAL_STATE__?.cid.toString())) { + response + .clone() + .json() + .then((data) => { + frameRate = data.data.dash.video.filter( + (v) => v.id === data.data.quality && v.codecid === data.data.video_codecid + )[0]?.frameRate; + }); } return response; }; -})(); +} function windowMessageListener(message: MessageEvent) { const data: InjectedScriptMessageSend = message.data; @@ -41,7 +44,8 @@ function windowMessageListener(message: MessageEvent) { if (data.type === "getBvID") { sendMessageToContent(data, window?.__INITIAL_STATE__?.bvid); } else if (data.type === "getFrameRate") { - sendMessageToContent(data, frameRate); + console.log("Frame rate", getFrameRate()); + sendMessageToContent(data, getFrameRate()); } else if (data.type === "getChannelID") { sendMessageToContent(data, window?.__INITIAL_STATE__?.upData?.mid); } else if (data.type === "getDescription") { @@ -52,6 +56,7 @@ function windowMessageListener(message: MessageEvent) { function init(): void { window.addEventListener("message", windowMessageListener); + overwriteFetch(); } init(); diff --git a/src/document/frameRateUtils.ts b/src/document/frameRateUtils.ts new file mode 100644 index 00000000..f8954aa0 --- /dev/null +++ b/src/document/frameRateUtils.ts @@ -0,0 +1,28 @@ +interface PlayInfo { + id: number; + frameRate: number; +} + +export function getPlayInfo(): PlayInfo[] { + if (window.__playinfo__?.data?.dash?.video) { + return window.__playinfo__.data.dash.video.map((v) => ({ id: v.id, frameRate: parseFloat(v.frameRate) })); + } + return []; +} + +export function getFrameRate() { + let currentQuality = null; + try { + currentQuality ||= JSON.parse(window?.localStorage?.bpx_player_profile)?.media?.quality; + } catch (e) { + console.debug("Failed to get current quality", e); + } + currentQuality = currentQuality ?? window?.__playinfo__?.data?.quality; + + const possibleQuality = getPlayInfo().filter((v) => v.id === currentQuality && !!v.frameRate); + + if (possibleQuality.length > 0) { + return possibleQuality[0].frameRate; + } + return 30; +} diff --git a/src/globals.d.ts b/src/globals.d.ts index f19d69ae..07f54bc5 100644 --- a/src/globals.d.ts +++ b/src/globals.d.ts @@ -2,6 +2,13 @@ import SBObject from "./config"; declare global { interface Window { SB: typeof SBObject; - __INITIAL_STATE__?: { bvid: string; aid: number; cid: number; upData: { mid: string }; videoData: { desc: string }}; + __INITIAL_STATE__?: { + bvid: string; + aid: number; + cid: number; + upData: { mid: string }; + videoData: { desc: string }; + }; + __playinfo__?: { data: { quality: number; dash: { video: { id: number; frameRate: string }[] } } }; } } From c1832871a713a5206d793bf31cf13317a141072b Mon Sep 17 00:00:00 2001 From: hanyd Date: Thu, 5 Dec 2024 19:10:50 +0800 Subject: [PATCH 04/19] update fetch overwrite --- src/document.ts | 32 ++++++++++++++++++-------------- src/document/frameRateUtils.ts | 2 +- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/document.ts b/src/document.ts index 7c3c08c0..7d16f622 100644 --- a/src/document.ts +++ b/src/document.ts @@ -1,6 +1,9 @@ -import { getFrameRate } from "./document/frameRateUtils"; +import { getFrameRate, PlayInfo } from "./document/frameRateUtils"; +import { DataCache } from "./utils/cache"; import { InjectedScriptMessageSend, sourceId } from "./utils/injectedScriptMessageUtils"; +const cache = new DataCache(() => []); + const sendMessageToContent = (messageData: InjectedScriptMessageSend, payload): void => { window.postMessage( { @@ -13,24 +16,25 @@ const sendMessageToContent = (messageData: InjectedScriptMessageSend, payload): ); }; -let frameRate: number; function overwriteFetch() { const originalFetch = window.fetch; window.fetch = async function (input, init) { - const url = typeof input === "string" ? input : (input as Request).url; + const urlStr = typeof input === "string" ? input : (input as Request).url; const response = await originalFetch(input, init); - - if (url.includes("/player/wbi/playurl") && url.includes(window?.__INITIAL_STATE__?.cid.toString())) { - response - .clone() - .json() - .then((data) => { - frameRate = data.data.dash.video.filter( - (v) => v.id === data.data.quality && v.codecid === data.data.video_codecid - )[0]?.frameRate; - }); - } + response + .clone() + .json() + .then((res) => { + const url = new URL(urlStr); + if (url.pathname.includes("/player/wbi/playurl")) { + const cid = url.searchParams.get("cid"); + if (!cache.getFromCache(cid) && res?.data?.dash?.video) { + cache.setupCache(cid).push(...res.data.dash.video); + } + } + }) + .catch(() => {}); return response; }; } diff --git a/src/document/frameRateUtils.ts b/src/document/frameRateUtils.ts index f8954aa0..e51e1ccc 100644 --- a/src/document/frameRateUtils.ts +++ b/src/document/frameRateUtils.ts @@ -1,4 +1,4 @@ -interface PlayInfo { +export interface PlayInfo { id: number; frameRate: number; } From 6de7d3aaa455bc65096d863150b4d85cf5e55126 Mon Sep 17 00:00:00 2001 From: hanyd Date: Thu, 5 Dec 2024 19:15:55 +0800 Subject: [PATCH 05/19] fix option page reactive layout --- public/options/options.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/options/options.css b/public/options/options.css index a55b043d..c5fe7b61 100644 --- a/public/options/options.css +++ b/public/options/options.css @@ -98,7 +98,7 @@ body { #navigation { display: flex; flex-direction: column; - gap: 25px; + gap: 20px; } .tab-heading { @@ -655,7 +655,7 @@ svg { } /* Top bar navigation for smaller screens */ -@media only screen and (max-height: 750px), only screen and (max-width: 1200px) { +@media only screen and (max-height: 765px), only screen and (max-width: 1200px) { #options-container { flex-direction: column; } From 5f3209e4006b52123b247057ff130e2ef44da5b1 Mon Sep 17 00:00:00 2001 From: hanyd Date: Thu, 5 Dec 2024 19:20:59 +0800 Subject: [PATCH 06/19] supplement play info with request cache --- src/document.ts | 14 +++++++++----- src/document/frameRateUtils.ts | 10 +++++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/document.ts b/src/document.ts index 7d16f622..3dab45b0 100644 --- a/src/document.ts +++ b/src/document.ts @@ -2,7 +2,7 @@ import { getFrameRate, PlayInfo } from "./document/frameRateUtils"; import { DataCache } from "./utils/cache"; import { InjectedScriptMessageSend, sourceId } from "./utils/injectedScriptMessageUtils"; -const cache = new DataCache(() => []); +const playInfoCache = new DataCache(() => []); const sendMessageToContent = (messageData: InjectedScriptMessageSend, payload): void => { window.postMessage( @@ -29,8 +29,13 @@ function overwriteFetch() { const url = new URL(urlStr); if (url.pathname.includes("/player/wbi/playurl")) { const cid = url.searchParams.get("cid"); - if (!cache.getFromCache(cid) && res?.data?.dash?.video) { - cache.setupCache(cid).push(...res.data.dash.video); + if (!playInfoCache.getFromCache(cid) && res?.data?.dash?.video) { + playInfoCache.setupCache(cid).push( + ...res.data.dash.video.map((v) => ({ + id: v.id, + frameRate: parseFloat(v.frameRate), + })) + ); } } }) @@ -48,8 +53,7 @@ function windowMessageListener(message: MessageEvent) { if (data.type === "getBvID") { sendMessageToContent(data, window?.__INITIAL_STATE__?.bvid); } else if (data.type === "getFrameRate") { - console.log("Frame rate", getFrameRate()); - sendMessageToContent(data, getFrameRate()); + sendMessageToContent(data, getFrameRate(playInfoCache)); } else if (data.type === "getChannelID") { sendMessageToContent(data, window?.__INITIAL_STATE__?.upData?.mid); } else if (data.type === "getDescription") { diff --git a/src/document/frameRateUtils.ts b/src/document/frameRateUtils.ts index e51e1ccc..18efedf7 100644 --- a/src/document/frameRateUtils.ts +++ b/src/document/frameRateUtils.ts @@ -1,16 +1,20 @@ +import { DataCache } from "../utils/cache"; + export interface PlayInfo { id: number; frameRate: number; } -export function getPlayInfo(): PlayInfo[] { +export function getPlayInfo(playInfoCache: DataCache): PlayInfo[] { if (window.__playinfo__?.data?.dash?.video) { return window.__playinfo__.data.dash.video.map((v) => ({ id: v.id, frameRate: parseFloat(v.frameRate) })); + } else if (playInfoCache.getFromCache(window?.__INITIAL_STATE__?.cid.toString())) { + return playInfoCache.getFromCache(window.__INITIAL_STATE__.cid.toString()); } return []; } -export function getFrameRate() { +export function getFrameRate(playInfoCache: DataCache) { let currentQuality = null; try { currentQuality ||= JSON.parse(window?.localStorage?.bpx_player_profile)?.media?.quality; @@ -19,7 +23,7 @@ export function getFrameRate() { } currentQuality = currentQuality ?? window?.__playinfo__?.data?.quality; - const possibleQuality = getPlayInfo().filter((v) => v.id === currentQuality && !!v.frameRate); + const possibleQuality = getPlayInfo(playInfoCache).filter((v) => v.id === currentQuality && !!v.frameRate); if (possibleQuality.length > 0) { return possibleQuality[0].frameRate; From 7371f72d52d1fcb8db212402bdb57eef33bce8a9 Mon Sep 17 00:00:00 2001 From: hanyd Date: Thu, 5 Dec 2024 19:24:19 +0800 Subject: [PATCH 07/19] simpler cache --- src/document.ts | 8 +++----- src/utils/cache.ts | 29 ++++++++++++++++++----------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/document.ts b/src/document.ts index 3dab45b0..1220bfd9 100644 --- a/src/document.ts +++ b/src/document.ts @@ -30,11 +30,9 @@ function overwriteFetch() { if (url.pathname.includes("/player/wbi/playurl")) { const cid = url.searchParams.get("cid"); if (!playInfoCache.getFromCache(cid) && res?.data?.dash?.video) { - playInfoCache.setupCache(cid).push( - ...res.data.dash.video.map((v) => ({ - id: v.id, - frameRate: parseFloat(v.frameRate), - })) + playInfoCache.set( + cid, + res.data.dash.video.map((v) => ({ id: v.id, frameRate: parseFloat(v.frameRate) })) ); } } diff --git a/src/utils/cache.ts b/src/utils/cache.ts index ea2c1075..d4c851e3 100644 --- a/src/utils/cache.ts +++ b/src/utils/cache.ts @@ -7,7 +7,7 @@ export class DataCache { private init: () => V; private cacheLimit: number; - constructor(init: () => V, cacheLimit = 2000) { + constructor(init?: () => V, cacheLimit = 2000) { this.cache = {}; this.init = init; this.cacheLimit = cacheLimit; @@ -17,17 +17,17 @@ export class DataCache { return this.cache[key]; } + public set(key: T, value: V): void { + this.cache[key] = { + ...value, + lastUsed: Date.now(), + }; + this.gc(); + } + public setupCache(key: T): V & CacheRecord { - if (!this.cache[key]) { - this.cache[key] = { - ...this.init(), - lastUsed: Date.now(), - }; - - if (Object.keys(this.cache).length > this.cacheLimit) { - const oldest = Object.entries(this.cache).reduce((a, b) => (a[1].lastUsed < b[1].lastUsed ? a : b)); - delete this.cache[oldest[0]]; - } + if (!this.cache[key] && this.init) { + this.set(key, this.init()); } return this.cache[key]; @@ -38,4 +38,11 @@ export class DataCache { return !!this.cache[key]; } + + private gc(): void { + if (Object.keys(this.cache).length > this.cacheLimit) { + const oldest = Object.entries(this.cache).reduce((a, b) => (a[1].lastUsed < b[1].lastUsed ? a : b)); + delete this.cache[oldest[0]]; + } + } } From 54d773274a0093f2c05ad64e831d251f6803ac9c Mon Sep 17 00:00:00 2001 From: hanyd Date: Thu, 5 Dec 2024 19:29:20 +0800 Subject: [PATCH 08/19] Wait for skip button control bar to be setup before using it --- src/content.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/content.ts b/src/content.ts index 89be6d56..69bf49c0 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1912,11 +1912,13 @@ function skipToTime({ v, skipTime, skippingSegments, openNotice, forceAutoSkip, } if (!autoSkip && skippingSegments.length === 1 && skippingSegments[0].actionType === ActionType.Poi) { - skipButtonControlBar.enable(skippingSegments[0]); - if (Config.config.skipKeybind == null) skipButtonControlBar.setShowKeybindHint(false); + waitFor(() => skipButtonControlBar).then(() => { + skipButtonControlBar.enable(skippingSegments[0]); + if (Config.config.skipKeybind == null) skipButtonControlBar.setShowKeybindHint(false); - activeSkipKeybindElement?.setShowKeybindHint(false); - activeSkipKeybindElement = skipButtonControlBar; + activeSkipKeybindElement?.setShowKeybindHint(false); + activeSkipKeybindElement = skipButtonControlBar; + }); } else { if (openNotice) { //send out the message saying that a sponsor message was skipped From 7cf89523d5f70c67b3bee8f36013fd08e93a23ab Mon Sep 17 00:00:00 2001 From: hanyd Date: Thu, 5 Dec 2024 19:38:57 +0800 Subject: [PATCH 09/19] Add a button element to skipbutton --- src/js-components/skipButtonControlBar.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/js-components/skipButtonControlBar.ts b/src/js-components/skipButtonControlBar.ts index b1e4e270..501816b7 100644 --- a/src/js-components/skipButtonControlBar.ts +++ b/src/js-components/skipButtonControlBar.ts @@ -13,6 +13,7 @@ export interface SkipButtonControlBarProps { export class SkipButtonControlBar { container: HTMLElement; + skipButton: HTMLButtonElement; skipIcon: HTMLImageElement; // textContainer: HTMLElement; // chapterText: HTMLElement; @@ -34,19 +35,20 @@ export class SkipButtonControlBar { this.container.classList.add("skipButtonControlBarContainer"); // this.container.classList.add("sbhidden"); - const button = document.createElement("button"); - button.classList.add("bpx-player-ctrl-btn", "playerButton"); - button.id = "sbSkipIconControlBarButton"; + this.skipButton = document.createElement("button"); + this.skipButton.classList.add("bpx-player-ctrl-btn", "playerButton"); + this.skipButton.id = "sbSkipIconControlBarButton"; this.skipIcon = document.createElement("img"); this.skipIcon.src = chrome.runtime.getURL("icons/skipIcon.svg"); this.skipIcon.classList.add("bpx-player-ctrl-btn-icon", "playerButtonImage"); this.skipIcon.id = "sbSkipIconControlBarImage"; + this.skipButton.appendChild(this.skipIcon); + // this.textContainer = document.createElement("div"); - button.appendChild(this.skipIcon); - this.container.appendChild(button); + this.container.appendChild(this.skipButton); // this.container.appendChild(this.textContainer); this.container.addEventListener("click", () => this.toggleSkip()); this.container.addEventListener("mouseenter", () => { @@ -74,7 +76,7 @@ export class SkipButtonControlBar { if (mountingContainer && !mountingContainer.contains(this.container)) { mountingContainer.append(this.container); - AnimationUtils.setupAutoHideAnimation(this.skipIcon, mountingContainer, true, false); + AnimationUtils.setupAutoHideAnimation(this.skipButton, mountingContainer, false, false); } } @@ -90,7 +92,7 @@ export class SkipButtonControlBar { this.refreshText(); this.container?.classList?.remove("textDisabled"); // this.textContainer?.classList?.remove("sbhidden"); - AnimationUtils.disableAutoHideAnimation(this.skipIcon); + AnimationUtils.disableAutoHideAnimation(this.skipButton); this.startTimer(); } @@ -100,7 +102,7 @@ export class SkipButtonControlBar { // this.chapterText?.classList?.add("sbhidden"); this.container.classList.remove("sbhidden"); // this.textContainer.innerText = this.getTitle(); - this.skipIcon.setAttribute("title", this.getTitle()); + this.skipButton.setAttribute("title", this.getTitle()); } } @@ -154,7 +156,7 @@ export class SkipButtonControlBar { this.getChapterPrefix()?.classList?.add("sbhidden"); - AnimationUtils.enableAutoHideAnimation(this.skipIcon); + AnimationUtils.enableAutoHideAnimation(this.skipButton); } private getTitle(): string { From 758bdbed9c2453e1032f8bc3fe55448c0a59f1af Mon Sep 17 00:00:00 2001 From: hanyd Date: Thu, 5 Dec 2024 19:51:24 +0800 Subject: [PATCH 10/19] update skip button style --- public/content.css | 13 +++++++------ src/js-components/skipButtonControlBar.ts | 2 ++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/public/content.css b/public/content.css index 4559717c..fe7f83a0 100644 --- a/public/content.css +++ b/public/content.css @@ -107,24 +107,25 @@ .autoHiding:not(.sbhidden) { transform: translateX(0%); - transition: transform 0.2s cubic-bezier(0.215, 0.61, 0.355, 1), width 0.2s cubic-bezier(0.215, 0.61, 0.355, 1), opacity 0.2s cubic-bezier(0.19, 1, 0.22, 1) !important; + transition: transform 0.2s cubic-bezier(0.215, 0.61, 0.355, 1), width 0.2s cubic-bezier(0.215, 0.61, 0.355, 1), + opacity 0.2s cubic-bezier(0.19, 1, 0.22, 1) !important; } .autoHiding.sbhidden { transform: translateX(100%); - transition: transform 0.2s cubic-bezier(0.215, 0.61, 0.355, 1), width 0.2s cubic-bezier(0.215, 0.61, 0.355, 1), opacity 0.2s cubic-bezier(0.19, 1, 0.22, 1) !important; - /* width: 0px !important; */ + transition: transform 0.2s cubic-bezier(0.215, 0.61, 0.355, 1), width 0.2s cubic-bezier(0.215, 0.61, 0.355, 1), + opacity 0.2s cubic-bezier(0.19, 1, 0.22, 1) !important; opacity: 0; } -@media (max-width: 1260px){ - .autoHiding.sbhidden{ +@media (max-width: 1260px) { + .autoHiding.sbhidden { width: 0px !important; } } .autoHiding.sbhidden.autoHideLeft { - transform: translateX(-100%) scale(0); + transform: translateX(-100%); } .sponsorSkipObject { diff --git a/src/js-components/skipButtonControlBar.ts b/src/js-components/skipButtonControlBar.ts index 501816b7..66b85165 100644 --- a/src/js-components/skipButtonControlBar.ts +++ b/src/js-components/skipButtonControlBar.ts @@ -38,11 +38,13 @@ export class SkipButtonControlBar { this.skipButton = document.createElement("button"); this.skipButton.classList.add("bpx-player-ctrl-btn", "playerButton"); this.skipButton.id = "sbSkipIconControlBarButton"; + this.skipButton.draggable = false; this.skipIcon = document.createElement("img"); this.skipIcon.src = chrome.runtime.getURL("icons/skipIcon.svg"); this.skipIcon.classList.add("bpx-player-ctrl-btn-icon", "playerButtonImage"); this.skipIcon.id = "sbSkipIconControlBarImage"; + this.skipIcon.draggable = false; this.skipButton.appendChild(this.skipIcon); From 1588ce5325007ca3016e40312e30d406ab690eb9 Mon Sep 17 00:00:00 2001 From: hanyd Date: Thu, 5 Dec 2024 19:51:59 +0800 Subject: [PATCH 11/19] Bump Version 0.5.5 --- manifest/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest/manifest.json b/manifest/manifest.json index 7b855a2d..6b3af6c0 100644 --- a/manifest/manifest.json +++ b/manifest/manifest.json @@ -1,7 +1,7 @@ { "name": "__MSG_fullName__", "short_name": "__MSG_shortName__", - "version": "0.5.4", + "version": "0.5.5", "default_locale": "zh_CN", "description": "__MSG_Description__", "icons": { From 23cacd9385e934ce43967d1d5d053a0113dd9f50 Mon Sep 17 00:00:00 2001 From: hanyd Date: Fri, 6 Dec 2024 08:56:54 +0800 Subject: [PATCH 12/19] fix element attachment --- src/content.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/content.ts b/src/content.ts index 69bf49c0..20369e3e 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1566,11 +1566,9 @@ function videoElementChange(newVideo: boolean): void { waitFor(() => Config.isReady() && !document.hidden, 24 * 60 * 60, 500).then(() => { if (newVideo) { setupVideoListeners(); - waitFor(getPageLoaded, 20000, 10).then(() => { - setupSkipButtonControlBar(); - setupCategoryPill(); - setupDescriptionPill(); - }); + setupSkipButtonControlBar(); + setupCategoryPill(); + setupDescriptionPill(); } updatePreviewBar(); From fa66e1b21618e6b34daef7089dda57b84b8ed07b Mon Sep 17 00:00:00 2001 From: hanyd Date: Fri, 6 Dec 2024 08:57:48 +0800 Subject: [PATCH 13/19] Bump Version 0.5.6 --- manifest/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest/manifest.json b/manifest/manifest.json index 6b3af6c0..a7758adc 100644 --- a/manifest/manifest.json +++ b/manifest/manifest.json @@ -1,7 +1,7 @@ { "name": "__MSG_fullName__", "short_name": "__MSG_shortName__", - "version": "0.5.5", + "version": "0.5.6", "default_locale": "zh_CN", "description": "__MSG_Description__", "icons": { From 801f03c79d79d49ed26960e8dc901fdeb157b8da Mon Sep 17 00:00:00 2001 From: hanyd Date: Fri, 6 Dec 2024 10:18:28 +0800 Subject: [PATCH 14/19] disable skip button when loading --- src/js-components/skipButtonControlBar.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js-components/skipButtonControlBar.ts b/src/js-components/skipButtonControlBar.ts index 66b85165..03d04817 100644 --- a/src/js-components/skipButtonControlBar.ts +++ b/src/js-components/skipButtonControlBar.ts @@ -33,7 +33,7 @@ export class SkipButtonControlBar { this.container = document.createElement("div"); this.container.classList.add("skipButtonControlBarContainer"); - // this.container.classList.add("sbhidden"); + this.container.classList.add("sbhidden"); this.skipButton = document.createElement("button"); this.skipButton.classList.add("bpx-player-ctrl-btn", "playerButton"); From 79876560ef3c029ed6061b51f2a72b78dc3b3237 Mon Sep 17 00:00:00 2001 From: hanyd Date: Fri, 6 Dec 2024 12:18:06 +0800 Subject: [PATCH 15/19] disable fetch overwrite --- src/document.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/document.ts b/src/document.ts index 1220bfd9..bfd8229d 100644 --- a/src/document.ts +++ b/src/document.ts @@ -62,7 +62,7 @@ function windowMessageListener(message: MessageEvent) { function init(): void { window.addEventListener("message", windowMessageListener); - overwriteFetch(); + // overwriteFetch(); } init(); From f4189c4b9583be2cb8b37033310257e2e8fd05d4 Mon Sep 17 00:00:00 2001 From: hanyd Date: Fri, 6 Dec 2024 12:18:46 +0800 Subject: [PATCH 16/19] Bump Version 0.5.7 --- manifest/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest/manifest.json b/manifest/manifest.json index a7758adc..76d54bf3 100644 --- a/manifest/manifest.json +++ b/manifest/manifest.json @@ -1,7 +1,7 @@ { "name": "__MSG_fullName__", "short_name": "__MSG_shortName__", - "version": "0.5.6", + "version": "0.5.7", "default_locale": "zh_CN", "description": "__MSG_Description__", "icons": { From 48ed6b28683e2093a393a41b5cfc6ef316b0f12c Mon Sep 17 00:00:00 2001 From: hanyd Date: Fri, 6 Dec 2024 15:05:01 +0800 Subject: [PATCH 17/19] reenable fetch overwrite --- src/document.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/document.ts b/src/document.ts index bfd8229d..1220bfd9 100644 --- a/src/document.ts +++ b/src/document.ts @@ -62,7 +62,7 @@ function windowMessageListener(message: MessageEvent) { function init(): void { window.addEventListener("message", windowMessageListener); - // overwriteFetch(); + overwriteFetch(); } init(); From 28ddf99f0a468c7cda6a6ded58c4d9f1bb55b9d2 Mon Sep 17 00:00:00 2001 From: xiaoxuan010 <2592053474@qq.com> Date: Fri, 6 Dec 2024 13:56:40 +0800 Subject: [PATCH 18/19] Add GitHub issue templates --- .github/ISSUE_TEMPLATE/bug-report.md | 36 +++++++++++++++++++++++ .github/ISSUE_TEMPLATE/feature-request.md | 20 +++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug-report.md create mode 100644 .github/ISSUE_TEMPLATE/feature-request.md diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md new file mode 100644 index 00000000..7cd8ee0d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -0,0 +1,36 @@ +--- +name: 问题反馈 +about: 提交您在使用插件中遇到的 Bug 或错误 +title: "[BUG] " +labels: bug +assignees: '' + +--- + +## 问题描述 +简要描述您遇到的 Bug 或错误: + +## 复现步骤 +请提供详细的复现步骤: + +1. 打开网址: +2. +3. + +## 预期表现 +描述您期望的正确表现: + +## 实际表现 +描述目前实际出现的错误或不符合预期的行为: + +## 屏幕截图或录像 +如果可能,请附上相关截图或视频,以便更好地说明问题: + +## 运行环境 +- 操作系统(OS): +- 浏览器: +- 浏览器版本: +- 插件版本: + +## 其他信息 +补充任何相关信息或日志: diff --git a/.github/ISSUE_TEMPLATE/feature-request.md b/.github/ISSUE_TEMPLATE/feature-request.md new file mode 100644 index 00000000..d7fa297d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature-request.md @@ -0,0 +1,20 @@ +--- +name: 新功能建议 +about: 提交您对插件的新功能或改进的建议 +title: "[Feature] " +labels: "新功能 Feature" +assignees: '' + +--- + +## 功能描述 +简要描述您希望添加的新功能或改进: + +## 使用场景 +请描述此功能的使用场景或带来的价值: + +## 您的建议 +如果可以,请提供您对功能实现的详细建议或方案: + +## 其他信息 +补充任何相关的上下文信息或参考资料: From 21074a1e567b63869c9f0fb865de2c3682ec6bac Mon Sep 17 00:00:00 2001 From: hanyd Date: Fri, 6 Dec 2024 15:41:23 +0800 Subject: [PATCH 19/19] update css --- public/content.css | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/public/content.css b/public/content.css index fe7f83a0..5fa9f062 100644 --- a/public/content.css +++ b/public/content.css @@ -103,18 +103,16 @@ .autoHiding { overflow: visible !important; + transition: transform 0.2s cubic-bezier(0.215, 0.61, 0.355, 1), width 0.2s cubic-bezier(0.215, 0.61, 0.355, 1), + opacity 0.2s cubic-bezier(0.19, 1, 0.22, 1) !important; } .autoHiding:not(.sbhidden) { transform: translateX(0%); - transition: transform 0.2s cubic-bezier(0.215, 0.61, 0.355, 1), width 0.2s cubic-bezier(0.215, 0.61, 0.355, 1), - opacity 0.2s cubic-bezier(0.19, 1, 0.22, 1) !important; } .autoHiding.sbhidden { transform: translateX(100%); - transition: transform 0.2s cubic-bezier(0.215, 0.61, 0.355, 1), width 0.2s cubic-bezier(0.215, 0.61, 0.355, 1), - opacity 0.2s cubic-bezier(0.19, 1, 0.22, 1) !important; opacity: 0; }