|
|
| Línea 1: |
Línea 1: |
|
| |
|
|
| |
| /* SHIBUSEN-ALLPAGES-INDEX-V1:START */
| |
| (function () {
| |
| 'use strict';
| |
| function init() {
| |
| if (typeof mw === 'undefined' || !mw.loader) { return; }
| |
| var root=document.getElementById('shibusen-allpages-root');
| |
| if (!root) { return; }
| |
| mw.loader.using(['mediawiki.api','mediawiki.util']).then(function () {
| |
| var api=new mw.Api(), items=[],cursor=null,page=0,letter='Todos',query='';
| |
| var collator=new Intl.Collator('es',{numeric:true,sensitivity:'base'});
| |
| function el(tag,cl,txt){var e=document.createElement(tag);if(cl)e.className=cl;if(txt!==undefined)e.textContent=txt;return e;}
| |
| function normalize(s){return String(s||'').normalize('NFD').replace(/[\u0300-\u036f]/g,'').toLocaleLowerCase('es');}
| |
| function fetchPages(){
| |
| var args={action:'query',list:'allpages',apnamespace:0,apfilterredir:'nonredirects',aplimit:'max',formatversion:2};
| |
| if(cursor)args.apcontinue=cursor;
| |
| return api.get(args).then(function(result){
| |
| (result.query&&result.query.allpages||[]).forEach(function(x){if(x.title)items.push(x.title);});
| |
| cursor=(result.continue&&result.continue.apcontinue)||null;
| |
| if(cursor&&items.length<5000)return fetchPages();
| |
| return items;
| |
| });
| |
| }
| |
| function render(){
| |
| var result=items.filter(function(s){return normalize(s).includes(normalize(query))&&(letter==='Todos'||(letter==='#'? !/^[a-z]/i.test(normalize(s)) : normalize(s).toUpperCase().startsWith(letter)));});
| |
| result.sort(collator.compare);
| |
| var max=Math.max(1,Math.ceil(result.length/48));page=Math.min(page,max-1);
| |
| status.textContent=result.length.toLocaleString('es-AR')+' artículos encontrados de '+items.length.toLocaleString('es-AR');
| |
| grid.replaceChildren();
| |
| result.slice(page*48,(page+1)*48).forEach(function(t){var a=el('a','swgi-item',t);a.href=mw.util.getUrl(t);grid.appendChild(a);});
| |
| if(!result.length)grid.appendChild(el('p','','No se encontraron artículos con ese filtro.'));
| |
| pager.replaceChildren();
| |
| if(max>1){var prev=el('button','','← Anterior');prev.disabled=page===0;prev.onclick=function(){page--;render();};pager.appendChild(prev);pager.appendChild(el('span','','Página '+(page+1)+' de '+max));var next=el('button','','Siguiente →');next.disabled=page>=max-1;next.onclick=function(){page++;render();};pager.appendChild(next);}
| |
| }
| |
| root.replaceChildren();
| |
| var tools=el('div','swgi-tools');var input=el('input','swgi-input');input.type='search';input.placeholder='Filtrar por nombre de artículo...';input.setAttribute('aria-label','Buscar por nombre en el índice general');input.oninput=function(){query=input.value;page=0;render();};tools.appendChild(input);root.appendChild(tools);
| |
| var letters=el('nav','swgi-letters');letters.setAttribute('aria-label','Filtrar artículos por letra');
| |
| ['Todos','#'].concat('ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('')).forEach(function(name){var b=el('button','swgi-letter',name);b.type='button';b.setAttribute('aria-pressed',name==='Todos'?'true':'false');b.onclick=function(){letter=name;page=0;Array.prototype.forEach.call(letters.children,function(c){c.setAttribute('aria-pressed',c===b?'true':'false');});render();};letters.appendChild(b);});root.appendChild(letters);
| |
| var status=el('div','swgi-status','Cargando índice...');status.setAttribute('aria-live','polite');root.appendChild(status);
| |
| var grid=el('div','swgi-grid');root.appendChild(grid);
| |
| var pager=el('div','swgi-pager');root.appendChild(pager);
| |
| fetchPages().then(render).catch(function(err){root.replaceChildren();var a=el('a','','El índice dinámico no está disponible; abrir todas las páginas →');a.href=mw.util.getUrl('Special:AllPages');root.appendChild(a);});
| |
| });
| |
| }
| |
| if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init, { once: true }); } else { init(); }
| |
| })();
| |
| /* SHIBUSEN-ALLPAGES-INDEX-V1:END */
| |