Utensa:Alex brollo/vector.js
Ocio: Daspò ver salvà, podaria esare neçesario snetare ła cache dal propio navegadore web par vedare i canbiamenti.
- Firefox / Safari: tegner strucà el boton de łe letare grande Shift e schiciare sora Ricarga, o se nò struca Ctrl-F5 o Ctrl-R (⌘-R so Mac)
- Google Chrome: strucare Ctrl-Shift-R (⌘-Shift-R so on Mac)
- Internet Explorer / Edge: tegner strucà el boton Ctrl e schiciare so Ajorna, o sinò Ctrl-F5
- Opera: Va in tel Menu → Inpostasion (Opera → Prefarense so on Mac) e pò in Privacy & sicuresa → Sneta dati del navegadore → Imajini e file in te ła cache.
//creazione di un tattoo che richiama la funzione di cattura e prenotazione modifica testo selezionato
var tattoo1="<div style=\"position:fixed;background-color:transparent;bottom:10px;right:10px;z-index:1000;display:block\"><A HREF=\"javascript:getSelect()\"><IMG SRC=\"http://upload.wikimedia.org/wikipedia/commons/f/f9/Edit-find-replace.svg\" WIDTH=\"30\" HEIGHT=\"30\" ALT=\"Prenotazione edit di testo selezionato\"></IMG></A></div>";
document.getElementById("content").innerHTML += tattoo1;
// creazione variabili di base
var urlEdit=jQuery('#ca-edit a').attr("href");
var listaEdit={};
// cattura testo selezionato e apertura di un prompt per l'inserimento della modifica
function GetSelectedText () {
if (window.getSelection) { // all browsers, except IE before version 9
var range = window.getSelection ();
edit1=range.toString ();
}
else {
if (document.selection.createRange) { // Internet Explorer
var range = document.selection.createRange();
edit1=range.text;
}
}
if (edit1.length > 0) {edit2=prompt("Sostituisci:\n"+edit1+"\ncon:",edit1);
return [edit1,edit2];
}
}
// richiamo della funzione di cattura e aggiornamento del link di Modifica pagina
function getSelect() {
coppia=GetSelectedText();
listaEdit[coppia[0]]=coppia[1];
uri=urlEdit+"&hotEdit="+encodeURI(JSON.stringify(listaEdit));
jQuery('#ca-edit a').attr("href",uri);
}
/* Hot Edit: esegue la lista di replaceAll ricevuta via URI
*/
function HotEditReplace() {
if (mw.config.get('wgAction') == "edit") {
listaEdit=$.getUrlVar("hotEdit");
if (listaEdit !== undefined) {
listaEdit=JSON.parse(decodeURI(listaEdit));
text=$("#wpTextbox1").text();
for (el in listaEdit)
{text=replaceAll(text,el,listaEdit[el]);
}
$("#wpTextbox1").text(text);
}
}
}
$(document).ready(HotEditReplace);
/* estensione jQuery che aggiunge la funzione getUrlVar(), per recuperare il valore di un parametro dalla request
*
* da http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html
*/
$.extend({
getUrlVars: function(){
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
},
getUrlVar: function(name){
return $.getUrlVars()[name];
}
});
function replaceAll(testo,a,b) {
if (a==b) return testo;
if (a==="") return testo;
if (testo.count(a)===0) return testo;
if (testo.count(a)==1) {testo=testo.replace(a,b);return testo;}
while (testo.indexOf(a)>-1) {
testo=testo.replace(a,b);}
return testo;
}
/* aggiunge un metodo conta all'oggetto String.
Restistuisce il numero di sottostringhe stringa contenute nella stringa principale. Il confronto è sensibile
alle maiuscole/minuscole. */
String.prototype.count = function(stringa) {
var n=0;
var testo=this;
while (testo.indexOf(stringa)>-1) {
n=n+1;
testo=testo.replace(stringa,"");
}
return n;
};