User:Salix alba/vector.js

/* jQuery( document ).ready( function( $ ) {       // Paste snippet here

var url = mw.util.wikiScript( 'api' ); var newmath = 0;

function setMath(val) { console.log('setMath' + val); newmath=val; //var url = mw.config.get( 'wgServer') + mw.config.get( 'wgScriptPath') + '/api.php'; console.log(url); //   $.getJSON(url, { action: "tokens", type: 'options' }, doneToken);

$.ajax({			url: url,			data: { action: 'tokens', type: 'options', format: 'json' },			dataType: "json"		}).done(doneToken);

// {"tokens":{"optionstoken":"5c01f3df8c6e49ce1b5ba77301a30f4f+\\"}} }

function doneToken(data) { console.log(data); var toks = data.tokens; var opttok = toks.optionstoken; console.log(opttok);

$.ajax({			url: url, type: 'POST',			data: { action: 'options', token: opttok, format: 'json', change: 'math=' + newmath },			dataType: "text"		}).done(doneSet);

}

function doneSet(data) { console.log(data); }

var mobile = ( mw.config.get( 'wgServer' ) == 'en.m.wikipedia.org' ); var oldmath = mw.user.options.get('math'); console.log("Math type " + oldmath + ' mobile ' + mobile ); if( mobile && oldmath == 6) { setMath(0); } if( !mobile && oldmath == 0) { setMath(6); }

} );