User:ಮಲ್ನಾಡಾಚ್ ಕೊಂಕ್ಣೊ/replace.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.
// <nowiki>
function replace_queryString(p) {
    var re = RegExp('[&?]' + p + '=([^&]*)');
    var matches = re.exec(document.location);
    if (matches) {
        try { 
            return decodeURI(matches[1]);
        } catch (e) { }
    }
    return null;
}

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

if(mw.config.get('wgAction') == 'edit' && replace_queryString('replaceedit') == 'true') {
    $(function replace() {
    	var myContent = document.getElementById('wpTextbox1').value;
    	
    	myContent = myContent.replace(/(row|col)span *\= *(\d+)([^\d]+?)/gi, '$1span="$2"$3');
    	myContent = myContent.replace(/width *\= *["']? *(\d+\%) *["']? *\|/gi, 'style="width:$1;"|');
    	
        /* Cleanup quarry results
        myContent = myContent.replace(/_/gi,' ');
        myContent = myContent.replace(/\{\| *class\=\"wikitable\"\n\![^\n]+\n/gi,'');
        myContent = myContent.replace(/\n\|-\n/gi,'\n');
        myContent = myContent.replace(/\n\|\}/gi,'');
        myContent = myContent.replace(/\|([#*])/gi,'$1');
        myContent = myContent.replace(/&#124;/gi,'|');
        */
        
if(document.getElementById('wpTextbox1').value != myContent) {
                  document.getElementById('wpTextbox1').value=myContent;
                  document.getElementById('wpSummary').value='Update table markup to [[WP:HTML5|HTML5]]';
                  document.getElementById('wpMinoredit').checked = false;
                  document.forms.editform.wpDiff.click();
              }
    }
)}
// </nowiki>