User:Sunwoo Lim/sunny.js

//Sunny.js Ver0.1.6!1 //A safe user script by Sunwoo Lim to improve Wikipedia. //I, The creator of sunny.js, will publish it under CC-BY-SA 3.0 License. You may give credits to developers of code snippets, if you want to do. //Do not make it Gadget!

//*Warning: You take full responsibility for any action you perform using sunny.js, as sunny.js is safe. //I made it safe due to it being loaded in my common.js.

$("#bodyContent").append('\n\n You are using sunny.js, User script by Sunwoo Lim. '); $("#bodyContent").append('\n\n Warning: You take full responsibility for any action you perform using any user script. '); mw.util.addPortletLink('p-personal', mw.util.getUrl('Special:MyPage/common.js'), 'My Common JS', 'pt-myvector', 'Visit your js file'); mw.util.addPortletLink('p-personal', mw.util.getUrl('Special:MyPage/skin.js'), 'My Skin JS', 'py-myskin', 'Visit your skin js file');

//from Wikipedia:WikiProject User scripts/Scripts/Add purge to tabs $(function {    var hist; var url;    if (!(hist = document.getElementById('ca-history') )) return;    if (!(url = hist.getElementsByTagName('a')[0] )) return;    if (!(url = url.href )) return;    mw.util.addPortletLink('p-cactions', url.replace(/([?&]action=)history([&#]|$)/, '$1purge$2'), 'Purge', 'ca-purge', 'Purge server cache for this page', '0'); });

// user:Where/usertabs $(function { if (wgTitle.indexOf("/") != -1 || document.title.indexOf("- History -") != -1)  //no subpages or history     return;  if (wgCanonicalNamespace == "User" || wgCanonicalNamespace == "User_talk") {     var username = encodeURIComponent( wgTitle );     mw.util.addPortletLink("p-tools", wgServer + "/w/index.php?title=Special:Log&type=move&user=" + username, "Page moves", "ca-pagemoves", "Page moves by this user");  } });

//from Wikipedia:WikiProject User scripts/Scripts/Replace function wpTextboxReplace {   var s = prompt("Search regexp:"); var txt = document.editform.wpTextbox1; while (true) { if (!s) return; var s_r = new RegExp(s, "mg"); if (s_r.test(txt.value)) { var r = prompt("Replace /"+s+"/ with:"); r = r.replace(/\\n/g,"\n"); // unescape newlines if (!r && r !== '') return; txt.value = txt.value.replace(s_r, r); return; }       else { var s_0 = s;           s = prompt("/" + s_0 + "/ did not match anything. You may enter a new regexp:"); }   } } $(function  {    if (document.forms.editform) {        mw.util.addPortletLink('p-cactions', 'javascript:wpTextboxReplace', 'Replace', 'ca-replace', 'Regexp replace for the edit window', 'R', document.getElementById('ca-history'));   } });

//from Wikipedia:WikiProject User scripts/Scripts/Watchlist Since $(function {    if (!wgCanonicalSpecialPageName || wgCanonicalSpecialPageName != "Watchlist") return;    if (!document.forms[0] || !document.forms[0].namespace) return;

var link = document.createElement('a'); link.id = 'listSince'; link.href = '#listSince'; // must have a href to show as link!

var then = +(new Date); var fixLinkHref = function { var url = window.location.href.split('#')[0]; var days = (( +(new Date) - then ) + (60 * 1000)) / (1000 * 3600 * 24); if (url.match(/[?&]days=/)) this.href = url.replace(/([?&]days=)[^&]*/, '$1'+days); else this.href = url + (url.indexOf('?') < 0 ? '?':'&') + 'days=' + days; return true; };   link.onclick = fixLinkHref; link.onmousedown = fixLinkHref; // react to middle clicks too var frag = document.createDocumentFragment; frag.appendChild(document.createTextNode(' | ')); frag.appendChild(link); link.appendChild(document.createTextNode('Changes')); frag.appendChild(document.createTextNode(' since last load.')); // just one little ID attribute would be _so_ nice... var nsSelectForm = document.getElementsByTagName('form')[0]; nsSelectForm.parentNode.insertBefore(frag, nsSelectForm); });

//based on add section -> + gadget. $( function {    var tab, tablink;    tab = document.getElementById('ca-addsection');    if ( !tab ) {        return;    }    tablink = tab.getElementsByTagName('a')[0];    if ( !tablink ) {        return;    }    tablink.firstChild.nodeValue = 'New section';    if ( mw.config.get( 'skin' ) === 'monobook' ) {      tablink.style.paddingLeft = ".4em";      tablink.style.paddingRight = ".4em";    } }); $( function {    var tab, tablink;    tab = document.getElementById('ca-visualedit');    if ( !tab ) {        return;    }    tablink = tab.getElementsByTagName('a')[0];    if ( !tablink ) {        return;    }    tablink.firstChild.nodeValue = 'Visual Edit'; }); $( function {    var tab, tablink;    tab = document.getElementById('ca-view');    if ( !tab ) {        return;    }    tablink = tab.getElementsByTagName('a')[0];    if ( !tablink ) {        return;    }    tablink.firstChild.nodeValue = 'View'; }); $( function {    var tab, tablink;    tab = document.getElementById('ca-history');    if ( !tab ) {        return;    }    tablink = tab.getElementsByTagName('a')[0];    if ( !tablink ) {        return;    }    tablink.firstChild.nodeValue = 'History'; });