fix(auth): guarantee all login links are hidden when user is logged in (v1.4.24)

This commit is contained in:
Enes Yakıştır
2026-09-04 06:55:20 +03:00
parent 64afa7c5e9
commit f73a1171c4
3 changed files with 102 additions and 53 deletions
+80 -52
View File
@@ -365,18 +365,24 @@ try {
var uEmail = localStorage.getItem('email'); var uEmail = localStorage.getItem('email');
var displayName = localStorage.getItem('displayName') || uName || ''; var displayName = localStorage.getItem('displayName') || uName || '';
var emailStr = uEmail || ''; var emailStr = uEmail || '';
var isAuth = !!token && !!uName; var isAuth =
(!!token && !!uName) ||
(liveWidget && liveWidget.querySelector('yaknet-account[authenticated="true"]')) ||
!!document.querySelector('yaknet-account[authenticated="true"]');
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 +455,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 +578,55 @@ 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) { document.body.classList.contains('yaktube-user-logged-in') ||
if (el.getAttribute('title') && el.getAttribute('title').includes('Giriş sayfasına git')) { !!document.querySelector('yaknet-account[authenticated="true"]');
el.setAttribute('title', 'YakNet ile Giriş Yap');
} if (!isAlreadyAuth) {
if (el.getAttribute('aria-label') && el.getAttribute('aria-label').includes('Giriş sayfasına git')) { // Replace all login buttons labels and titles ONLY for guests
el.setAttribute('aria-label', 'YakNet ile Giriş Yap'); document
} .querySelectorAll(
var anchor = el.tagName.toLowerCase() === 'a' ? el : el.querySelector('a'); 'my-login-link, a[href*="/login"], a[title*="Giriş sayfasına git"], [aria-label*="Giriş sayfasına git"]'
if (anchor) { )
anchor.setAttribute('title', 'YakNet ile Giriş Yap'); .forEach(function (el) {
anchor.setAttribute('aria-label', 'YakNet ile Giriş Yap'); if (el.getAttribute('title') && el.getAttribute('title').includes('Giriş sayfasına git')) {
var spans = anchor.querySelectorAll('span'); el.setAttribute('title', 'YakNet ile Giriş Yap');
spans.forEach(function (s) { }
if ( if (el.getAttribute('aria-label') && el.getAttribute('aria-label').includes('Giriş sayfasına git')) {
s.textContent.includes('Giriş sayfasına git') || el.setAttribute('aria-label', 'YakNet ile Giriş Yap');
s.textContent.trim() === 'Giriş' || }
s.textContent.trim() === 'Giriş yap' var anchor = el.tagName.toLowerCase() === 'a' ? el : el.querySelector('a');
) { if (anchor) {
s.textContent = 'YakNet ile Giriş Yap'; anchor.setAttribute('title', 'YakNet ile Giriş Yap');
} anchor.setAttribute('aria-label', 'YakNet ile Giriş Yap');
}); var spans = anchor.querySelectorAll('span');
} 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';
}
});
}
});
} else {
// Guarantee all login links are hidden when user is logged in
document
.querySelectorAll(
'my-login-link, a[href*="/login"], .login-button, [class*="login-link"]'
)
.forEach(function (el) {
el.style.setProperty('display', 'none', 'important');
el.setAttribute('aria-hidden', 'true');
el.setAttribute('tabindex', '-1');
});
}
// 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.24",
"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",
+21
View File
@@ -24,6 +24,27 @@ button[title*='Dismiss'],
clip: rect(0, 0, 0, 0) !important; clip: rect(0, 0, 0, 0) !important;
} }
/* Permanent suppression of native login links when user is authenticated */
body.yaktube-user-logged-in my-login-link,
body.yaktube-user-logged-in a[href*="/login"],
body.yaktube-user-logged-in .login-button,
body.yaktube-user-logged-in [class*="login-link"],
body.yaktube-user-logged-in .peertube-button-link[href*="/login"],
body.yaktube-user-logged-in a[title*="Giriş"],
body.yaktube-user-logged-in a[aria-label*="Giriş"] {
display: none !important;
visibility: hidden !important;
height: 0 !important;
width: 0 !important;
margin: 0 !important;
padding: 0 !important;
pointer-events: none !important;
opacity: 0 !important;
position: absolute !important;
z-index: -99999 !important;
clip: rect(0, 0, 0, 0) !important;
}
/* Permanent Aggressive Suppression of Generic JoinPeerTube / Framasoft Open-in-App Banners */ /* Permanent Aggressive Suppression of Generic JoinPeerTube / Framasoft Open-in-App Banners */
my-open-app, my-open-app,
my-open-in-app, my-open-in-app,