mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-06 19:47:04 +03:00
Add support for live updating in chrome
This commit is contained in:
@@ -81,7 +81,8 @@
|
|||||||
],
|
],
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"storage",
|
"storage",
|
||||||
"https://sponsor.ajay.app/*"
|
"https://sponsor.ajay.app/*",
|
||||||
|
"https://*.youtube.com/*"
|
||||||
],
|
],
|
||||||
"optional_permissions": [
|
"optional_permissions": [
|
||||||
"*://*/*",
|
"*://*/*",
|
||||||
|
|||||||
Submodule maze-utils updated: 5945ad4aa1...b3572eaeff
@@ -13,6 +13,9 @@ window.SB = Config;
|
|||||||
|
|
||||||
import Utils from "./utils";
|
import Utils from "./utils";
|
||||||
import { getExtensionIdsToImportFrom } from "./utils/crossExtension";
|
import { getExtensionIdsToImportFrom } from "./utils/crossExtension";
|
||||||
|
import { isFirefoxOrSafari } from "./maze-utils";
|
||||||
|
import { injectUpdatedScripts } from "./maze-utils/cleanup";
|
||||||
|
import { logWarn } from "./utils/logger";
|
||||||
const utils = new Utils({
|
const utils = new Utils({
|
||||||
registerFirefoxContentScript,
|
registerFirefoxContentScript,
|
||||||
unregisterFirefoxContentScript
|
unregisterFirefoxContentScript
|
||||||
@@ -132,6 +135,11 @@ chrome.runtime.onInstalled.addListener(function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 1500);
|
}, 1500);
|
||||||
|
|
||||||
|
// Only do this once the old version understands how to clean itself up
|
||||||
|
if (!isFirefoxOrSafari() && chrome.runtime.getManifest().version !== "5.4.13") {
|
||||||
|
injectUpdatedScripts().catch(logWarn);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ import { Tooltip } from "./render/Tooltip";
|
|||||||
import { isDeArrowInstalled } from "./utils/crossExtension";
|
import { isDeArrowInstalled } from "./utils/crossExtension";
|
||||||
import { runCompatibilityChecks } from "./utils/compatibility";
|
import { runCompatibilityChecks } from "./utils/compatibility";
|
||||||
import { cleanPage } from "./utils/pageCleaner";
|
import { cleanPage } from "./utils/pageCleaner";
|
||||||
|
import { addCleanupListener } from "./maze-utils/cleanup";
|
||||||
|
|
||||||
cleanPage();
|
cleanPage();
|
||||||
|
|
||||||
@@ -476,6 +477,8 @@ function videoIDChange(): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleMobileControlsMutations(): void {
|
function handleMobileControlsMutations(): void {
|
||||||
|
if (!chrome.runtime?.id) return;
|
||||||
|
|
||||||
updateVisibilityOfPlayerControlsButton();
|
updateVisibilityOfPlayerControlsButton();
|
||||||
|
|
||||||
skipButtonControlBar?.updateMobileControls();
|
skipButtonControlBar?.updateMobileControls();
|
||||||
@@ -815,18 +818,26 @@ function incorrectVideoCheck(videoID?: string, sponsorTime?: SponsorTime): boole
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let setupVideoListenersFirstTime = true;
|
||||||
function setupVideoListeners() {
|
function setupVideoListeners() {
|
||||||
//wait until it is loaded
|
//wait until it is loaded
|
||||||
getVideo().addEventListener('loadstart', videoOnReadyListener)
|
getVideo().addEventListener('loadstart', videoOnReadyListener)
|
||||||
getVideo().addEventListener('durationchange', durationChangeListener);
|
getVideo().addEventListener('durationchange', durationChangeListener);
|
||||||
|
|
||||||
|
if (setupVideoListenersFirstTime) {
|
||||||
|
addCleanupListener(() => {
|
||||||
|
getVideo().removeEventListener('loadstart', videoOnReadyListener);
|
||||||
|
getVideo().removeEventListener('durationchange', durationChangeListener);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (!Config.config.disableSkipping) {
|
if (!Config.config.disableSkipping) {
|
||||||
switchingVideos = false;
|
switchingVideos = false;
|
||||||
|
|
||||||
let startedWaiting = false;
|
let startedWaiting = false;
|
||||||
let lastPausedAtZero = true;
|
let lastPausedAtZero = true;
|
||||||
|
|
||||||
getVideo().addEventListener('play', () => {
|
const playListener = () => {
|
||||||
// If it is not the first event, then the only way to get to 0 is if there is a seek event
|
// If it is not the first event, then the only way to get to 0 is if there is a seek event
|
||||||
// This check makes sure that changing the video resolution doesn't cause the extension to think it
|
// This check makes sure that changing the video resolution doesn't cause the extension to think it
|
||||||
// gone back to the begining
|
// gone back to the begining
|
||||||
@@ -857,8 +868,10 @@ function setupVideoListeners() {
|
|||||||
startSponsorSchedule();
|
startSponsorSchedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
};
|
||||||
getVideo().addEventListener('playing', () => {
|
getVideo().addEventListener('play', playListener);
|
||||||
|
|
||||||
|
const playingListener = () => {
|
||||||
updateVirtualTime();
|
updateVirtualTime();
|
||||||
lastPausedAtZero = false;
|
lastPausedAtZero = false;
|
||||||
|
|
||||||
@@ -884,8 +897,10 @@ function setupVideoListeners() {
|
|||||||
|
|
||||||
startSponsorSchedule();
|
startSponsorSchedule();
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
getVideo().addEventListener('seeking', () => {
|
getVideo().addEventListener('playing', playingListener);
|
||||||
|
|
||||||
|
const seekingListener = () => {
|
||||||
lastKnownVideoTime.fromPause = false;
|
lastKnownVideoTime.fromPause = false;
|
||||||
|
|
||||||
if (!getVideo().paused){
|
if (!getVideo().paused){
|
||||||
@@ -909,20 +924,19 @@ function setupVideoListeners() {
|
|||||||
lastPausedAtZero = true;
|
lastPausedAtZero = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
getVideo().addEventListener('ratechange', () => {
|
getVideo().addEventListener('seeking', seekingListener);
|
||||||
|
|
||||||
|
const rateChangeListener = () => {
|
||||||
updateVirtualTime();
|
updateVirtualTime();
|
||||||
clearWaitingTime();
|
clearWaitingTime();
|
||||||
|
|
||||||
startSponsorSchedule();
|
startSponsorSchedule();
|
||||||
});
|
};
|
||||||
|
getVideo().addEventListener('ratechange', () => rateChangeListener);
|
||||||
// Used by videospeed extension (https://github.com/igrigorik/videospeed/pull/740)
|
// Used by videospeed extension (https://github.com/igrigorik/videospeed/pull/740)
|
||||||
getVideo().addEventListener('videoSpeed_ratechange', () => {
|
getVideo().addEventListener('videoSpeed_ratechange', rateChangeListener);
|
||||||
updateVirtualTime();
|
|
||||||
clearWaitingTime();
|
|
||||||
|
|
||||||
startSponsorSchedule();
|
|
||||||
});
|
|
||||||
const stoppedPlayback = () => {
|
const stoppedPlayback = () => {
|
||||||
// Reset lastCheckVideoTime
|
// Reset lastCheckVideoTime
|
||||||
lastCheckVideoTime = -1;
|
lastCheckVideoTime = -1;
|
||||||
@@ -934,20 +948,36 @@ function setupVideoListeners() {
|
|||||||
|
|
||||||
cancelSponsorSchedule();
|
cancelSponsorSchedule();
|
||||||
};
|
};
|
||||||
getVideo().addEventListener('pause', () => {
|
const pauseListener = () => {
|
||||||
lastKnownVideoTime.fromPause = true;
|
lastKnownVideoTime.fromPause = true;
|
||||||
|
|
||||||
stoppedPlayback();
|
stoppedPlayback();
|
||||||
});
|
};
|
||||||
getVideo().addEventListener('waiting', () => {
|
getVideo().addEventListener('pause', pauseListener);
|
||||||
|
const waitingListener = () => {
|
||||||
logDebug("[SB] Not skipping due to buffering");
|
logDebug("[SB] Not skipping due to buffering");
|
||||||
startedWaiting = true;
|
startedWaiting = true;
|
||||||
|
|
||||||
stoppedPlayback();
|
stoppedPlayback();
|
||||||
});
|
};
|
||||||
|
getVideo().addEventListener('waiting', waitingListener);
|
||||||
|
|
||||||
startSponsorSchedule();
|
startSponsorSchedule();
|
||||||
|
|
||||||
|
if (setupVideoListenersFirstTime) {
|
||||||
|
addCleanupListener(() => {
|
||||||
|
getVideo().removeEventListener('play', playListener);
|
||||||
|
getVideo().removeEventListener('playing', playingListener);
|
||||||
|
getVideo().removeEventListener('seeking', seekingListener);
|
||||||
|
getVideo().removeEventListener('ratechange', rateChangeListener);
|
||||||
|
getVideo().removeEventListener('videoSpeed_ratechange', rateChangeListener);
|
||||||
|
getVideo().removeEventListener('pause', pauseListener);
|
||||||
|
getVideo().removeEventListener('waiting', waitingListener);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setupVideoListenersFirstTime = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateVirtualTime() {
|
function updateVirtualTime() {
|
||||||
@@ -1626,9 +1656,10 @@ function skipToTime({v, skipTime, skippingSegments, openNotice, forceAutoSkip, u
|
|||||||
beep.play();
|
beep.play();
|
||||||
beep.addEventListener("ended", () => {
|
beep.addEventListener("ended", () => {
|
||||||
navigator.mediaSession.metadata = null;
|
navigator.mediaSession.metadata = null;
|
||||||
setTimeout(() =>
|
setTimeout(() => {
|
||||||
navigator.mediaSession.metadata = oldMetadata
|
navigator.mediaSession.metadata = oldMetadata;
|
||||||
);
|
beep.remove();
|
||||||
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2342,6 +2373,10 @@ function addHotkeyListener(): void {
|
|||||||
// Allow us to stop propagation to YouTube by being deeper
|
// Allow us to stop propagation to YouTube by being deeper
|
||||||
document.removeEventListener("keydown", hotkeyListener);
|
document.removeEventListener("keydown", hotkeyListener);
|
||||||
document.body.addEventListener("keydown", hotkeyListener);
|
document.body.addEventListener("keydown", hotkeyListener);
|
||||||
|
|
||||||
|
addCleanupListener(() => {
|
||||||
|
document.body.removeEventListener("keydown", hotkeyListener);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (document.readyState === "complete") {
|
if (document.readyState === "complete") {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { DEFAULT_CATEGORY, shortCategoryName } from "../utils/categoryUtils";
|
|||||||
import { normalizeChapterName } from "../utils/exporter";
|
import { normalizeChapterName } from "../utils/exporter";
|
||||||
import { getFormattedTimeToSeconds } from "../maze-utils/formating";
|
import { getFormattedTimeToSeconds } from "../maze-utils/formating";
|
||||||
import { findValidElement } from "../maze-utils/dom";
|
import { findValidElement } from "../maze-utils/dom";
|
||||||
|
import { addCleanupListener } from "../maze-utils/cleanup";
|
||||||
|
|
||||||
const TOOLTIP_VISIBLE_CLASS = 'sponsorCategoryTooltipVisible';
|
const TOOLTIP_VISIBLE_CLASS = 'sponsorCategoryTooltipVisible';
|
||||||
const MIN_CHAPTER_SIZE = 0.003;
|
const MIN_CHAPTER_SIZE = 0.003;
|
||||||
@@ -201,6 +202,10 @@ class PreviewBar {
|
|||||||
childList: true,
|
childList: true,
|
||||||
subtree: true,
|
subtree: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
addCleanupListener(() => {
|
||||||
|
observer.disconnect();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private setTooltipTitle(segment: PreviewBarSegment, tooltip: HTMLElement): void {
|
private setTooltipTitle(segment: PreviewBarSegment, tooltip: HTMLElement): void {
|
||||||
@@ -626,6 +631,11 @@ class PreviewBar {
|
|||||||
childListObserver.observe(this.originalChapterBar, {
|
childListObserver.observe(this.originalChapterBar, {
|
||||||
childList: true
|
childList: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
addCleanupListener(() => {
|
||||||
|
attributeObserver.disconnect();
|
||||||
|
childListObserver.disconnect();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateChapterAllMutation(originalChapterBar: HTMLElement, progressBar: HTMLElement, firstUpdate = false): void {
|
private updateChapterAllMutation(originalChapterBar: HTMLElement, progressBar: HTMLElement, firstUpdate = false): void {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { Category, SegmentUUID, SponsorTime } from "../types";
|
|||||||
import { Tooltip } from "./Tooltip";
|
import { Tooltip } from "./Tooltip";
|
||||||
import { waitFor } from "../maze-utils";
|
import { waitFor } from "../maze-utils";
|
||||||
import { getYouTubeTitleNode } from "../maze-utils/elements";
|
import { getYouTubeTitleNode } from "../maze-utils/elements";
|
||||||
|
import { addCleanupListener } from "../maze-utils/cleanup";
|
||||||
|
|
||||||
const id = "categoryPill";
|
const id = "categoryPill";
|
||||||
|
|
||||||
@@ -24,6 +25,12 @@ export class CategoryPill {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.ref = React.createRef();
|
this.ref = React.createRef();
|
||||||
|
|
||||||
|
addCleanupListener(() => {
|
||||||
|
if (this.mutationObserver) {
|
||||||
|
this.mutationObserver.disconnect();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async attachToPage(onMobileYouTube: boolean, onInvidious: boolean,
|
async attachToPage(onMobileYouTube: boolean, onInvidious: boolean,
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
export function cleanPage() {
|
export function cleanPage() {
|
||||||
// For live-updates
|
// For live-updates
|
||||||
for (const element of document.querySelectorAll("#categoryPillParent, .playerButton, .sponsorThumbnailLabel, #submissionNoticeContainer, .sponsorSkipNoticeContainer, #sponsorBlockPopupContainer, .skipButtonControlBarContainer, #previewbar")) {
|
if (document.readyState === "complete") {
|
||||||
|
for (const element of document.querySelectorAll("#categoryPillParent, .playerButton, .sponsorThumbnailLabel, #submissionNoticeContainer, .sponsorSkipNoticeContainer, #sponsorBlockPopupContainer, .skipButtonControlBarContainer, #previewbar, .sponsorBlockChapterBar")) {
|
||||||
element.remove();
|
element.remove();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user