User:ಮಲ್ನಾಡಾಚ್ ಕೊಂಕ್ಣೊ/center.js

// function center_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 'center' tab if(mw.config.get('wgArticleId') != 0 ) { $( function centerEditButton {       mw.util.addPortletLink('p-cactions', mw.util.getUrl(null,{action:'edit',centeredit:true}), 'center', 'p-center', 'center');   } )}

if(mw.config.get('wgAction') == 'edit' && center_queryString('centeredit') == 'true') { $(function lint {       var myContent = document.getElementById('wpTextbox1').value;		/*   		//center caption in 		myContent = myContent.replace(/(\{\{\s*wide image\s*\|\s*[^}]*) ([^<]+)<\/center\>(\s*\}\})/gi,'$1align-cap=center|$2$3');		//Table cell having an image        myContent = myContent.replace(/(\|\s*) (\s*\[\[(file|image):[^\|]+?\|)([^\]]+?\]\]\s*)<\/center>/gi,'$1$2center|$4');        //Center tag wrapping table		myContent = myContent.replace(/ \n*(\{\| *)\n/gi,'$1style="margin:1em auto;"\n');		myContent = myContent.replace(/(\|\}) *\n*<\/center>/gi,'$1');

//Table header with scope row or col having piped Wikilink myContent = myContent.replace(/(\! *scope=\"*[rc]o[wl]\"*) *\|( *) ( *\'*\[\[^\+\]\]\'* *)<\/center>/gi,'$1 style="text-align:center;" |$2$3'); //Table header with scope row or col having unpiped Wikilink myContent = myContent.replace(/(\! *scope=\"*[rc]o[wl]\"*) *\|( *) ( *\'*\[\^\+\]\]\'* *)<\/center>/gi,'$1 style="text-align:center;" |$2$3'); //Table header with scope row or col having anything without | before closing center tag myContent = myContent.replace(/(\! *scope=\"*[rc]o[wl]\"*) *\|( *) ([^|]*)<\/center>/gi,'$1 style="text-align:center;" |$2$3'); //Table cell with rowspan and colspan having piped Wikilink myContent = myContent.replace(/([\!\|] *[rc]o[wl]span=)\"*(\d+)\"*( *[rc]o[wl]span=)\"*(\d+)\"* *\|( *) ( *\'*\[\[^\+\]\]\'* *)<\/center>/gi,'$1"$2"$3"$4" style="text-align:center;" |$5$6'); //Table cell with rowspan and colspan having unpiped Wikilink myContent = myContent.replace(/([\!\|] *[rc]o[wl]span=)\"*(\d+)\"*( *[rc]o[wl]span=)\"*(\d+)\"* *\|( *) ( *\'*\[\^\+\]\]\'* *)<\/center>/gi,'$1"$2"$3"$4" style="text-align:center;" |$5$6'); //Table cell with rowspan and colspan having anything without | before closing center tag myContent = myContent.replace(/([\!\|] *[rc]o[wl]span=)\"*(\d+)\"*( *[rc]o[wl]span=)\"*(\d+)\"* *\|( *) ([^|]*)<\/center>/gi,'$1"$2"$3"$4" style="text-align:center;" |$5$6'); //Table cell with rowspan or colspan having piped Wikilink myContent = myContent.replace(/([\!\|] *[rc]o[wl]span=)\"*(\d+)\"* *\|( *) ( *\'*\[\[^\+\]\]\'* *)<\/center>/gi,'$1"$2" style="text-align:center;" |$3$4');

//Table cell with rowspan or colspan having unpiped Wikilink myContent = myContent.replace(/([\!\|] *[rc]o[wl]span=)\"*(\d+)\"* *\|( *) ( *\'*\[\^\+\]\]\'* *)<\/center>/gi,'$1"$2" style="text-align:center;" |$3$4');

//Table cell with rowspan or colspan having anything without | before closing center tag myContent = myContent.replace(/([\!\|] *[rc]o[wl]span=)\"*(\d+)\"* *\|( *) ([^|]*)<\/center>/gi,'$1"$2" style="text-align:center;" |$3$4'); //Table cell with bgcolor attribute hex without # having piped Wikilink myContent = myContent.replace(/bgcolor=\"* *([a-f\d][a-f\d][a-f\d]|[a-f\d][a-f\d][a-f\d][a-f\d][a-f\d][a-f\d]) *\"* *\|( *) ( *\'*\[\[^\+\]\]\'* *)<\/center>/gi,'style="background:#$1; text-align:center;" |$2$3'); //Table cell with bgcolor attribute having piped Wikilink myContent = myContent.replace(/bgcolor=\"*(\#*[\d\w]+)\"* *\|( *) ( *\'*\[\[^\+\]\]\'* *)<\/center>/gi,'style="background:$1; text-align:center;" |$2$3'); //Table cell with bgcolor attribute hex without # having unpiped Wikilink myContent = myContent.replace(/bgcolor=\"* *([a-f\d][a-f\d][a-f\d]|[a-f\d][a-f\d][a-f\d][a-f\d][a-f\d][a-f\d]) *\"* *\|( *) ( *\'*\[\^\+\]\]\'* *)<\/center>/gi,'style="background:#$1; text-align:center;" |$2$3'); //Table cell with bgcolor attribute having unpiped Wikilink myContent = myContent.replace(/bgcolor=\"*(\#*[\d\w]+)\"* *\|( *) ( *\'*\[\^\+\]\]\'* *)<\/center>/gi,'style="background:$1; text-align:center;" |$2$3'); //Table cell with bgcolor attribute hex without # having anything without | before closing center tag myContent = myContent.replace(/bgcolor=\"* *([a-f\d][a-f\d][a-f\d]|[a-f\d][a-f\d][a-f\d][a-f\d][a-f\d][a-f\d]) *\"* *\|( *) ([^|]*)<\/center>/gi,'style="background:#$1; text-align:center;" |$2$3'); //Table cell with bgcolor attribute having anything without | before closing center tag myContent = myContent.replace(/bgcolor=\"*(\#*[\d\w]+)\"* *\|( *) ([^|]*)<\/center>/gi,'style="background:$1; text-align:center;" |$2$3'); //Table cell with style having piped Wikilink myContent = myContent.replace(/(style=\")([^\"]+\" *\| *) ( *\'*\[\[^\+\]\]\'* *)<\/center>/gi,'$1text-align:center;$2$3');

//Table cell with style having unpiped Wikilink myContent = myContent.replace(/(style=\")([^\"]+\" *\| *) ( *\'*\[\^\+\]\]\'* *)<\/center>/gi,'$1text-align:center;$2$3');       //Table cell with style having anything without | before closing center tag        myContent = myContent.replace(/(style=\")([^\"]+\" *\| *) ([^|]*)<\/center>/gi,'$1text-align:center;$2$3');

//Table cell having single self-closed ref tag myContent = myContent.replace(/\|( *) ( * *)<\/center>/gi, '|style="text-align:center;"|$1$2'); //Table cell having ref tag myContent = myContent.replace(/\|( *) *() *<\/center>/gi,'$1'); //Table cell having specific templates with parameters myContent = myContent.replace(/\|( *) ( *\{\{(flagicon|convert|leagueicon|fb|sort|nowrap|nbay)\|[^}]+\}\} *)<\/center>/gi,'|style="text-align:center;"|$1$2');

//Table cell having piped wikilink myContent = myContent.replace(/\|( *) ( *\'*\[\[^\+\]\]\'* *)<\/center>/gi,'|style="text-align:center;"|$1$2'); //Table cell having unpiped wikilink myContent = myContent.replace(/\|( *) ( *\'*\[\^\+\]\]\'* *)<\/center>/gi,'|style="text-align:center;"|$1$2');

//Table cell having anything without | before closing center tag myContent = myContent.replace(/\|( *) ([^|]*)<\/center>/gi,'|style="text-align:center;"|$1$2'); */       //center table using margin 1em auto. Be careful about one center tag used to center two or more tables myContent = myContent.replace(/< *center *> *\n*(\{\| *)\n/gi, '$1style="margin:1em auto;"\n'); myContent = myContent.replace(/< *center *> *\n*(\{\|.*style\=\")/gi, '$1margin:1em auto; ');   	myContent = myContent.replace(/< *center *> *\n*(\{\| *class\=\"[^"]+?\" *)\n*/gi, '$1 style="margin:1em auto;"\n'); myContent = myContent.replace(/< *center *> *\n*(\{\| *class\=) *(wikitable) *\n*/gi, '$1"$2" style="margin:1em auto;"\n'); myContent = myContent.replace(/< *center *> *\n*(\{\|[^\n]*)\n/gi, '$1 style="margin:1em auto;"\n'); myContent = myContent.replace(/(\|\}) *\n*<\/ *center *>/gi, '$1'); //replace center tags with myContent = myContent.replace(/ /gi,''); myContent = myContent.replace(/<\/center>/gi,''); /*		//replace center tags with myContent = myContent.replace(/ /gi,' '); myContent = myContent.replace(/<\/center>/gi,'<\/div>'); */

if(document.getElementById('wpTextbox1').value != myContent) { document.getElementById('wpTextbox1').value=myContent; document.getElementById('wpSummary').value='Replaced obsolete center tags and reduced Lint errors'; document.getElementById('wpMinoredit').checked = true; document.forms.editform.wpDiff.click; }   } )} //