User:DDOstream/vector.js

/* fixes for T:Unique enchantment changes */ // $( document ).ready( function { var pageid = mw.config.get( 'wgArticleId' );  var editSummary = 'Modifications for changes in  T:Unique enchantment';  var pageContent = '';  mw.util.addPortletLink( 'p-tb-list', '#',   'Fix Enchantments', 'ca-fix-ue', 'Update for modifications to T:Unique enchantment', null, null ); $( '#ca-fix-ue' ).click( function ( e ) { e.preventDefault; new mw.Api.get( {     action: 'query',      prop: 'revisions|info',      rvprop: 'content',      pageids: pageid,      indexpageids: 1    } ).done( function ( pageResponse ) {      pageContent = pageResponse.query.pages[ pageid ].revisions[ 0 ][ '*' ];      pageContent = pageContent        .replace( /[\s\r\n]*?\{\{Unique[ _]enchantment/gi, '{{Unique enchantment' )        .replace( /[\s\r\n]*?\| *?name *?= *?/g,   '\n  | name   = ' )        .replace( /[\s\r\n]*?\| *?effect *?= *?/g, '\n  | effect = ' )        .replace( /[\s\r\n]*?\| *?found *?= *?/g,  '\n  | found  = ' )        .replace( /[\s\r\n]*?\| *?note *?= *?/g,   '\n  | note   = ' )        .replace( /\[http:\/\/forums\.ddo\.com\/showthread\.php\?t=([\d]*)(.*?)\]/, '{{Forums|$1}}' )        .replace( /={1} */g,                                   '\= ' )        .replace( /[\s\r\n]*?\}\}\{\{/g,                  '\n}}\n', nextTemplateStart + 2 ); founds++; } else { if ( founds > 1 ) { alert( '\t\t|found=\t\t\n\nOkay, I won\'t remove any more "found" line(s)' ); } else { alert( '\t\t|found=\t\t\n\nOkay, I won\'t remove any "found" line(s)' ); }         break; }     }      new mw.Api.postWithToken( 'edit', {        action: 'edit',        pageid: pageid,        text: pageContent,        summary: editSummary      } ).done( function ( tagged ) {         if ( tagged.edit.result === 'Success' ) {          alert( 'Page was updated!' );          location.href = location.href.replace( location.hash, '' ) + ( location.search ? '&' : '?' ) + 'diff=last';       } else {          alert( 'Page was NOT updated!' );        }      } ); // console.log( pageContent ); } ); } ); } ); //