Compare commits

...
2 Commits
2 changed files with 141 additions and 69 deletions
+140 -68
View File
@@ -50,6 +50,52 @@ try {
}, 50); }, 50);
} }
// Load official YakNet Web Component definition
if (
typeof customElements !== 'undefined' &&
!customElements.get('yaknet-account') &&
!document.getElementById('yaknet-account-script')
) {
var s = document.createElement('script');
s.id = 'yaknet-account-script';
s.src = 'https://auth.yakhub.com.tr/js/yaknet-account.js';
s.async = true;
document.head.appendChild(s);
}
// Silent background SSO Probe Engine
function initSilentSSOProbe() {
var token = localStorage.getItem('access_token');
var isManualLogout = sessionStorage.getItem('yaknet_manual_logout');
if (
token ||
isManualLogout ||
window.location.search.includes('local=true') ||
window.location.search.includes('externalAuthError') ||
window.location.pathname.includes('/login')
) {
return;
}
var iframeId = 'yaknet-sso-iframe-instance';
if (!document.getElementById(iframeId)) {
var iframe = document.createElement('iframe');
iframe.id = iframeId;
iframe.src = 'https://auth.yakhub.com.tr/sdk/sso-frame';
iframe.title = 'YakNet Oturum Kontrolü';
iframe.setAttribute('aria-hidden', 'true');
iframe.tabIndex = -1;
iframe.style.cssText =
'display:none!important;width:0!important;height:0!important;border:0!important;position:absolute!important;pointer-events:none!important;';
document.body.appendChild(iframe);
}
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initSilentSSOProbe);
} else {
initSilentSSOProbe();
}
function triggerYakNetOAuth() { function triggerYakNetOAuth() {
sessionStorage.removeItem('yaknet_manual_logout'); sessionStorage.removeItem('yaknet_manual_logout');
var callbackUrl = 'https://yaktube.yakhub.com.tr/plugins/peertube-plugin-auth-yaknet/router/auth-callback'; var callbackUrl = 'https://yaktube.yakhub.com.tr/plugins/peertube-plugin-auth-yaknet/router/auth-callback';
@@ -287,78 +333,104 @@ try {
var defaultLoginLink = headerRight.querySelector('my-login-link, a[href*="/login"], .login-button'); 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');
// Always hide duplicate native login link in favor of unified YakNet component if (isAuth) {
if (defaultLoginLink) { // 1. AUTHENTICATED: Hide native login link, Show YakNet Account Profile Menu
defaultLoginLink.style.display = 'none'; if (defaultLoginLink) {
defaultLoginLink.setAttribute('aria-hidden', 'true'); defaultLoginLink.style.display = 'none';
} defaultLoginLink.setAttribute('aria-hidden', 'true');
if (!liveWidget) {
var widgetWrap = document.createElement('div');
widgetWrap.id = 'yaknet-header-account-widget';
widgetWrap.className = 'yaknet-header-widget';
widgetWrap.style.display = 'inline-flex';
widgetWrap.style.alignItems = 'center';
widgetWrap.style.marginRight = '8px';
widgetWrap.innerHTML =
'<yaknet-account ' +
'client-id="01a03c41-f758-721e-b927-619bffde5c23" ' +
'redirect-uri="https://yaktube.yakhub.com.tr/plugins/peertube-plugin-auth-yaknet/router/auth-callback" ' +
'base-url="https://auth.yakhub.com.tr" ' +
'login-url="https://auth.yakhub.com.tr/oauth/authorize?client_id=01a03c41-f758-721e-b927-619bffde5c23&redirect_uri=https%3A%2F%2Fyaktube.yakhub.com.tr%2Fplugins%2Fpeertube-plugin-auth-yaknet%2Frouter%2Fauth-callback&response_type=code&scope=" ' +
(isAuth ? 'authenticated="true" ' : 'authenticated="false" ') +
'user-name="' +
displayName.replace(/"/g, '&quot;') +
'" ' +
'user-email="' +
emailStr.replace(/"/g, '&quot;') +
'" ' +
'theme="dark">' +
'</yaknet-account>';
var targetSibling =
headerRight.querySelector('my-user-menu') ||
headerRight.querySelector('.user-menu') ||
headerRight.querySelector('.settings-button') ||
headerRight.querySelector('my-user-notifications') ||
headerRight.querySelector('my-notification-bell');
if (targetSibling && targetSibling.parentElement === headerRight) {
headerRight.insertBefore(widgetWrap, targetSibling);
} else {
headerRight.prepend(widgetWrap);
} }
} else {
var el = liveWidget.querySelector('yaknet-account'); if (!liveWidget) {
if (el) { var widgetWrap = document.createElement('div');
var authAttr = isAuth ? 'true' : 'false'; widgetWrap.id = 'yaknet-header-account-widget';
if (el.getAttribute('authenticated') !== authAttr || el.getAttribute('user-name') !== displayName) { widgetWrap.className = 'yaknet-header-widget';
el.setAttribute('authenticated', authAttr); widgetWrap.style.display = 'inline-flex';
el.setAttribute('user-name', displayName); widgetWrap.style.alignItems = 'center';
el.setAttribute('user-email', emailStr); widgetWrap.style.marginRight = '8px';
if (typeof el.syncStateFromAttributes === 'function') {
el.syncStateFromAttributes(); widgetWrap.innerHTML =
el.render(); '<yaknet-account ' +
'client-id="01a03c41-f758-721e-b927-619bffde5c23" ' +
'redirect-uri="https://yaktube.yakhub.com.tr/plugins/peertube-plugin-auth-yaknet/router/auth-callback" ' +
'base-url="https://auth.yakhub.com.tr" ' +
'login-url="/login" ' +
'authenticated="true" ' +
'user-name="' +
displayName.replace(/"/g, '&quot;') +
'" ' +
'user-email="' +
emailStr.replace(/"/g, '&quot;') +
'" ' +
'theme="dark">' +
'</yaknet-account>';
var targetSibling =
headerRight.querySelector('my-user-menu') ||
headerRight.querySelector('.user-menu') ||
headerRight.querySelector('.settings-button') ||
headerRight.querySelector('my-user-notifications') ||
headerRight.querySelector('my-notification-bell');
if (targetSibling && targetSibling.parentElement === headerRight) {
headerRight.insertBefore(widgetWrap, targetSibling);
} else {
headerRight.prepend(widgetWrap);
}
} else {
var el = liveWidget.querySelector('yaknet-account');
if (el) {
if (el.getAttribute('authenticated') !== 'true' || el.getAttribute('user-name') !== displayName) {
el.setAttribute('authenticated', 'true');
el.setAttribute('user-name', displayName);
el.setAttribute('user-email', emailStr);
if (typeof el.syncStateFromAttributes === 'function') {
el.syncStateFromAttributes();
el.render();
}
}
if (el.shadowRoot) {
var shadowLogoutBtn =
el.shadowRoot.getElementById('logoutBtn') ||
el.shadowRoot.querySelector('.yn-logout-btn') ||
el.shadowRoot.querySelector('button[title*="Çıkış"], button[aria-label*="Çıkış"]');
if (shadowLogoutBtn && !shadowLogoutBtn.hasAttribute('data-yaktube-hooked')) {
shadowLogoutBtn.setAttribute('data-yaktube-hooked', 'true');
shadowLogoutBtn.addEventListener(
'click',
function (ev) {
ev.preventDefault();
ev.stopPropagation();
performUnifiedLogout();
},
true
);
}
} }
} }
}
} else {
// 2. GUEST / NOT LOGGED IN:
// A. Physically remove any <yaknet-account> widget from DOM to guarantee zero shadow DOM duplicate buttons
if (liveWidget) {
liveWidget.remove();
}
if (el.shadowRoot) { // B. Ensure PeerTube's native login link is the ONLY single accessible login element
var shadowLogoutBtn = if (defaultLoginLink) {
el.shadowRoot.getElementById('logoutBtn') || defaultLoginLink.style.display = '';
el.shadowRoot.querySelector('.yn-logout-btn') || defaultLoginLink.removeAttribute('aria-hidden');
el.shadowRoot.querySelector('button[title*="Çıkış"], button[aria-label*="Çıkış"]');
if (shadowLogoutBtn && !shadowLogoutBtn.hasAttribute('data-yaktube-hooked')) { var loginAnchor =
shadowLogoutBtn.setAttribute('data-yaktube-hooked', 'true'); defaultLoginLink.tagName.toLowerCase() === 'a' ? defaultLoginLink : defaultLoginLink.querySelector('a');
shadowLogoutBtn.addEventListener( if (loginAnchor) {
'click', loginAnchor.setAttribute('aria-label', 'YakNet ile Giriş Yap');
function (ev) { loginAnchor.setAttribute('title', 'YakNet ile Giriş Yap');
ev.preventDefault(); var spanText = loginAnchor.querySelector('span');
ev.stopPropagation(); if (spanText) {
performUnifiedLogout(); spanText.textContent = 'YakNet ile Giriş Yap';
}, } else {
true loginAnchor.textContent = 'YakNet ile Giriş Yap';
);
} }
} }
} }
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "peertube-plugin-yaktube-ondemand", "name": "peertube-plugin-yaktube-ondemand",
"version": "1.4.13", "version": "1.4.15",
"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",