mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-12-06 19:56:45 +10:30
Merge pull request #465 from StroepWafel/fix-external-video-loading
fix(ext video): Fix loading of external video by internalising
This commit is contained in:
5 files changed
+253
-5
No files matched your search
@@ -5857,3 +5857,76 @@ h2.home-subtitle {
|
||||
font-size: 20px;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.bsplus-ld-surprise-root {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 50;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.bsplus-ld-surprise-popout {
|
||||
pointer-events: auto;
|
||||
position: fixed;
|
||||
right: 24px;
|
||||
bottom: 24px;
|
||||
width: min(640px, calc(100vw - 48px));
|
||||
aspect-ratio: 16 / 9;
|
||||
border-radius: 16px;
|
||||
overflow: hidden;
|
||||
background: #000;
|
||||
box-shadow: 0 22px 70px rgba(0, 0, 0, 0.35);
|
||||
border: 1px solid color-mix(in srgb, var(--text-primary) 12%, transparent);
|
||||
transform-origin: bottom right;
|
||||
animation: bsplusLdSurprisePopoutIn 0.28s ease-out;
|
||||
}
|
||||
|
||||
.bsplus-ld-surprise-player {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: #000;
|
||||
|
||||
iframe {
|
||||
display: block;
|
||||
width: 640px;
|
||||
max-width: 100%;
|
||||
height: 360px;
|
||||
max-height: 100%;
|
||||
border: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.bsplus-ld-surprise-close {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
z-index: 1;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: 999px;
|
||||
cursor: pointer;
|
||||
background: rgba(0, 0, 0, 0.55);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.bsplus-ld-surprise-close::before {
|
||||
content: "\ed8a";
|
||||
font-family: "IconFamily";
|
||||
font-size: 20px;
|
||||
line-height: 1;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
@keyframes bsplusLdSurprisePopoutIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: scale(0.92) translateY(12px);
|
||||
}
|
||||
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: scale(1) translateY(0);
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,7 @@
|
||||
"resources/update-image.webp",
|
||||
"resources/pdfjs/pdf.worker.min.mjs",
|
||||
"resources/pdfjs/pdf.legacy.min.mjs",
|
||||
"resources/themeToggleSurprisePage.js",
|
||||
"resources/ort/*",
|
||||
"assets/*.css",
|
||||
"assets/*"
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/* Maintainer note: page-context YouTube IFrame API for theme toggle easter egg. */
|
||||
(function () {
|
||||
if (window.__bsplusThemeSurprisePage) return;
|
||||
window.__bsplusThemeSurprisePage = true;
|
||||
|
||||
var MESSAGE_SOURCE = "betterseqta-theme-surprise";
|
||||
var ytPlayer = null;
|
||||
var apiReady = false;
|
||||
var pendingMountId = null;
|
||||
|
||||
window.onYouTubeIframeAPIReady = function () {
|
||||
apiReady = true;
|
||||
if (pendingMountId) {
|
||||
var mountId = pendingMountId;
|
||||
pendingMountId = null;
|
||||
openPlayer(mountId);
|
||||
}
|
||||
};
|
||||
|
||||
if (
|
||||
!document.querySelector('script[src="https://www.youtube.com/iframe_api"]')
|
||||
) {
|
||||
var apiScript = document.createElement("script");
|
||||
apiScript.src = "https://www.youtube.com/iframe_api";
|
||||
(document.head || document.documentElement).appendChild(apiScript);
|
||||
}
|
||||
|
||||
function openPlayer(mountId) {
|
||||
if (!apiReady) {
|
||||
pendingMountId = mountId;
|
||||
return;
|
||||
}
|
||||
|
||||
if (ytPlayer) {
|
||||
ytPlayer.playVideo();
|
||||
ytPlayer.unMute();
|
||||
return;
|
||||
}
|
||||
|
||||
ytPlayer = new YT.Player(mountId, {
|
||||
height: "360",
|
||||
width: "640",
|
||||
videoId: "dQw4w9WgXcQ",
|
||||
playerVars: {
|
||||
autoplay: 1,
|
||||
rel: 0,
|
||||
origin: window.location.origin,
|
||||
},
|
||||
events: {
|
||||
onReady: function (event) {
|
||||
event.target.unMute();
|
||||
event.target.playVideo();
|
||||
},
|
||||
onError: function (event) {
|
||||
console.warn(
|
||||
"[BetterSEQTA+] Theme toggle surprise YouTube error:",
|
||||
event.data,
|
||||
);
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
window.addEventListener("message", function (event) {
|
||||
if (event.source !== window || !event.data) return;
|
||||
if (event.data.source !== MESSAGE_SOURCE) return;
|
||||
|
||||
if (event.data.type === "open" && event.data.mountId) {
|
||||
openPlayer(event.data.mountId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.data.type === "close") {
|
||||
try {
|
||||
if (ytPlayer && ytPlayer.destroy) {
|
||||
ytPlayer.destroy();
|
||||
}
|
||||
} catch (error) {}
|
||||
ytPlayer = null;
|
||||
pendingMountId = null;
|
||||
}
|
||||
});
|
||||
})();
|
||||
@@ -14,6 +14,11 @@ import stringToHTML from "@/seqta/utils/stringToHTML";
|
||||
import { settingsState } from "@/seqta/utils/listeners/SettingsState";
|
||||
import { updateAllColors } from "./colors/Manager";
|
||||
import { delay } from "@/seqta/utils/delay";
|
||||
import {
|
||||
ensureThemeToggleSurprisePageScript,
|
||||
openThemeToggleSurprise,
|
||||
THEME_TOGGLE_SURPRISE_TRIGGER_AT,
|
||||
} from "@/seqta/utils/Openers/openThemeToggleSurprise";
|
||||
import { LUCIDE_MOON_ICON_SVG } from "@/lib/icons/lucideMoon";
|
||||
import { LUCIDE_SUN_ICON_SVG } from "@/lib/icons/lucideSun";
|
||||
import { ensureTitlebarFounderBadgeMounted, refreshTitlebarFounderBadge } from "@/seqta/ui/founderBadge/mountTitlebarFounderBadge";
|
||||
@@ -47,7 +52,7 @@ function attachUserInfoCacheInvalidation(): void {
|
||||
|
||||
attachUserInfoCacheInvalidation();
|
||||
|
||||
let LightDarkModeSnakeEggButton = 0;
|
||||
let lightDarkToggleStreak = 0;
|
||||
let sidebarAccessibilityObserver: MutationObserver | null = null;
|
||||
let sidebarTabOrderAnimationFrame: number | null = null;
|
||||
let sidebarAccessibilityListenersAttached = false;
|
||||
@@ -543,14 +548,17 @@ async function addDarkLightToggle(parent?: Element) {
|
||||
"LightDarkModeButton",
|
||||
)!;
|
||||
|
||||
ensureThemeToggleSurprisePageScript();
|
||||
|
||||
lightDarkModeButtonElement.addEventListener("click", async () => {
|
||||
const darklightText = document.getElementById("darklighttooliptext");
|
||||
|
||||
LightDarkModeSnakeEggButton += 1;
|
||||
lightDarkToggleStreak += 1;
|
||||
|
||||
if (LightDarkModeSnakeEggButton >= 10) {
|
||||
window.open("https://www.youtube.com/watch?v=dQw4w9WgXcQ", "_blank");
|
||||
LightDarkModeSnakeEggButton = 0;
|
||||
if (lightDarkToggleStreak >= THEME_TOGGLE_SURPRISE_TRIGGER_AT) {
|
||||
lightDarkToggleStreak = 0;
|
||||
openThemeToggleSurprise();
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
import browser from "webextension-polyfill";
|
||||
|
||||
/** Maintainer note: the light/dark toggle easter egg (10 clicks) plays a Rick Roll video. */
|
||||
const PAGE_SCRIPT_RESOURCE = "resources/themeToggleSurprisePage.js";
|
||||
const POPOUT_ROOT_ID = "bsplus-ld-surprise-root";
|
||||
const PLAYER_MOUNT_ID = "bsplus-ld-surprise-player";
|
||||
const PAGE_SCRIPT_ID = "bsplus-theme-surprise-page-script";
|
||||
const MESSAGE_SOURCE = "betterseqta-theme-surprise";
|
||||
|
||||
export const THEME_TOGGLE_SURPRISE_TRIGGER_AT = 10;
|
||||
|
||||
let playerRoot: HTMLElement | null = null;
|
||||
let pageScriptInjected = false;
|
||||
|
||||
function hostElement(): HTMLElement {
|
||||
return document.getElementById("container") ?? document.body;
|
||||
}
|
||||
|
||||
function postToPageContext(type: "open" | "close", mountId?: string): void {
|
||||
window.postMessage(
|
||||
{
|
||||
source: MESSAGE_SOURCE,
|
||||
type,
|
||||
mountId,
|
||||
},
|
||||
"*",
|
||||
);
|
||||
}
|
||||
|
||||
/** Loads YouTube IFrame API in the page context (mirrors the test HTML setup). */
|
||||
export function ensureThemeToggleSurprisePageScript(): void {
|
||||
if (pageScriptInjected || document.getElementById(PAGE_SCRIPT_ID)) {
|
||||
pageScriptInjected = true;
|
||||
return;
|
||||
}
|
||||
|
||||
const script = document.createElement("script");
|
||||
script.id = PAGE_SCRIPT_ID;
|
||||
script.src = browser.runtime.getURL(PAGE_SCRIPT_RESOURCE);
|
||||
(document.head || document.documentElement).appendChild(script);
|
||||
pageScriptInjected = true;
|
||||
}
|
||||
|
||||
function ensurePlayerShell(): void {
|
||||
if (playerRoot) return;
|
||||
|
||||
const root = document.createElement("div");
|
||||
root.id = POPOUT_ROOT_ID;
|
||||
root.className = "bsplus-ld-surprise-root";
|
||||
|
||||
const aside = document.createElement("aside");
|
||||
aside.className = "bsplus-ld-surprise-popout";
|
||||
aside.setAttribute("role", "dialog");
|
||||
aside.setAttribute("aria-label", "Video player");
|
||||
|
||||
const closeBtn = document.createElement("button");
|
||||
closeBtn.type = "button";
|
||||
closeBtn.className = "bsplus-ld-surprise-close";
|
||||
closeBtn.setAttribute("aria-label", "Close");
|
||||
closeBtn.addEventListener("click", closeThemeToggleSurprise);
|
||||
|
||||
const mount = document.createElement("div");
|
||||
mount.id = PLAYER_MOUNT_ID;
|
||||
mount.className = "bsplus-ld-surprise-player";
|
||||
|
||||
aside.append(closeBtn, mount);
|
||||
root.append(aside);
|
||||
hostElement().append(root);
|
||||
|
||||
playerRoot = root;
|
||||
}
|
||||
|
||||
export function closeThemeToggleSurprise(): void {
|
||||
postToPageContext("close");
|
||||
playerRoot?.remove();
|
||||
playerRoot = null;
|
||||
}
|
||||
|
||||
export function openThemeToggleSurprise(): void {
|
||||
ensureThemeToggleSurprisePageScript();
|
||||
ensurePlayerShell();
|
||||
postToPageContext("open", PLAYER_MOUNT_ID);
|
||||
}
|
||||
Reference in new issue
Block a user