fix: suppress app banners, seamless background audio auto-resume, and continuous YakNet SSO session probe v1.4.11

This commit is contained in:
Enes Yakıştır
2026-08-31 20:20:55 +03:00
parent dac3137330
commit 3016fc6328
3 changed files with 131 additions and 115 deletions
+52 -62
View File
@@ -287,8 +287,7 @@ 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');
if (isAuth) { // Always hide duplicate native login link in favor of unified YakNet component
// Logged In: Show YakNet Profile Menu, Hide default login link
if (defaultLoginLink) { if (defaultLoginLink) {
defaultLoginLink.style.display = 'none'; defaultLoginLink.style.display = 'none';
defaultLoginLink.setAttribute('aria-hidden', 'true'); defaultLoginLink.setAttribute('aria-hidden', 'true');
@@ -307,8 +306,8 @@ try {
'client-id="01a03c41-f758-721e-b927-619bffde5c23" ' + 'client-id="01a03c41-f758-721e-b927-619bffde5c23" ' +
'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="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=" ' +
'authenticated="true" ' + (isAuth ? 'authenticated="true" ' : 'authenticated="false" ') +
'user-name="' + 'user-name="' +
displayName.replace(/"/g, '"') + displayName.replace(/"/g, '"') +
'" ' + '" ' +
@@ -333,6 +332,17 @@ try {
} else { } else {
var el = liveWidget.querySelector('yaknet-account'); var el = liveWidget.querySelector('yaknet-account');
if (el) { if (el) {
var authAttr = isAuth ? 'true' : 'false';
if (el.getAttribute('authenticated') !== authAttr || el.getAttribute('user-name') !== displayName) {
el.setAttribute('authenticated', authAttr);
el.setAttribute('user-name', displayName);
el.setAttribute('user-email', emailStr);
if (typeof el.syncStateFromAttributes === 'function') {
el.syncStateFromAttributes();
el.render();
}
}
if (el.shadowRoot) { if (el.shadowRoot) {
var shadowLogoutBtn = var shadowLogoutBtn =
el.shadowRoot.getElementById('logoutBtn') || el.shadowRoot.getElementById('logoutBtn') ||
@@ -351,39 +361,6 @@ try {
); );
} }
} }
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();
}
}
}
}
} 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';
}
}
} }
} }
} }
@@ -3019,8 +2996,8 @@ try {
(function initBackgroundPlaybackEngine() { (function initBackgroundPlaybackEngine() {
var videoState = { var videoState = {
hasPlayed: false, hasPlayed: false,
pausedByUser: false, explicitlyPausedByClick: false,
pausedAt: null lastPlayTime: 0
}; };
function attachVideoListeners(video) { function attachVideoListeners(video) {
@@ -3029,21 +3006,14 @@ try {
video.addEventListener('play', function () { video.addEventListener('play', function () {
videoState.hasPlayed = true; videoState.hasPlayed = true;
videoState.pausedByUser = false; videoState.explicitlyPausedByClick = false;
videoState.lastPlayTime = Date.now();
updateMediaSessionMetadata(video); updateMediaSessionMetadata(video);
}); });
video.addEventListener('pause', function () {
videoState.pausedAt = Date.now();
// If document is visible when paused, it was paused manually by the user
if (!document.hidden) {
videoState.pausedByUser = true;
}
});
video.addEventListener('ended', function () { video.addEventListener('ended', function () {
videoState.hasPlayed = false; videoState.hasPlayed = false;
videoState.pausedByUser = true; videoState.explicitlyPausedByClick = true;
}); });
video.addEventListener('timeupdate', function () { video.addEventListener('timeupdate', function () {
@@ -3051,30 +3021,50 @@ try {
}); });
} }
function handleVisibilityChange() { // Hook manual play/pause buttons
if (!document.hidden) return; // Screen is active document.addEventListener(
'click',
function (e) {
var target = e.target;
if (!target) return;
var btn = target.closest(
'.vjs-play-control, button[title*="Duraklat"], button[aria-label*="Duraklat"], #yaktube-bar-play-btn'
);
if (btn) {
var video = getVideoElement();
if (video && !video.paused) {
videoState.explicitlyPausedByClick = true;
}
}
},
true
);
function handleVisibilityChange() {
var video = getVideoElement(); var video = getVideoElement();
if (!video) return; if (!video) return;
// If user hasn't played or deliberately paused, do not auto-resume // When screen turns off / tab is hidden:
if (!videoState.hasPlayed || videoState.pausedByUser) return; if (document.hidden || document.webkitHidden) {
if (videoState.hasPlayed && !videoState.explicitlyPausedByClick) {
var now = Date.now(); // Unconditionally keep audio stream active
if (videoState.pausedAt && now - videoState.pausedAt > 1500 && videoState.pausedByUser) {
return;
}
// Resume playback when screen locks or tab switches
setTimeout(function () { setTimeout(function () {
if (video.paused && !videoState.pausedByUser) { if (video.paused && !videoState.explicitlyPausedByClick) {
video.play().catch(function () {}); video.play().catch(function () {});
} }
}, 50); }, 100);
setTimeout(function () {
if (video.paused && !videoState.explicitlyPausedByClick) {
video.play().catch(function () {});
}
}, 300);
}
}
} }
document.addEventListener('visibilitychange', handleVisibilityChange, false); document.addEventListener('visibilitychange', handleVisibilityChange, false);
document.addEventListener('webkitvisibilitychange', handleVisibilityChange, false); document.addEventListener('webkitvisibilitychange', handleVisibilityChange, false);
window.addEventListener('pagehide', handleVisibilityChange, false);
// MediaSession API Integration (Lock Screen, Bluetooth, Smart Watches) // MediaSession API Integration (Lock Screen, Bluetooth, Smart Watches)
function updateMediaSessionMetadata(video) { function updateMediaSessionMetadata(video) {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "peertube-plugin-yaktube-ondemand", "name": "peertube-plugin-yaktube-ondemand",
"version": "1.4.10", "version": "1.4.11",
"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",
+26
View File
@@ -1,3 +1,29 @@
/* Permanent Aggressive Suppression of Generic JoinPeerTube / Framasoft Open-in-App Banners */
my-open-app,
my-open-in-app,
my-client-app-banner,
.open-app-container,
.app-banner,
[class*='open-app'],
[class*='open-in-app'],
.mobile-app-banner,
.app-promotion,
.client-app-banner,
a[href*='play.google.com/store/apps/details?id=app.joinpeertube'],
a[href*='f-droid.org'],
a[href*='joinpeertube'] {
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;
}
/* YakTube Accessibility & On-Demand CSS */ /* YakTube Accessibility & On-Demand CSS */
:focus-visible { :focus-visible {