From f73a1171c43ed9efce36ca73cf423be5cfd14a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enes=20Yak=C4=B1=C5=9Ft=C4=B1r?= Date: Fri, 4 Sep 2026 06:55:20 +0300 Subject: [PATCH] fix(auth): guarantee all login links are hidden when user is logged in (v1.4.24) --- client.js | 132 +++++++++++++++++++++++++++++++-------------------- package.json | 2 +- style.css | 21 ++++++++ 3 files changed, 102 insertions(+), 53 deletions(-) diff --git a/client.js b/client.js index 9403c6a..576bd52 100644 --- a/client.js +++ b/client.js @@ -365,18 +365,24 @@ try { var uEmail = localStorage.getItem('email'); var displayName = localStorage.getItem('displayName') || uName || ''; 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) { - var defaultLoginLink = headerRight.querySelector('my-login-link, a[href*="/login"], .login-button'); var liveWidget = headerRight.querySelector('#yaknet-header-account-widget'); if (isAuth) { - // 1. AUTHENTICATED: Hide native login link, Show YakNet Account Profile Menu - if (defaultLoginLink) { - defaultLoginLink.style.display = 'none'; - defaultLoginLink.setAttribute('aria-hidden', 'true'); - } + // 1. AUTHENTICATED: Add class to body & Hide ALL native login links completely + document.body.classList.add('yaktube-user-logged-in'); + document + .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) { var widgetWrap = document.createElement('div'); @@ -449,29 +455,30 @@ try { } } else { // 2. GUEST / NOT LOGGED IN: - // A. Physically remove any widget from DOM to guarantee zero shadow DOM duplicate buttons + document.body.classList.remove('yaktube-user-logged-in'); if (liveWidget) { liveWidget.remove(); } - // B. Ensure PeerTube's native login link is the ONLY single accessible login element - if (defaultLoginLink) { - defaultLoginLink.style.display = ''; - defaultLoginLink.removeAttribute('aria-hidden'); + document + .querySelectorAll('my-login-link, a[href*="/login"], .login-button, [class*="login-link"]') + .forEach(function (btn) { + btn.style.display = ''; + btn.removeAttribute('aria-hidden'); + btn.removeAttribute('tabindex'); - var loginAnchor = - defaultLoginLink.tagName.toLowerCase() === 'a' ? defaultLoginLink : defaultLoginLink.querySelector('a'); - if (loginAnchor) { - loginAnchor.setAttribute('aria-label', 'YakNet ile Giriş Yap'); - loginAnchor.setAttribute('title', 'YakNet ile Giriş Yap'); - var spanText = loginAnchor.querySelector('span'); - if (spanText) { - spanText.textContent = 'YakNet ile Giriş Yap'; - } else { - loginAnchor.textContent = 'YakNet ile Giriş Yap'; + var loginAnchor = btn.tagName.toLowerCase() === 'a' ? btn : btn.querySelector('a'); + if (loginAnchor) { + loginAnchor.setAttribute('aria-label', 'YakNet ile Giriş Yap'); + loginAnchor.setAttribute('title', 'YakNet ile Giriş Yap'); + var spanText = loginAnchor.querySelector('span'); + if (spanText) { + spanText.textContent = 'YakNet ile Giriş Yap'; + } else { + loginAnchor.textContent = 'YakNet ile Giriş Yap'; + } } - } - } + }); } } @@ -571,34 +578,55 @@ try { injectYakNetSSO(); - // Replace all login buttons labels and titles - document - .querySelectorAll( - 'my-login-link, a[href*="/login"], a[title*="Giriş sayfasına git"], [aria-label*="Giriş sayfasına git"]' - ) - .forEach(function (el) { - if (el.getAttribute('title') && el.getAttribute('title').includes('Giriş sayfasına git')) { - el.setAttribute('title', 'YakNet ile Giriş Yap'); - } - if (el.getAttribute('aria-label') && el.getAttribute('aria-label').includes('Giriş sayfasına git')) { - el.setAttribute('aria-label', 'YakNet ile Giriş Yap'); - } - var anchor = el.tagName.toLowerCase() === 'a' ? el : el.querySelector('a'); - if (anchor) { - 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'; - } - }); - } - }); + // Check auth status for login button rendering + var tokenVal = localStorage.getItem('access_token'); + var userVal = localStorage.getItem('username'); + var isAlreadyAuth = + (!!tokenVal && !!userVal) || + document.body.classList.contains('yaktube-user-logged-in') || + !!document.querySelector('yaknet-account[authenticated="true"]'); + + if (!isAlreadyAuth) { + // Replace all login buttons labels and titles ONLY for guests + document + .querySelectorAll( + 'my-login-link, a[href*="/login"], a[title*="Giriş sayfasına git"], [aria-label*="Giriş sayfasına git"]' + ) + .forEach(function (el) { + if (el.getAttribute('title') && el.getAttribute('title').includes('Giriş sayfasına git')) { + el.setAttribute('title', 'YakNet ile Giriş Yap'); + } + if (el.getAttribute('aria-label') && el.getAttribute('aria-label').includes('Giriş sayfasına git')) { + el.setAttribute('aria-label', 'YakNet ile Giriş Yap'); + } + var anchor = el.tagName.toLowerCase() === 'a' ? el : el.querySelector('a'); + if (anchor) { + 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 document diff --git a/package.json b/package.json index 4dce07f..5f2889e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "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", "main": "main.js", "library": "./main.js", diff --git a/style.css b/style.css index 2230afc..bb391cf 100644 --- a/style.css +++ b/style.css @@ -24,6 +24,27 @@ button[title*='Dismiss'], 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 */ my-open-app, my-open-in-app,