Compare commits

...
2 Commits
2 changed files with 82 additions and 60 deletions
+81 -59
View File
@@ -1,26 +1,37 @@
// 100% Incompatible Browser Suppression & Error Guardian // 100% Incompatible Browser Suppression & Error Guardian
// CRITICAL: PeerTube's Angular app (my-app ngOnInit) relies on document.getElementById('incompatible-browser')
// to exist so it can do .className += " browser-ok" before calling this.loadUser()!
// Removing it from DOM causes a null pointer crash that breaks user session initialization!
if (typeof window !== 'undefined') { if (typeof window !== 'undefined') {
try { try {
window.displayIncompatibleBrowser = function () {}; window.displayIncompatibleBrowser = function () {};
var neuterIncompatible = function () { var neuterIncompatible = function () {
var el = document.getElementById('incompatible-browser'); var el = document.getElementById('incompatible-browser');
if (el) { if (el) {
el.classList.add('browser-ok'); if (!el.classList.contains('browser-ok')) {
el.classList.add('browser-ok');
}
el.style.setProperty('display', 'none', 'important'); el.style.setProperty('display', 'none', 'important');
if (el.parentNode) el.parentNode.removeChild(el); el.style.setProperty('visibility', 'hidden', 'important');
el.style.setProperty('height', '0px', 'important');
el.style.setProperty('width', '0px', 'important');
el.style.setProperty('opacity', '0', 'important');
el.style.setProperty('pointer-events', 'none', 'important');
} else {
try {
var dummy = document.createElement('div');
dummy.id = 'incompatible-browser';
dummy.className = 'browser-ok';
dummy.style.display = 'none';
(document.body || document.documentElement).appendChild(dummy);
} catch (e) {}
} }
}; };
neuterIncompatible(); neuterIncompatible();
if (document.readyState === 'loading') { if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', neuterIncompatible); document.addEventListener('DOMContentLoaded', neuterIncompatible);
} }
try {
var incompObserver = new MutationObserver(function () {
neuterIncompatible();
});
incompObserver.observe(document.documentElement || document.body, { childList: true, subtree: true });
} catch (e) {}
setInterval(neuterIncompatible, 1000); setInterval(neuterIncompatible, 1000);
} catch (e) {} } catch (e) {}
} }
@@ -368,15 +379,18 @@ try {
var isAuth = !!token && !!uName; var isAuth = !!token && !!uName;
if (headerRight) { if (headerRight) {
var defaultLoginLink = headerRight.querySelector('my-login-link, a[href*="/login"], .login-button');
var liveWidget = headerRight.querySelector('#yaknet-header-account-widget'); var liveWidget = headerRight.querySelector('#yaknet-header-account-widget');
if (isAuth) { if (isAuth) {
// 1. AUTHENTICATED: Hide native login link, Show YakNet Account Profile Menu // 1. AUTHENTICATED: Add class to body & Hide ALL native login links completely
if (defaultLoginLink) { document.body.classList.add('yaktube-user-logged-in');
defaultLoginLink.style.display = 'none'; document
defaultLoginLink.setAttribute('aria-hidden', 'true'); .querySelectorAll('my-login-link, a[href*="/login"], .login-button, [class*="login-link"]')
} .forEach(function (btn) {
btn.style.setProperty('display', 'none', 'important');
btn.setAttribute('aria-hidden', 'true');
btn.setAttribute('tabindex', '-1');
});
if (!liveWidget) { if (!liveWidget) {
var widgetWrap = document.createElement('div'); var widgetWrap = document.createElement('div');
@@ -449,29 +463,30 @@ try {
} }
} else { } else {
// 2. GUEST / NOT LOGGED IN: // 2. GUEST / NOT LOGGED IN:
// A. Physically remove any <yaknet-account> widget from DOM to guarantee zero shadow DOM duplicate buttons document.body.classList.remove('yaktube-user-logged-in');
if (liveWidget) { if (liveWidget) {
liveWidget.remove(); liveWidget.remove();
} }
// B. Ensure PeerTube's native login link is the ONLY single accessible login element document
if (defaultLoginLink) { .querySelectorAll('my-login-link, a[href*="/login"], .login-button, [class*="login-link"]')
defaultLoginLink.style.display = ''; .forEach(function (btn) {
defaultLoginLink.removeAttribute('aria-hidden'); btn.style.display = '';
btn.removeAttribute('aria-hidden');
btn.removeAttribute('tabindex');
var loginAnchor = var loginAnchor = btn.tagName.toLowerCase() === 'a' ? btn : btn.querySelector('a');
defaultLoginLink.tagName.toLowerCase() === 'a' ? defaultLoginLink : defaultLoginLink.querySelector('a'); if (loginAnchor) {
if (loginAnchor) { loginAnchor.setAttribute('aria-label', 'YakNet ile Giriş Yap');
loginAnchor.setAttribute('aria-label', 'YakNet ile Giriş Yap'); loginAnchor.setAttribute('title', 'YakNet ile Giriş Yap');
loginAnchor.setAttribute('title', 'YakNet ile Giriş Yap'); var spanText = loginAnchor.querySelector('span');
var spanText = loginAnchor.querySelector('span'); if (spanText) {
if (spanText) { spanText.textContent = 'YakNet ile Giriş Yap';
spanText.textContent = 'YakNet ile Giriş Yap'; } else {
} else { loginAnchor.textContent = 'YakNet ile Giriş Yap';
loginAnchor.textContent = 'YakNet ile Giriş Yap'; }
} }
} });
}
} }
} }
@@ -571,34 +586,41 @@ try {
injectYakNetSSO(); injectYakNetSSO();
// Replace all login buttons labels and titles // Check auth status for login button rendering
document var tokenVal = localStorage.getItem('access_token');
.querySelectorAll( var userVal = localStorage.getItem('username');
'my-login-link, a[href*="/login"], a[title*="Giriş sayfasına git"], [aria-label*="Giriş sayfasına git"]' var isAlreadyAuth = !!tokenVal && !!userVal;
)
.forEach(function (el) { if (!isAlreadyAuth) {
if (el.getAttribute('title') && el.getAttribute('title').includes('Giriş sayfasına git')) { // Replace all login buttons labels and titles ONLY for guests
el.setAttribute('title', 'YakNet ile Giriş Yap'); document
} .querySelectorAll(
if (el.getAttribute('aria-label') && el.getAttribute('aria-label').includes('Giriş sayfasına git')) { 'my-login-link, a[href*="/login"], a[title*="Giriş sayfasına git"], [aria-label*="Giriş sayfasına git"]'
el.setAttribute('aria-label', 'YakNet ile Giriş Yap'); )
} .forEach(function (el) {
var anchor = el.tagName.toLowerCase() === 'a' ? el : el.querySelector('a'); if (el.getAttribute('title') && el.getAttribute('title').includes('Giriş sayfasına git')) {
if (anchor) { el.setAttribute('title', 'YakNet ile Giriş Yap');
anchor.setAttribute('title', 'YakNet ile Giriş Yap'); }
anchor.setAttribute('aria-label', 'YakNet ile Giriş Yap'); if (el.getAttribute('aria-label') && el.getAttribute('aria-label').includes('Giriş sayfasına git')) {
var spans = anchor.querySelectorAll('span'); el.setAttribute('aria-label', 'YakNet ile Giriş Yap');
spans.forEach(function (s) { }
if ( var anchor = el.tagName.toLowerCase() === 'a' ? el : el.querySelector('a');
s.textContent.includes('Giriş sayfasına git') || if (anchor) {
s.textContent.trim() === 'Giriş' || anchor.setAttribute('title', 'YakNet ile Giriş Yap');
s.textContent.trim() === 'Giriş yap' anchor.setAttribute('aria-label', 'YakNet ile Giriş Yap');
) { var spans = anchor.querySelectorAll('span');
s.textContent = 'YakNet ile Giriş Yap'; spans.forEach(function (s) {
} if (
}); s.textContent.includes('Giriş sayfasına git') ||
} s.textContent.trim() === 'Giriş' ||
}); s.textContent.trim() === 'Giriş yap'
) {
s.textContent = 'YakNet ile Giriş Yap';
}
});
}
});
}
// Aggressively remove generic Framasoft Open-in-App / Play Store banners // Aggressively remove generic Framasoft Open-in-App / Play Store banners
document document
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "peertube-plugin-yaktube-ondemand", "name": "peertube-plugin-yaktube-ondemand",
"version": "1.4.23", "version": "1.4.25",
"description": "Accessible On-Demand YouTube Import, Live Streams, Smart Recommendations and A11y Engine for PeerTube", "description": "Accessible On-Demand YouTube Import, Live Streams, Smart Recommendations and A11y Engine for PeerTube",
"main": "main.js", "main": "main.js",
"library": "./main.js", "library": "./main.js",