Jump to content

User:Sunwoo Lim/common.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
let useCadmiumRed = true;
let useCadmiumYellow = true;

mw.loader.load( 'https://en.wikipedia.org/w/index.php?title=%22User:Sunwoo_Lim/Scripts/cadmium_red.js%22&action=raw&ctype=text/javascript' ); // Backlink: [["User:Sunwoo Lim/Scripts/cadmium_red.js"]]
mw.loader.load( 'htttps://en.wikipedia.org/w/index.php?title=%22User:Sunwoo_Lim/Scripts/cadmium_yellow.js%22&action=raw&ctype=text/javascript' ); // Backlink: [["User:Sunwoo Lim/Scripts/cadmium_yellow.js"]]

$("#bodyContent").append('\n\n<small>You are using sunny.js, User script by Sunwoo Lim.</small>');
$("#bodyContent").append('\n\n<small>Warning: You take full responsibility for any action you perform using any user script.</small>');
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';
});