mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-10 13:37:04 +03:00
Support live updates on firefox
This commit is contained in:
Submodule maze-utils updated: b7f55f39cc...5945ad4aa1
@@ -45,6 +45,9 @@ import * as documentScript from "../dist/js/document.js";
|
|||||||
import { Tooltip } from "./render/Tooltip";
|
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";
|
||||||
|
|
||||||
|
cleanPage();
|
||||||
|
|
||||||
const utils = new Utils();
|
const utils = new Utils();
|
||||||
|
|
||||||
@@ -1356,6 +1359,7 @@ async function channelIDChange(channelIDInfo: ChannelIDInfo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function videoElementChange(newVideo: boolean): void {
|
function videoElementChange(newVideo: boolean): void {
|
||||||
|
waitFor(() => Config.isReady()).then(() => {
|
||||||
if (newVideo) {
|
if (newVideo) {
|
||||||
setupVideoListeners();
|
setupVideoListeners();
|
||||||
setupSkipButtonControlBar();
|
setupSkipButtonControlBar();
|
||||||
@@ -1368,6 +1372,7 @@ function videoElementChange(newVideo: boolean): void {
|
|||||||
setTimeout(checkPreviewbarState, 100);
|
setTimeout(checkPreviewbarState, 100);
|
||||||
setTimeout(checkPreviewbarState, 1000);
|
setTimeout(checkPreviewbarState, 1000);
|
||||||
setTimeout(checkPreviewbarState, 5000);
|
setTimeout(checkPreviewbarState, 5000);
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkPreviewbarState(): void {
|
function checkPreviewbarState(): void {
|
||||||
@@ -2331,11 +2336,17 @@ function previousChapter(): void {
|
|||||||
function addHotkeyListener(): void {
|
function addHotkeyListener(): void {
|
||||||
document.addEventListener("keydown", hotkeyListener);
|
document.addEventListener("keydown", hotkeyListener);
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
const onLoad = () => {
|
||||||
// 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);
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (document.readyState === "complete") {
|
||||||
|
onLoad();
|
||||||
|
} else {
|
||||||
|
document.addEventListener("DOMContentLoaded", onLoad);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function hotkeyListener(e: KeyboardEvent): void {
|
function hotkeyListener(e: KeyboardEvent): void {
|
||||||
@@ -2392,7 +2403,7 @@ function hotkeyListener(e: KeyboardEvent): void {
|
|||||||
*/
|
*/
|
||||||
function addCSS() {
|
function addCSS() {
|
||||||
if (!isFirefoxOrSafari() && Config.config.invidiousInstances.includes(new URL(document.URL).hostname)) {
|
if (!isFirefoxOrSafari() && Config.config.invidiousInstances.includes(new URL(document.URL).hostname)) {
|
||||||
window.addEventListener("DOMContentLoaded", () => {
|
const onLoad = () => {
|
||||||
const head = document.getElementsByTagName("head")[0];
|
const head = document.getElementsByTagName("head")[0];
|
||||||
|
|
||||||
for (const file of utils.css) {
|
for (const file of utils.css) {
|
||||||
@@ -2404,7 +2415,13 @@ function addCSS() {
|
|||||||
|
|
||||||
head.appendChild(fileref);
|
head.appendChild(fileref);
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (document.readyState === "complete") {
|
||||||
|
onLoad();
|
||||||
|
} else {
|
||||||
|
document.addEventListener("DOMContentLoaded", onLoad);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,11 @@ import { showDonationLink } from "./utils/configUtils";
|
|||||||
|
|
||||||
import { waitFor } from "./maze-utils";
|
import { waitFor } from "./maze-utils";
|
||||||
|
|
||||||
window.addEventListener('DOMContentLoaded', init);
|
if (document.readyState === "complete") {
|
||||||
|
init();
|
||||||
|
} else {
|
||||||
|
document.addEventListener("DOMContentLoaded", init);
|
||||||
|
}
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
localizeHtmlPage();
|
localizeHtmlPage();
|
||||||
|
|||||||
@@ -24,7 +24,11 @@ let embed = false;
|
|||||||
const categoryChoosers: CategoryChooser[] = [];
|
const categoryChoosers: CategoryChooser[] = [];
|
||||||
const unsubmittedVideos: UnsubmittedVideos[] = [];
|
const unsubmittedVideos: UnsubmittedVideos[] = [];
|
||||||
|
|
||||||
window.addEventListener('DOMContentLoaded', init);
|
if (document.readyState === "complete") {
|
||||||
|
init();
|
||||||
|
} else {
|
||||||
|
document.addEventListener("DOMContentLoaded", init);
|
||||||
|
}
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
localizeHtmlPage();
|
localizeHtmlPage();
|
||||||
|
|||||||
@@ -7,7 +7,11 @@ const utils = new Utils();
|
|||||||
// Probably due to cyclic dependencies
|
// Probably due to cyclic dependencies
|
||||||
Config.config;
|
Config.config;
|
||||||
|
|
||||||
window.addEventListener('DOMContentLoaded', init);
|
if (document.readyState === "complete") {
|
||||||
|
init();
|
||||||
|
} else {
|
||||||
|
document.addEventListener("DOMContentLoaded", init);
|
||||||
|
}
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
localizeHtmlPage();
|
localizeHtmlPage();
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ export default class GenericNotice {
|
|||||||
const referenceNode = options.referenceNode ?? utils.findReferenceNode();
|
const referenceNode = options.referenceNode ?? utils.findReferenceNode();
|
||||||
|
|
||||||
this.noticeElement = document.createElement("div");
|
this.noticeElement = document.createElement("div");
|
||||||
|
this.noticeElement.className = "sponsorSkipNoticeContainer";
|
||||||
this.noticeElement.id = "sponsorSkipNoticeContainer" + idSuffix;
|
this.noticeElement.id = "sponsorSkipNoticeContainer" + idSuffix;
|
||||||
|
|
||||||
referenceNode.prepend(this.noticeElement);
|
referenceNode.prepend(this.noticeElement);
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ class SkipNotice {
|
|||||||
idSuffix += amountOfPreviousNotices;
|
idSuffix += amountOfPreviousNotices;
|
||||||
|
|
||||||
this.noticeElement = document.createElement("div");
|
this.noticeElement = document.createElement("div");
|
||||||
|
this.noticeElement.className = "sponsorSkipNoticeContainer";
|
||||||
this.noticeElement.id = "sponsorSkipNoticeContainer" + idSuffix;
|
this.noticeElement.id = "sponsorSkipNoticeContainer" + idSuffix;
|
||||||
|
|
||||||
referenceNode.prepend(this.noticeElement);
|
referenceNode.prepend(this.noticeElement);
|
||||||
|
|||||||
6
src/utils/pageCleaner.ts
Normal file
6
src/utils/pageCleaner.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
export function cleanPage() {
|
||||||
|
// For live-updates
|
||||||
|
for (const element of document.querySelectorAll("#categoryPillParent, .playerButton, .sponsorThumbnailLabel, #submissionNoticeContainer, .sponsorSkipNoticeContainer, #sponsorBlockPopupContainer")) {
|
||||||
|
element.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user