在名媒国际平台发声、展示属于你的风彩
美国总统特朗普机场对媒体透露对委内瑞拉和伊朗局势的动作
/* =========================
CM26 JS (FIXED)
- hero carousel
- multi-source player plays
- preview player
- global mutual exclusion (single authority)
========================= */
(function(){
/* ---------- Hero carousel ---------- */
document.querySelectorAll('.cm26-hero').forEach(hero=>{
const imgs = Array.from(hero.querySelectorAll('img'));
if(!imgs.length) return;
let i = imgs.findIndex(x=>x.classList.contains('on'));
if(i < 0) i = 0;
const interval = parseInt(hero.getAttribute('data-interval') || '4000', 10);
setInterval(()=>{
imgs[i].classList.remove('on');
i = (i + 1) % imgs.length;
imgs[i].classList.add('on');
}, interval);
});
/* ---------- Utilities ---------- */
function isVideo(u){
return /\.(mp4|webm|ogg)(\?.*)?$/i.test(u||'');
}
function cap(k){ return k ? (k.charAt(0).toUpperCase() + k.slice(1)) : ''; }
/* ✅ Single authority mutual exclusion
- Stop native audio/video
- Unload multi-source iframes/videos by clearing stages
- (iframe cannot be reliably paused cross-origin, so unloading is correct) */
function cm26StopAllMedia(exceptEl){
// Stop audio/video
document.querySelectorAll('audio,video').forEach(m=>{
if(exceptEl && m === exceptEl) return;
try{ m.pause(); m.currentTime = 0; }catch(e){}
});
// Unload multi-source embeds
document.querySelectorAll('.cm26-embed-stage').forEach(stage=>{
// if except is inside this stage, keep it
if(exceptEl && stage.contains(exceptEl)) return;
stage.innerHTML = '';
const shell = stage.closest('.cm26-multi-shell');
if(shell) shell.classList.remove('playing');
});
}
/* Also enforce: whenever ANY audio/video starts playing, stop others */
document.addEventListener('play', function(e){
const t = e.target;
if(!t) return;
if(t.tagName === 'AUDIO' || t.tagName === 'VIDEO'){
cm26StopAllMedia(t);
}
}, true);
/* ---------- Multi-source player (4 sources) ---------- */
document.querySelectorAll('.cm26-multi').forEach(block=>{
if(block.dataset.inited) return;
block.dataset.inited = '1';
const shell = block.querySelector('.cm26-multi-shell');
const stage = block.querySelector('.cm26-embed-stage');
const cover = block.querySelector('.cm26-multi-cover');
const caption = block.querySelector('.cm26-multi-caption');
const buttons = block.querySelectorAll('.cm26-multi-switch button');
let current = block.dataset.default || 'local';
function setPreview(key){
const img = block.dataset['preview' + cap(key)] || '';
cover.style.backgroundImage = img ? ("url('" + img + "')") : 'none';
caption.textContent = block.dataset['caption' + cap(key)] || '';
buttons.forEach(b=>b.classList.toggle('on', b.dataset.src === key));
shell.classList.remove('playing');
stage.innerHTML = '';
}
function playCurrent(){
cm26StopAllMedia(); // unload everything else first
const url = block.dataset[current];
if(!url) return;
stage.innerHTML = '';
if(isVideo(url)){
const v = document.createElement('video');
v.src = url;
v.controls = true;
v.playsInline = true;
v.setAttribute('controlslist','nodownload noplaybackrate noremoteplayback');
v.setAttribute('disablepictureinpicture','');
stage.appendChild(v);
// ensure this video becomes the active one
v.addEventListener('play', ()=>cm26StopAllMedia(v), {once:true});
v.play().catch(()=>{});
}else{
const f = document.createElement('iframe');
f.src = url;
f.allow = 'autoplay; encrypted-media; fullscreen; picture-in-picture';
stage.appendChild(f);
}
shell.classList.add('playing');
}
buttons.forEach(btn=>{
btn.addEventListener('click', ()=>{
current = btn.dataset.src;
setPreview(current);
});
});
cover.addEventListener('click', playCurrent);
setPreview(current);
});
/* ---------- Preview player (landscape/portrait) ---------- */
(function(){
const wrap = document.getElementById('cm26PreviewWrap');
const video = document.getElementById('cm26PreviewVideo');
const cover = document.getElementById('cm26PreviewCover');
const toggle = document.getElementById('cm26PreviewToggle');
if(!wrap || !video || !cover || !toggle) return;
cover.addEventListener('click', ()=>{
cm26StopAllMedia(video);
wrap.classList.add('playing');
video.play().catch(()=>{});
});
video.addEventListener('play', ()=>{
wrap.classList.add('playing');
cm26StopAllMedia(video);
});
video.addEventListener('pause', ()=>{
if(video.currentTime < (video.duration || 0) - 0.5){
wrap.classList.remove('playing');
}
});
toggle.addEventListener('click', ()=>{
const isPortrait = wrap.classList.contains('portrait');
if(isPortrait){
wrap.classList.remove('portrait');
wrap.classList.add('landscape');
toggle.textContent = '切换为竖屏';
toggle.classList.remove('active');
}else{
wrap.classList.remove('landscape');
wrap.classList.add('portrait');
toggle.textContent = '切换为横屏';
toggle.classList.add('active');
}
});
})();
/* ---------- HeyGen overlay blocker (your original logic preserved) ---------- */
(function(){
const wrap = document.querySelector('.ytVideoWrapper');
const blk = document.getElementById('dl-block');
if(!wrap || !blk) return;
function placeBlock(){
const r = wrap.getBoundingClientRect();
const w = r.width, h = r.height;
const bw = w * 0.20;
const bh = h * 0.24;
Object.assign(blk.style, {width:bw+'px', height:bh+'px', right:'0', bottom:'0'});
}
try{
new ResizeObserver(placeBlock).observe(wrap);
}catch(e){
window.addEventListener('resize', placeBlock);
}
placeBlock();
})();
/* Soft protection: right click & some keys (kept minimal to avoid site-wide side effects) */
document.addEventListener('contextmenu', e => e.preventDefault());
document.addEventListener('keydown', e => {
const k = (e.key || '').toLowerCase();
if ((e.ctrlKey||e.metaKey) && ['s','u','p'].includes(k)) e.preventDefault();
});
})();