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:
@@ -548,28 +548,48 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<script>
|
<script>
|
||||||
/* تحميل فيديوهات تيك توك بالتدريج (واحد واحد وقت ظهوره) لتفادي overload-protect */
|
/* تحميل فيديوهات تيك توك بالتدريج (واحد واحد وقت ظهوره) + إعادة محاولة لو تيك توك رفض (overload-protect) */
|
||||||
(function(){
|
(function(){
|
||||||
const items=[].slice.call(document.querySelectorAll('.tiktok-lazy'));
|
const items=[].slice.call(document.querySelectorAll('.tiktok-lazy'));
|
||||||
if(!items.length) return;
|
if(!items.length) return;
|
||||||
const queue=[]; let busy=false;
|
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(){
|
function next(){
|
||||||
if(busy||!queue.length) return;
|
if(busy||!queue.length) return;
|
||||||
busy=true;
|
busy=true;
|
||||||
const el=queue.shift();
|
load(queue.shift());
|
||||||
const bq=document.createElement('blockquote');
|
}
|
||||||
bq.className='tiktok-embed';
|
function enqueue(el){
|
||||||
bq.setAttribute('cite',el.dataset.cite);
|
const holder=document.createElement('div');
|
||||||
bq.setAttribute('data-video-id',el.dataset.videoId);
|
holder.style.width='100%';
|
||||||
bq.style.cssText='max-width:100%;min-width:260px;';
|
el.replaceWith(holder);
|
||||||
bq.appendChild(document.createElement('section'));
|
queue.push({holder:holder,cite:el.dataset.cite,id:el.dataset.videoId,tries:0});
|
||||||
el.replaceWith(bq);
|
next();
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
function enqueue(el){ if(queue.indexOf(el)<0){queue.push(el);next();} }
|
|
||||||
if('IntersectionObserver' in window){
|
if('IntersectionObserver' in window){
|
||||||
const io=new IntersectionObserver(function(es){
|
const io=new IntersectionObserver(function(es){
|
||||||
es.forEach(function(e){ if(e.isIntersecting){ io.unobserve(e.target); enqueue(e.target);} });
|
es.forEach(function(e){ if(e.isIntersecting){ io.unobserve(e.target); enqueue(e.target);} });
|
||||||
|
|||||||
Reference in New Issue
Block a user