/* SAN AVELIO - PROFILE VIEW + UNIVERSAL AVATAR v10 Load AFTER v6 and v7. - "View" in native editor returns to the custom dossier. - Universal avatar: use best native Rusff source and NEVER upscale it. - Does not modify 12993 / 70119 / HTML-bottom. */ (function(){ 'use strict'; if(!/\/profile\.php$/i.test(location.pathname)) return; function params(u){ try{return new URL(u||location.href,location.href).searchParams}catch(e){return new URLSearchParams()} } function idFrom(u){return params(u).get('id')||''} function management(u){ var p=params(u); return p.has('section')||p.has('action')||p.has('edit')||p.has('p')|| p.has('page')||p.has('mode')||p.has('form'); } function plainView(){return !management(location.href)} function installViewGuard(){ document.addEventListener('click',function(e){ var a=e.target&&e.target.closest?e.target.closest('a[href]'):null; if(!a)return; var u; try{u=new URL(a.href,location.href)}catch(_){return} if(!/\/profile\.php$/i.test(u.pathname))return; var txt=(a.textContent||'').replace(/\s+/g,' ').trim().toLowerCase(); if(txt!=='\u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440')return; var id=idFrom(a.href)||idFrom(location.href); if(!id)return; e.preventDefault(); e.stopImmediatePropagation(); location.href='/profile.php?id='+encodeURIComponent(id)+'&sa_dossier=1'; },true); } function addCss(){ if(document.getElementById('sa-view-avatar-v10'))return; var s=document.createElement('style');s.id='sa-view-avatar-v10'; s.textContent=` #sa-dossier-clean .portrait{ min-height:390px!important; display:flex!important;align-items:center!important;justify-content:center!important; padding:26px 24px!important;box-sizing:border-box!important;overflow:hidden!important; } #sa-dossier-clean .portrait img.sa-avatar-native{ position:relative!important;inset:auto!important; display:block!important;flex:none!important; min-width:0!important;min-height:0!important; object-fit:contain!important; transform:none!important;scale:1!important;filter:none!important; image-rendering:auto!important; border:1px solid rgba(199,154,79,.55)!important; padding:5px!important;box-sizing:content-box!important; background:rgba(4,24,27,.82)!important; box-shadow:0 14px 32px rgba(0,0,0,.30)!important; } `; document.head.appendChild(s); } function score(im,target){ if(!im||!im.src||im===target||(im.closest&&im.closest('#sa-dossier-clean')))return -1; var src=im.currentSrc||im.src||'', r=0; if(im.closest&&im.closest('.pa-avatar'))r+=1500; if(/avatar/i.test((im.className||'')+' '+src))r+=700; var w=im.naturalWidth||0,h=im.naturalHeight||0; if(w>=120&&h>=160)r+=400; r+=Math.min(w*h,1000000)/1000; return r; } function bestNative(target){ var main=document.getElementById('pun-main');if(!main)return null; var imgs=main.querySelectorAll('img'),best=null,bestScore=-1; for(var i=0;ibestScore){best=imgs[i];bestScore=sc} } return best; } function sizeOneToOne(target){ var nw=target.naturalWidth||0,nh=target.naturalHeight||0; if(!nw||!nh)return; /* NEVER upscale. 180x250 is only the maximum display box. */ var k=Math.min(1,180/nw,250/nh); var w=Math.max(1,Math.round(nw*k)),h=Math.max(1,Math.round(nh*k)); target.style.setProperty('width',w+'px','important'); target.style.setProperty('height',h+'px','important'); target.style.setProperty('max-width','none','important'); target.style.setProperty('max-height','none','important'); } function avatar(){ if(!plainView())return; var d=document.getElementById('sa-dossier-clean');if(!d)return; addCss(); var target=d.querySelector('.portrait img,.sa-portrait img,.avatar img'); if(!target)return; var native=bestNative(target); if(native){ var src=native.currentSrc||native.src||''; if(src&&target.src!==src)target.src=src; } target.classList.add('sa-avatar-native'); if(target.complete)sizeOneToOne(target); if(!target.dataset.saV10Load){ target.dataset.saV10Load='1'; target.addEventListener('load',function(){sizeOneToOne(target)}); } } function run(){avatar()} var mo=new MutationObserver(run); function start(){ installViewGuard();run(); mo.observe(document.documentElement,{childList:true,subtree:true}); setTimeout(run,200);setTimeout(run,700);setTimeout(run,1500); } if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',start,{once:true});else start(); })();