User:Marcelobbr/monobook.js
From Wikipedia, the free encyclopedia
If a message on your talk page led you here, please be wary of who left it. The code below could contain malicious content capable of compromising your account; if your account appears to be compromised, it will be blocked. If you are unsure whether the code is safe, you can ask at the appropriate village pump.
Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.
/* Category watch ([[User:ais523/catwatch.js]]); adds entries on the watchlist if a page is added to a category (and is still in the category when the watchlist is checked). The entry will only appear if there is another page on the watchlist edited that day (if the addition was the only change on that day, it's neglected). The recategorisation of a page in a watched category will also trigger the watching, even if it's a different category that's added or removed (unless the watched category is removed); removals from the watched category can't be detected. Categories with more than 100 elements won't be watched for server-load reasons. */ //<pre><nowiki> var cwwpajax; // From [[WP:US]] mainpage (wpajax renamed to cwwpajax) cwwpajax={ download:function(bundle) { // mandatory: bundle.url // optional: bundle.onSuccess (xmlhttprequest, bundle) // optional: bundle.onFailure (xmlhttprequest, bundle) // optional: bundle.otherStuff OK too, passed to onSuccess and onFailure var x = window.XMLHttpRequest ? new XMLHttpRequest() : window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : false; if (x) { x.onreadystatechange=function() { x.readyState==4 && cwwpajax.downloadComplete(x,bundle); }; x.open("GET",bundle.url,true); x.send(null); } return x; }, downloadComplete:function(x,bundle) { x.status==200 && ( bundle.onSuccess && bundle.onSuccess(x,bundle) || true ) || ( bundle.onFailure && bundle.onFailure(x,bundle) || alert(x.statusText)); } }; // Example: // function dlComplete(xmlreq, data) { // alert(data.message + xmlreq.responseText); // } // cwwpajax.download({url:'http://en.wikipedia.org/w/index.php?title=Thresher&action=raw', // onSuccess: dlComplete, message: "Here's what we got:\n\n" }); // End of [[WP:US]] quote function cwOntoWatchlist(xmlreq, data) { var a=xmlreq.responseText; var c=data.catname; var i; var diag=""; if(a.indexOf("<error>")!=-1) return; //cat is empty, nothing to do here if(a.indexOf("<category next=")!=-1) return; //cat has more than 100 elements, so the results will be misleading a=a.split("<timestamp>"); var latesttime=0; var latestpage=""; var temp, temp2; for(i in a) { temp=a[i].indexOf("</timestamp>"); if(temp!=-1) { temp=new Number(a[i].substr(0,temp)); if(temp>latesttime) { latesttime=temp; a[i]=a[i].substr(a[i].indexOf("<title>")+7); latestpage=a[i].substr(0,a[i].indexOf("</title>")); } } } a=document.getElementsByTagName("h4"); //get dates in the watchlist var monthname=new Array(); monthname['01']="January"; monthname['02']="February"; monthname['03']="March"; monthname['04']="April"; monthname['05']="May"; monthname['06']="June"; monthname['07']="July"; monthname['08']="August"; monthname['09']="September"; monthname['10']="October"; monthname['11']="November"; monthname['12']="December"; latesttime=new String(latesttime); temp=""+new Number(latesttime.substr(6,2))+" "+monthname[latesttime.substr(4,2)]+" "+latesttime.substr(0,4); i=a.length; while(i--) { if(a[i].innerHTML==temp) { diag+=a[i].innerHTML+":"; temp=a[i].nextSibling.firstChild; if(temp==null) temp=a[i].nextSibling.nextSibling.firstChild; while(temp!=null) { diag+=temp.tagname+"!"; if(temp.tagName!=null) if(temp.tagName.toLowerCase()=="li") { temp2=temp.innerHTML.match(/; ([0-9][0-9]):([0-9][0-9]) \. \./); temp2=new Number(temp2[1])*100+new Number(temp2[2]); diag+=temp2+","; if(temp2<new Number(latesttime.substr(8,4))) {temp2=temp; break;} } temp2=temp; temp=temp.nextSibling; if(temp==null) break; } temp=document.createElement("li"); if(temp2==null) {return;} if(a[i].nextSibling.firstChild!=null) // IE a[i].nextSibling.insertBefore(temp,temp2); else //Firefox a[i].nextSibling.nextSibling.insertBefore(temp,temp2); temp.innerHTML="(diff) (hist) . . <a href='http://en.wikipedia.org/wiki/Category:"+encodeURI(c)+ "'>Category:"+c+"</a>; "+latesttime.substr(8,2)+":"+latesttime.substr(10,2)+" . . (+ "+ "<a href='http://en.wikipedia.org/wiki/"+encodeURI(latestpage)+"'>"+latestpage+"</a> "+ "(<a href='http://en.wikipedia.org/w/index.php?title="+encodeURI(latestpage)+ "&diff=last'>last</a>))"; return; } } } var WatchedCategories; //prevent error if there isn't a cat-watchlist yet //An example of a query to check a category would be //http://en.wikipedia.org/w/query.php?what=category&cptitle=Wikipedia%20protected%20edit%20requests&cplimit=100&cpextended addOnloadHook(function(){ if(wgPageName=="Special:Watchlist") { if(WatchedCategories==undefined) { if(confirm("You don't have a category watchlist yet. Do you want to create one?")) location.href='http://en.wikipedia.org/w/index.php?title=User:'+wgUserName+ '/WatchedCategories.js&action=edit&preload=User:Ais523/WatchedCategoriesTemplate.js'; } else { var i; for(i in WatchedCategories) { var a=WatchedCategories[i]; cwwpajax.download({url:'http://en.wikipedia.org/w/query.php?what=category&cptitle='+encodeURI(a)+ '&cplimit=100&cpextended&format=xml', onSuccess:cwOntoWatchlist, catname:a}); } } } }); // include current user's category watchlist document.write('<script type="text/javascript" src="http://en.wikipedia.org' + '/w/index.php?title=User:'+wgUserName+'/WatchedCategories.js' + '&action=raw&ctype=text/javascript&dontcountme=s"></script>'); //</nowiki></pre> //[[Category:Wikipedia scripts]] // Script from [[User:Tra/userwatchlist.js]] importScript('User:Tra/userwatchlist.js'); //[[User:Tra/userwatchlist.js]] // Script from [[User:Tra/whatlinksherewatchlist.js]] importScript('User:Tra/whatlinksherewatchlist.js'); //[[User:Tra/whatlinksherewatchlist.js]] //Botões //var div=document.getElementById('editpage-specialchars'); //if ( div ) { // //} window.AddMyOwnButton=function(tbar, caption, href, imgsrc) { var ba = document.createElement('a'); ba.href = href; var img = document.createElement('img'); img.src = imgsrc; img.alt = caption; ba.appendChild(img); tbar.appendChild(ba); } window.myOwnEditButtons=function() { var tbdiv=document.getElementById('toolbar'); if ( tbdiv ) { tbdiv.appendChild(document.createTextNode(' ')); // Botao:{Categoria} AddMyOwnButton(tbdiv, 'categoria', 'javascript:document.editform.wpSummary.value=\'\+cat\';insertTags(\'[\[Categorie:\',\']]\',\'\');', 'http://upload.wikimedia.org/wikipedia/commons/1/11/Button_category.png'); // Botao:{iw} AddMyOwnButton(tbdiv, 'interwiki', 'javascript:document.editform.wpSummary.value=\'\+pt\';insertTags(\'[\[pt:\',\']]\',\'\');', 'http://upload.wikimedia.org/wikipedia/commons/3/3f/Button_en.png'); // Botao:autoDisambig caption = 'desambigtxt'; var badis = document.createElement('a'); badis.href = 'javascript:document.editform.wpSummary.value=\'v1\';insertTags(\'\{\{desambiguação\}\}\\n\\nPor \\\'\\\'\\\'\{\{subst:PAGENAME}}\\\'\\\'\\\' pode estar à procura de:\\n* \',\'\',\'\');'; var imgdis = document.createElement('img'); imgdis.src = 'http://upload.wikimedia.org/wikipedia/commons/6/62/Button_desambig.png'; imgdis.alt = caption; badis.appendChild(imgdis); tbdiv.appendChild(badis); // Botao:CaixaSucessao AddMyOwnButton(tbdiv, 'Caixa de sucessão', 'javascript:document.editform.wpSummary.value=\'+caixa de sucessão\';insertTags(\'\{\{Começa caixa\}\}\\n\{\{Caixa de sucessão\|\\n\|título = \\n\|anos = \\n\|antes = \\n\|depois = \\n\}\}\\n\{\{Termina caixa\}\}\\n\',\'\',\'\');', 'http://upload.wikimedia.org/wikipedia/commons/8/8f/Cs_icon.png'); // Botao:— AddMyOwnButton(tbdiv, 'MD', 'javascript:document.editform.wpSummary.value=document.editform.wpSummary.value+\'+— \';insertTags(\'—\',\'\',\'\');', 'http://pt.wikipedia.org/skins-1.5/common/images/button_hr.png'); // Botao:Ver tambem AddMyOwnButton(tbdiv, 'VT', 'javascript:document.editform.wpSummary.value=document.editform.wpSummary.value+\'+ver também \';insertTags(\'=={{Ver também}}==\\n\',\'\',\'\');', 'http://upload.wikimedia.org/wikipedia/commons/f/fc/Button_no_license.png'); // Botao:Links externos AddMyOwnButton(tbdiv, 'LE', 'javascript:document.editform.wpSummary.value=document.editform.wpSummary.value+\'+ligações externas \';insertTags(\'=={{Ligações externas}}==\\n\',\'\',\'\');', 'http://upload.wikimedia.org/wikipedia/commons/f/fc/Button_no_license.png'); // Botao:<strike> caption = '<s></s>'; var bas = document.createElement('a'); bas.href = 'javascript:insertTags(\'<s>\',\'</s>\',\'\');'; var imgs = document.createElement('img'); imgs.src = 'http://republico.estv.ipv.pt/~nmct/wikipedia/icons/button_strike.png'; imgs.alt = caption; bas.appendChild(imgs); tbdiv.appendChild(bas); // Botao:<tt> caption = '<tt></tt>'; var batt = document.createElement('a'); batt.href = 'javascript:insertTags(\'<tt>\',\'</tt>\',\'\');'; var imgtt = document.createElement('img'); imgtt.src = 'http://republico.estv.ipv.pt/~nmct/wikipedia/icons/button_tt.png'; imgtt.alt = caption; batt.appendChild(imgtt); tbdiv.appendChild(batt); // Botao:<small> caption = '<small></small>'; var basm = document.createElement('a'); basm.href = 'javascript:insertTags(\'<small>\',\'</small>\',\'\');'; var imgsm = document.createElement('img'); imgsm.src = 'http://republico.estv.ipv.pt/~nmct/wikipedia/icons/button_small.png'; imgsm.alt = caption; basm.appendChild(imgsm); tbdiv.appendChild(basm); // Botao:correlatos AddMyOwnButton(tbdiv, 'correlatos', 'javascript:document.editform.wpSummary.value=\'\+correlato\';insertTags(\'{\{Começa correlatos}\}\\n\{\{Correlato\|\commons\|}\}\\n\{\{Correlato\|\wikiquote\|}\}\\n\{\{Correlato\|\wikcionário\|}\}\\n\{\{Correlato\|\wikilivros\|}\}\\n\{\{Correlato\|\wikinotícias\|}\}\\n\{\{Correlato\|\wikisource\|}\}\\n\{\{Correlato\|\wikispecies\|}\}\\n\{\{Correlato\|\meta\|}\}\\n\{\{Termina correlatos}\}\\n\',\'\',\'\');', 'http://img379.imageshack.us/img379/6558/wikimedia5wg.png'); } } window.myAddOnload=function(f) { if (window.addEventListener) window.addEventListener("load", f, false); else if (window.attachEvent) window.attachEvent("onload",f); } myAddOnload(myOwnEditButtons);