// À¯Æ©ºê ID ÃßÃâ
function getYoutubeVideoId(url) {
const watchRegex = /[?&]v=([^&]+)/;
const shortsRegex = /\/shorts\/([^?&]+)/;
const watchMatch = url.match(watchRegex);
if (watchMatch) return watchMatch[1];
const shortsMatch = url.match(shortsRegex);
if (shortsMatch) return shortsMatch[1];
return null;
}
// ½æ³×ÀÏ URL »ý¼º
function createThumbnailUrl(id) {
return id ? `https://img.youtube.com/vi/${id}/0.jpg` : null;
}
// ÀÓº£µå URL »ý¼º
function createEmbedUrl(id) {
return id ? `https://www.youtube.com/embed/${id}?autoplay=1&mute=1` : null;
}
let ytScrollY;
function lockScroll() {
ytScrollY = window.scrollY;
document.body.style.position = 'fixed';
document.body.style.top = `-${ytScrollY}px`; document.body.style.width = '100%';
}
function unlockScroll() {
const html = document.documentElement;
const prevScrollBehavior = html.style.scrollBehavior;
html.style.scrollBehavior = 'auto';
document.body.style.position = '';
document.body.style.top = '';
document.body.style.width = '';
window.scrollTo(0, ytScrollY);
setTimeout(() => {
html.style.scrollBehavior = prevScrollBehavior || '';
}, 0);
}
// ÇÁ·¹ÀÓ ´Ý±â
function closeFrame(e) {
e.remove();
unlockScroll();
}
// ÇÁ·¹ÀÓ ¿±â
function openFrame(embedSrc) {
const html = `
`;
document.querySelector('.contribution-form')?.insertAdjacentHTML('beforeend', html);
lockScroll();
}
// ½æ³×ÀÏ ·¹ÀÌ¾î »ý¼º
function createLayer(imgSrc, embedSrc) {
return `
`;
}
// DOM ·Îµå ½Ã ½ÇÇà
window.addEventListener("DOMContentLoaded", () => {
const videoData = []; // °¢ Ç׸ñº° À¯Æ©ºê Á¤º¸ ÀúÀå
// ½æ³×ÀÏ »ðÀÔ ¹× Á¤º¸ ¼öÁý
document.querySelectorAll('.gallery_etc > font').forEach((el, idx) => {
const text = el.textContent.trim();
if (text.startsWith("À¯Æ©ºêÁÖ¼Ò :")) {
const youtubeUrl = text.replace("À¯Æ©ºêÁÖ¼Ò : ", "").replace(/\[|\]/g, "").trim();
const youtubeId = getYoutubeVideoId(youtubeUrl);
const thumbnailSrc = createThumbnailUrl(youtubeId);
const embedSrc = createEmbedUrl(youtubeId);
const html = createLayer(thumbnailSrc, embedSrc);
el.insertAdjacentHTML('afterbegin', html);
// ³»¿¡ .gallery_title ¾ø´Â °æ¿ì¸¸ [] Á¦°Å
const td = el.closest('td');
if (td && !td.querySelector('.gallery_title')) {
td.innerHTML = td.innerHTML.replace(/\[|\]/g, '');
}
videoData[idx] = { embedSrc };
}
});
// Á¦¸ñ ¸µÅ© Ŭ¸¯ ¹æÁö + Ŭ¸¯ ½Ã ¿µ»ó Àç»ý
let isAdmin = document.querySelector('.board_admin_bgcolor')
if(!isAdmin){
document.querySelectorAll('.gallery_subject a').forEach((aTag, idx) => {
aTag.removeAttribute('href');
aTag.style.pointerEvents = 'auto';
aTag.style.cursor = 'pointer';
const data = videoData[idx];
if (data && data.embedSrc) {
aTag.addEventListener('click', () => {
openFrame(data.embedSrc);
});
}
});
}
// ½æ³×ÀÏ Å¬¸¯ ½Ã ¿µ»ó Àç»ý
document.querySelectorAll('.thumbnail-wrap').forEach((el) => {
el.addEventListener('click', () => {
const embedSrc = el.getAttribute('data-embed');
if (embedSrc) openFrame(embedSrc);
});
});
}); |