Utente:Sanjilops/monobook.js: differenze tra le versioni
Vai alla navigazione
Vai alla ricerca
Contenuto aggiunto Contenuto cancellato
Nessun oggetto della modifica |
Nessun oggetto della modifica |
||
Riga 13: | Riga 13: | ||
if (wgPageName == "Utente:Sanjilops/sandbox") gif_hack(); |
if (wgPageName == "Utente:Sanjilops/sandbox") gif_hack(); |
||
disable_search_thumb = true; |
|||
search_fix(); |
|||
/* Funzioni dell'editor */ |
/* Funzioni dell'editor */ |
||
Riga 229: | Riga 227: | ||
return; |
return; |
||
} |
} |
||
} |
|||
/* Mostra thumbnail delle immagini nella ricerca */ |
|||
function search_fix() { |
|||
if (wgPageName != "Speciale:Ricerca") return false; |
|||
var links = getElementsByClass(document, 'mw-search-result-title', 'a'); |
|||
var titles = new Array(), image_titles = new Array(), image_links = new Array(); |
|||
for (var i = 0; i < links.length; i++) { |
|||
titles.push(getText(links[i])); |
|||
if (/^File:/i.test(getText(links[i]))) { |
|||
image_titles.push(getText(links[i])); |
|||
image_links.push(links[i]); |
|||
} |
|||
} |
|||
var httpRequest = createRequest(); |
|||
httpRequest.onreadystatechange = function () { Do(httpRequest, id); return; } |
|||
var param = "format=xml&action=query&prop=info%7" + "Cimageinfo&iiprop=url&iiurlwidth=50&titles=" + encodeURIComponent(titles.join('|')); |
|||
httpRequest.open('POST', wgServer + wgScriptPath + "/api.php", true); |
|||
httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); |
|||
httpRequest.setRequestHeader('Content-Length', param.length); |
|||
var id = setTimeout(function() {httpRequest.abort();}, 30000); |
|||
httpRequest.send(param); |
|||
return; |
|||
function Do(o, id) { |
|||
if (o.readyState != 4) return; |
|||
clearTimeout(id); |
|||
if (o.status != 200) { alert("Status:" + o.status); return; } |
|||
if (o.responseXML == null) return; |
|||
if (o.responseXML.normalize) o.responseXML.normalize(); |
|||
if (o.responseXML.getElementsByTagName('ii').length == 0) return false; |
|||
var page = o.responseXML.getElementsByTagName('page'); |
|||
var url = '', ii, img, l; |
|||
for (var i = 0; i < page.length; i++) { |
|||
l = titles.indexOf(page[i].getAttribute('title')); |
|||
if (l == -1) continue; |
|||
/* rimuove risultati eliminati */ |
|||
if (page[i].getAttribute('missing') != undefined) { |
|||
links[l].style.color = "rgb(50, 50, 50)"; |
|||
links[l].style.textDecoration = "line-through"; |
|||
links[l].style.fontSize = "50%"; |
|||
links[l].title = links[l].title + " (pagina inesistente)"; |
|||
getElementsByClass(document, 'searchresult', 'div')[l].style.display = 'none'; |
|||
continue; |
|||
} |
|||
/* anteprima immagini */ |
|||
if (page[i].getAttribute('ns') != '6') continue; |
|||
ii = page[i].getElementsByTagName('ii')[0]; |
|||
if (ii == undefined) continue; |
|||
if (ii.getAttribute("thumbheight") == '-1') continue; // non è un'immagine |
|||
url = ii.getAttribute("thumburl"); |
|||
if (url == null) continue; |
|||
img = document.createElement('img'); |
|||
img.src = url; |
|||
img.alt = ''; |
|||
img.width = ii.getAttribute("thumbwidth"); |
|||
img.height = ii.getAttribute("thumbheight"); |
|||
img.style.marginRight = "3px"; |
|||
l = image_titles.indexOf(page[i].getAttribute('title')); |
|||
image_links[l].insertBefore(img, image_links[l].firstChild); |
|||
} |
|||
return; |
|||
} |
|||
} |
} |