invidious/assets/js/watch-actions.js
Nachiketh Reddy 09fc7878e2 feat(ui): modernize the browsing and watch experience
Refresh navigation, search results, login, channel cards, and the watch page while keeping native no-JavaScript fallbacks. Add scoped player gestures, theater mode, accessible action menus, theme controls, and focused regression coverage.

Model: OpenAI gpt-5.6-sol (high reasoning)
Harness: T3 Code Codex
2026-09-11 19:42:49 +08:00

48 lines
2.1 KiB
JavaScript

'use strict';
(function () {
var menus = document.querySelectorAll('.watch-action-menu');
menus.forEach(function (menu) {
menu.addEventListener('toggle', function () {
if (menu.open) menus.forEach(function (other) {
if (other !== menu && !other.contains(menu)) other.open = false;
});
});
});
document.addEventListener('click', function (event) {
menus.forEach(function (menu) {
if (!menu.contains(event.target)) menu.open = false;
});
});
document.addEventListener('keydown', function (event) {
if (event.key !== 'Escape') return;
menus.forEach(function (menu) {
if (menu.open) { menu.open = false; menu.querySelector('summary').focus(); }
});
});
document.querySelectorAll('.watch-action').forEach(function (action) {
if (!action.title) action.title = action.textContent.trim();
});
document.querySelectorAll('.watch-share-link').forEach(function (link) {
var row = document.createElement('div');
row.className = 'watch-share-choice';
link.before(row); row.appendChild(link);
var input = document.createElement('input');
input.readOnly = true; input.value = link.href;
input.setAttribute('aria-label', link.textContent.trim());
input.addEventListener('focus', function () { input.select(); });
row.appendChild(input);
if (!navigator.clipboard) return;
var button = document.createElement('button');
button.type = 'button';
var panel = row.closest('.watch-share-panel');
button.textContent = panel.dataset.copyLabel;
button.addEventListener('click', function () {
navigator.clipboard.writeText(link.href).then(function () {
button.textContent = panel.dataset.copiedLabel;
setTimeout(function () { button.textContent = panel.dataset.copyLabel; }, 1800);
}).catch(function () { input.focus(); input.select(); });
});
row.appendChild(button);
});
})();