fix(header): eliminate duplicate login button and polish single YakNet login link v1.4.4

This commit is contained in:
Enes Yakıştır
2026-08-31 14:32:22 +03:00
parent 51e41df3ca
commit 551b6d1ab6
2 changed files with 92 additions and 74 deletions
+39 -21
View File
@@ -283,7 +283,16 @@
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) {
// Logged In: Show YakNet Profile Menu, Hide default login link
if (defaultLoginLink) {
defaultLoginLink.style.display = 'none';
defaultLoginLink.setAttribute('aria-hidden', 'true');
}
if (!liveWidget) { if (!liveWidget) {
var widgetWrap = document.createElement('div'); var widgetWrap = document.createElement('div');
widgetWrap.id = 'yaknet-header-account-widget'; widgetWrap.id = 'yaknet-header-account-widget';
@@ -298,21 +307,18 @@
'redirect-uri="https://yaktube.yakhub.com.tr/plugins/peertube-plugin-auth-yaknet/router/auth-callback" ' + 'redirect-uri="https://yaktube.yakhub.com.tr/plugins/peertube-plugin-auth-yaknet/router/auth-callback" ' +
'base-url="https://auth.yakhub.com.tr" ' + 'base-url="https://auth.yakhub.com.tr" ' +
'login-url="/login" ' + 'login-url="/login" ' +
'authenticated="' + 'authenticated="true" ' +
(isAuth ? 'true' : 'false') +
'" ' +
'user-name="' + 'user-name="' +
(isAuth ? displayName.replace(/"/g, '"') : '') + displayName.replace(/"/g, '"') +
'" ' + '" ' +
'user-email="' + 'user-email="' +
(isAuth ? emailStr.replace(/"/g, '"') : '') + emailStr.replace(/"/g, '"') +
'" ' + '" ' +
'theme="dark">' + 'theme="dark">' +
'</yaknet-account>'; '</yaknet-account>';
var targetSibling = var targetSibling =
headerRight.querySelector('my-user-menu') || headerRight.querySelector('my-user-menu') ||
headerRight.querySelector('my-login-link') ||
headerRight.querySelector('.user-menu') || headerRight.querySelector('.user-menu') ||
headerRight.querySelector('.settings-button') || headerRight.querySelector('.settings-button') ||
headerRight.querySelector('my-user-notifications') || headerRight.querySelector('my-user-notifications') ||
@@ -323,15 +329,7 @@
} else { } else {
headerRight.prepend(widgetWrap); headerRight.prepend(widgetWrap);
} }
var defaultLoginLink = headerRight.querySelector('my-login-link');
if (defaultLoginLink) {
defaultLoginLink.setAttribute('aria-hidden', 'true');
defaultLoginLink.setAttribute('tabindex', '-1');
defaultLoginLink.style.display = 'none';
}
} else { } else {
// Sync widget attributes dynamically if auth state changed
var el = liveWidget.querySelector('yaknet-account'); var el = liveWidget.querySelector('yaknet-account');
if (el) { if (el) {
if (el.shadowRoot) { if (el.shadowRoot) {
@@ -353,13 +351,10 @@
} }
} }
var expectedAuth = isAuth ? 'true' : 'false'; if (el.getAttribute('authenticated') !== 'true' || el.getAttribute('user-name') !== displayName) {
var expectedName = isAuth ? displayName : ''; el.setAttribute('authenticated', 'true');
var expectedEmail = isAuth ? emailStr : ''; el.setAttribute('user-name', displayName);
if (el.getAttribute('authenticated') !== expectedAuth || el.getAttribute('user-name') !== expectedName) { el.setAttribute('user-email', emailStr);
el.setAttribute('authenticated', expectedAuth);
el.setAttribute('user-name', expectedName);
el.setAttribute('user-email', expectedEmail);
if (typeof el.syncStateFromAttributes === 'function') { if (typeof el.syncStateFromAttributes === 'function') {
el.syncStateFromAttributes(); el.syncStateFromAttributes();
el.render(); el.render();
@@ -367,6 +362,29 @@
} }
} }
} }
} else {
// Not Logged In: Remove YakNet widget to eliminate duplicate button, keep PeerTube native login button clean
if (liveWidget) {
liveWidget.remove();
}
if (defaultLoginLink) {
defaultLoginLink.style.display = '';
defaultLoginLink.removeAttribute('aria-hidden');
var loginAnchor =
defaultLoginLink.tagName.toLowerCase() === 'a' ? defaultLoginLink : defaultLoginLink.querySelector('a');
if (loginAnchor) {
loginAnchor.setAttribute('aria-label', 'YakNet ile Giriş Yap');
loginAnchor.setAttribute('title', 'YakNet Hesabınız ile Giriş Yapın');
var spanText = loginAnchor.querySelector('span');
if (spanText) {
spanText.textContent = 'YakNet ile Giriş Yap';
} else {
loginAnchor.textContent = 'YakNet ile Giriş Yap';
}
}
}
}
} }
// 2.2 Login Modal / Page // 2.2 Login Modal / Page
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "peertube-plugin-yaktube-ondemand", "name": "peertube-plugin-yaktube-ondemand",
"version": "1.4.3", "version": "1.4.4",
"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",