User:EtäKärppä/monobook.js

/* Funktio sivujen lisäämiseen JavaScriptinä * * Tehnyt Nikerabbit                        */ function includeJsPage (page, hostname) { if (!hostname) hostname = "fi.wikipedia.org"; page = encodeURIComponent(page.replace(/^\[\[\s*(.*)\s*\]\]$/, "$1").replace(/ /g, "_")); document.write('<'+'script type="text/javascript" src="http://'+hostname+'/w/index.php?title='+page+                  '&action=raw&ctype=text/javascript&dontcountme=s"><'+'/script>'); }; includeJsPage( "User:Nikerabbit/iwtrans.js" ); // Interwikilinkit käännettynä suomeksi. includeJsPage( "User:Str4nd/admintyökalut.js" ); // Vandaalityökalut includeJsPage( "User:Str4nd/metasivu.js" ); // Metasivu-painike includeJsPage( "User:Str4nd/edittop.js" ); // Muokkaa-painike johdantoon, näytti olevan nykyään myös pienoisohjelmana /* Englanninkielisen Wikipedian kielilinkki ensimmäiseksi */ if (wgAction != 'edit' && wgAction != 'submit' && wgNamespaceNumber == '0') { addOnloadHook( function { var iwmod_ul = document.getElementById( 'p-lang' ).getElementsByTagName( 'ul' )[0];  var iwmod_enwiki = iwmod_ul.getElementsByClassName( 'interwiki-en' )[0];  iwmod_ul.insertBefore(iwmod_enwiki, iwmod_ul.firstChild); }); } // Muokkaukset-välilehti käyttäjäsivuille ja käyttäjien keskustelusivuille. function global_contrib_tabs { if (wgNamespaceNumber > -1) { if (wgNamespaceNumber == 2 || wgNamespaceNumber == 3) { global_append_tab('Toiminnot:Muokkaukset/' + wgTitle, 'muokkaukset', 'ca-contributions'); } } } addOnloadHook( global_contrib_tabs ); /* Allekirjoitus mdashilla ja välillä */ if ((wgAction == 'edit' || wgAction == 'submit') && wgNamespaceNumber != '0') { addOnloadHook( function { var edittoolsname = document.getElementById( 'edittools_name' );  var edittoolsnamea = edittoolsname.getElementsByTagName( 'a' );  edittoolsnamea[0].setAttribute( 'onclick', "insertTags('— '+,,'');return false" ); }); } /* Kokeilua */ /* Muutosten tarkistaminen med JavaScript          by str4nd */ if (location.href.match(/rcid=/) && location.href.match(/diff=/)) { addOnloadHook( function{   document.getElementById('mw-diff-ntitle4').getElementsByTagName('span')[0].getElementsByTagName('a')[0].setAttribute('onclick', 'hax(\'http://fi.wikipedia.org'+document.getElementById('mw-diff-ntitle4').getElementsByTagName('span')[0].getElementsByTagName('a')[0].getAttribute('href')+'\')');    document.getElementById('mw-diff-ntitle4').getElementsByTagName('span')[0].getElementsByTagName('a')[0].setAttribute('href', '#');  } ); } function hax(url) { if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest; } else if (window.ActiveXObject) { xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); } else { alert('Hanki selain.'); return; } xmlhttp.onreadystatechange = valmis; xmlhttp.open('GET', url, true); xmlhttp.send(null); } function valmis { if (xmlhttp.readyState == 4) { document.getElementById('mw-diff-ntitle4').getElementsByTagName('span')[0].getElementsByTagName('a')[0].innerHTML = 'Tarkastettu'; } } var rcp_http; var rcp_enabled; var rcp_num_pages; var rcp_refresh; addOnloadHook( rcp_init ); /* initalise */ function rcp_init { // allow user settings through if(rcp_enabled == null) { rcp_enabled = false; } if(rcp_num_pages == null) { rcp_num_pages = 10; } if(rcp_refresh == null) { rcp_refresh = 5; } // A few limits to be nice to the servers if (rcp_num_pages > 50) { rcp_num_pages = 50; } if (rcp_num_pages < 1) { rcp_num_pages = 1; } if (rcp_refresh < 2) { rcp_refresh = 2; } // get our cookie if (document.cookie.length > 0) { var c_start = document.cookie.indexOf("rcp_show_box="); if (c_start != -1) { c_start = c_start + 13; var c_end = document.cookie.indexOf(";", c_start); if (c_end == -1) { c_end = document.cookie.length; }     if (document.cookie.substring(c_start, c_end) == "yes") { rcp_enabled = true; } else { rcp_enabled = false; }   }   }  // Either make a request or show nothing if (rcp_enabled == true) { rcp_ajax_request; } else { rcp_draw_disabled_box; } } /* init ajax */ function rcp_create_request { try { rcp_http = new XMLHttpRequest; } catch (e) { try { rcp_http = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { rcp_http = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Your browser does not support AJAX!"); return false; }   }  }  rcp_http.onreadystatechange = function { if(rcp_http.readyState == 4) rcp_ajax_response; } return true; } /* make a request */ function rcp_ajax_request { // check we are enabled if (rcp_enabled == false) return; // firstly, inform the user var cur_box = document.getElementById('p-recentchanges'); if (cur_box != null) { cur_box.firstChild.firstChild.data = 'Tuoreet muutokset (päivitetään…)'; } if (rcp_create_request  == false) { if (cur_box != null) { cur_box.firstChild.firstChild.data = 'Tuoreet muutokset (päivitys epäonnistui)'; } else { alert ("There seems to be a problem using the RecentChangePatrol script. I can't make AJAX objects, so I'm just going to complain. God Bless!"); } }  // Then make the request rcp_http.open("GET", "http://fi.wikipedia.org/w/api.php?action=query&list=recentchanges&format=xml&rcnamespace=0&rcshow=anon&rclimit=" + rcp_num_pages + '&rcprop=user|title|ids', true); rcp_http.send(null); } /* we have received a response */ function rcp_ajax_response { var items = rcp_http.responseXML.getElementsByTagName('rc'); // create the div that holds all the recentchanges links var link_div = document.createElement('div'); link_div.className = 'pBody'; var list = document.createElement('ul'); link_div.appendChild(list); // populate the list with 10 links. for (var i = 0; i < items.length; i++) { var item_name = items[i].getAttribute('title'); var user_name = items[i].getAttribute('user'); var item_url = 'http://fi.wikipedia.org/w/index.php?diff=cur&oldid=prev&title=' + escape(item_name); a = document.createElement('a'); a.setAttribute('href', item_url); a.appendChild(document.createTextNode(item_name+' (' + user_name + ')')); var li = document.createElement('li'); li.appendChild(a); list.appendChild(li); } // Container div var div = document.createElement('div'); div.setAttribute('id', 'p-recentchanges'); div.className = 'portlet'; var heading = document.createElement('h5'); heading.appendChild(document.createTextNode('Tuoreet muutokset')); div.appendChild(heading); div.appendChild(link_div); // disable link var p = document.createElement('p'); p.style.fontSize = 'x-small'; p.style.margin = '0px'; p.style.textAlign = 'right'; a = document.createElement('a'); a.appendChild(document.createTextNode('poista käytöstä')); a.onclick = rcp_disable_box; p.appendChild(a); link_div.appendChild(p); // now replace the div var old_div = document.getElementById('p-recentchanges'); var side_col = document.getElementById('column-one'); if (old_div != null) { side_col.replaceChild(div, old_div); } else { var node = document.getElementById('p-search'); side_col.insertBefore(div, node); } // and do it again in 5 secs setTimeout("rcp_ajax_request", rcp_refresh * 1000); } function rcp_disable_box { rcp_enabled = false; rcp_draw_disabled_box; document.cookie = "rcp_show_box=no; path=/"; } function rcp_enable_box { rcp_enabled = true; document.cookie = "rcp_show_box=yes; path=/"; rcp_ajax_request; } function rcp_draw_disabled_box { // Container div var link_div = document.createElement('div'); link_div.className = 'pBody'; var div = document.createElement('div'); div.setAttribute('id', 'p-recentchanges'); div.className = 'portlet'; var heading = document.createElement('h5'); heading.appendChild(document.createTextNode('Tuoreet muutokset')); div.appendChild(heading); div.appendChild(link_div); // enable link var p = document.createElement('p'); p.style.fontSize = 'x-small'; p.style.margin = '0px'; var a = document.createElement('a'); a.appendChild(document.createTextNode('Ota käyttöön')); a.onclick = rcp_enable_box; p.appendChild(a); link_div.appendChild(p); // now replace the div var old_div = document.getElementById('p-recentchanges'); var side_col = document.getElementById('column-one'); if (old_div != null) { side_col.replaceChild(div, old_div); } else { var node = document.getElementById('p-search'); side_col.insertBefore(div, node); } }