PT: retry TikTok embeds that hit overload-protect (up to 3 times)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
root
2026-10-19 20:57:25 +00:00
parent 111ec08c7d
commit 04476732db

View File

@@ -548,28 +548,48 @@
</div>
</section>
<script>
/* تحميل فيديوهات تيك توك بالتدريج (واحد واحد وقت ظهوره) لتفادي overload-protect */
/* تحميل فيديوهات تيك توك بالتدريج (واحد واحد وقت ظهوره) + إعادة محاولة لو تيك توك رفض (overload-protect) */
(function(){
const items=[].slice.call(document.querySelectorAll('.tiktok-lazy'));
if(!items.length) return;
const queue=[]; let busy=false;
const MAX_TRIES=3;
function build(cite,id){
const bq=document.createElement('blockquote');
bq.className='tiktok-embed';
bq.setAttribute('cite',cite);
bq.setAttribute('data-video-id',id);
bq.style.cssText='max-width:100%;min-width:260px;';
bq.appendChild(document.createElement('section'));
return bq;
}
function load(job){
const holder=job.holder;
holder.innerHTML='';
holder.appendChild(build(job.cite,job.id));
const sc=document.createElement('script');
sc.async=true; sc.src='https://www.tiktok.com/embed.js?'+Date.now();
document.body.appendChild(sc);
/* بعد ما يخلص التحميل: لو الإطار قصير (رسالة خطأ) أعد المحاولة */
setTimeout(function(){
const fr=holder.querySelector('iframe');
const failed=!fr||fr.offsetHeight<300;
if(failed&&job.tries<MAX_TRIES){ job.tries++; queue.push(job); }
busy=false; next();
},job.tries===0?1500:5000*job.tries);
}
function next(){
if(busy||!queue.length) return;
busy=true;
const el=queue.shift();
const bq=document.createElement('blockquote');
bq.className='tiktok-embed';
bq.setAttribute('cite',el.dataset.cite);
bq.setAttribute('data-video-id',el.dataset.videoId);
bq.style.cssText='max-width:100%;min-width:260px;';
bq.appendChild(document.createElement('section'));
el.replaceWith(bq);
const sc=document.createElement('script');
sc.async=true; sc.src='https://www.tiktok.com/embed.js';
document.body.appendChild(sc);
setTimeout(function(){busy=false;next();},900);
load(queue.shift());
}
function enqueue(el){
const holder=document.createElement('div');
holder.style.width='100%';
el.replaceWith(holder);
queue.push({holder:holder,cite:el.dataset.cite,id:el.dataset.videoId,tries:0});
next();
}
function enqueue(el){ if(queue.indexOf(el)<0){queue.push(el);next();} }
if('IntersectionObserver' in window){
const io=new IntersectionObserver(function(es){
es.forEach(function(e){ if(e.isIntersecting){ io.unobserve(e.target); enqueue(e.target);} });