OpenCode AI e9899d2e6d
Some checks failed
Android CI Build / check (push) Has been cancelled
Android CI Build / package-apks (push) Has been cancelled
Docs Deploy / build (push) Has been cancelled
Module Market Check / Validate modules/ (push) Has been cancelled
Module Market Publish / Generate submissions.json (push) Has been cancelled
Docs Deploy / deploy (push) Has been cancelled
Initial DruksCode V2: fresh fork of web-to-app (f3b488e) with DruksCode identity
- Package rename com.webtoapp -> br.com.drukstech.codeapp
- Product rename WebToApp/web-to-app -> DruksCode/drukscode
- Design system Wta* -> Dkc*
- applicationId br.com.drukstech.codeapp (.play for gplay flavor)
- rootProject.name DruksCode
- Fresh git history (upstream kept as remote for sync)
2026-09-12 02:42:02 +02:00

112 lines
4.8 KiB
JavaScript

(function() {
'use strict';
const TAG = "YouTubePlayer";
function log(msg) { console.log(`[${TAG}] ${msg}`); }
function extractYouTubeVideoId(url) {
const patterns = [
/(?:youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/|m\.youtube\.com\/watch\?v=)([a-zA-Z0-9_-]{11})/,
/v=([a-zA-Z0-9_-]{11})/
];
for (const pattern of patterns) {
const match = url.match(pattern);
if (match && match[1]) return match[1];
}
return null;
}
function playStream(streamUrl, playBtn) {
if (!streamUrl) {
alert('Failed to start playback');
return;
}
log('Playing: ' + streamUrl);
const wrapper = document.createElement('div');
wrapper.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;z-index:99999;background:#000;display:flex;flex-direction:column;';
const closeBtn = document.createElement('button');
closeBtn.textContent = '✕';
closeBtn.style.cssText = 'position:absolute;top:20px;right:20px;width:50px;height:50px;background:rgba(0,0,0,0.7);color:#fff;border:2px solid #fff;border-radius:50%;font-size:32px;cursor:pointer;z-index:100000;display:flex;align-items:center;justify-content:center;transition:all 0.3s;';
closeBtn.onmouseover = () => { closeBtn.style.background = 'rgba(255,0,0,0.8)'; closeBtn.style.transform = 'scale(1.1)'; };
closeBtn.onmouseout = () => { closeBtn.style.background = 'rgba(0,0,0,0.7)'; closeBtn.style.transform = 'scale(1)'; };
const resetBtn = () => { if (playBtn) { playBtn.textContent = '▶'; playBtn.disabled = false; } };
const close = () => { wrapper.remove(); resetBtn(); document.removeEventListener('keydown', onEsc); };
closeBtn.onclick = close;
const onEsc = (e) => { if (e.key === 'Escape') close(); };
document.addEventListener('keydown', onEsc);
wrapper.appendChild(closeBtn);
const videoContainer = document.createElement('div');
videoContainer.style.cssText = 'flex:1;background:#000;display:flex;justify-content:center;align-items:center;position:relative;';
const iframe = document.createElement('iframe');
iframe.src = streamUrl;
iframe.style.cssText = 'width:100%;height:100%;border:none;';
iframe.allow = 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; fullscreen';
iframe.allowFullscreen = true;
videoContainer.appendChild(iframe);
wrapper.appendChild(videoContainer);
document.body.appendChild(wrapper);
}
function createPlayButton() {
const playBtn = document.createElement('button');
playBtn.textContent = '▶';
playBtn.title = 'Play Fullscreen';
playBtn.style.cssText = 'position:fixed;bottom:20px;right:20px;width:60px;height:60px;background:linear-gradient(135deg,#FF0000,#CC0000);color:#fff;border:2px solid #FF0000;border-radius:50%;cursor:pointer;font-size:28px;font-weight:bold;z-index:9998;display:flex;align-items:center;justify-content:center;box-shadow:0 4px 12px rgba(0,0,0,0.5);transition:all 0.3s;';
playBtn.onmouseover = () => { playBtn.style.transform = 'scale(1.15)'; playBtn.style.boxShadow = '0 6px 16px rgba(255,0,0,0.6)'; };
playBtn.onmouseout = () => { playBtn.style.transform = 'scale(1)'; playBtn.style.boxShadow = '0 4px 12px rgba(0,0,0,0.5)'; };
playBtn.onclick = () => {
playBtn.textContent = '⏳';
playBtn.disabled = true;
// FIX 1: Grab the URL inside the onclick event
const currentUrl = window.location.href;
const videoId = extractYouTubeVideoId(currentUrl);
if (!videoId) {
log('No video ID found at: ' + currentUrl);
playBtn.textContent = '▶';
playBtn.disabled = false;
return;
}
const streamUrl = 'https://www.youtube-nocookie.com/embed/' + videoId + '?autoplay=1';
log('Playing YouTube: ' + videoId);
playStream(streamUrl, playBtn);
};
document.body.appendChild(playBtn);
// FIX 2: Check URL visibility and poll for dynamic changes
function checkUrl() {
const videoId = extractYouTubeVideoId(window.location.href);
playBtn.style.display = videoId ? 'flex' : 'none';
}
checkUrl();
let lastUrl = window.location.href;
setInterval(() => {
if (window.location.href !== lastUrl) {
lastUrl = window.location.href;
checkUrl();
}
}, 500);
}
createPlayButton();
log('YouTube Player loaded - one-click fullscreen playback');
})();