User:WOSlinker/common.js

From Wikiquote
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
//importScript('User:WOSlinker/defaultsort.js');

function span_queryString(p) {
    var re = RegExp('[&?]' + p + '=([^&]*)');
    var matches;
    if (matches = re.exec(document.location)) {
        try { 
            return decodeURI(matches[1]);
        } catch (e) { }
    }
    return null;
}

//Add a 'span edit' tab
if(mw.config.get('wgArticleId') != 0 ) { 
    $( function spanEditButton() {
        mw.util.addPortletLink('p-cactions', 
                       mw.util.getUrl(null,{action:'edit',span:true}),
                       'span',
                       'p-span',
                       'span edit');
    }
)}

if(mw.config.get('wgAction') == 'edit' && span_queryString('span') == 'true') {
    $(function span() {
        var myContent = document.getElementById('wpTextbox1').value;

        myContent = myContent.replace(/\<font color\=\#([0-9A-Fa-f]*) *\>([ A-Za-z0-9\.\;\&\#\,\'\/\(\)]*)\<\/font\>/g,'<span style="color:#$1;">$2</span>');
        myContent = myContent.replace(/\<font color\=([a-z]*) *\>([ A-Za-z0-9\.\;\&\#\,\'\/\(\)]*)\<\/font\>/g,'<span style="color:$1;">$2</span>');

        myContent = myContent.replace(/\<font color\=\#([0-9A-Fa-f]*) *\>/g,'<span style="color:#$1;">');
        myContent = myContent.replace(/\<font color\=\"\#([0-9A-Fa-f]*)\" *\>/g,'<span style="color:#$1;">');
        myContent = myContent.replace(/\<font color\=(black|white|yellow) *\>/g,'<span style="color:$1;">');
        myContent = myContent.replace(/<\/font\>/g,'</span>');

        if(document.getElementById('wpTextbox1').value != myContent) {
           document.getElementById('wpTextbox1').value=myContent;
           document.getElementById('wpSummary').value='tidy style for better HTML5 compatibility';
           //document.getElementById('wpMinoredit').checked = true;
        }
    }
)}