User:Cantcreateausername/global.js

/* * Note: - currWiki: the current wiki the user visited based on the data from the wgServer configuration value. - prevWiki: the last wiki the user visited other than CC based on the data from the userjs-prevWiki preference option. - Conditional 1.a: If the user is visiting non-CC wiki but the userjs-prevWiki preference option has still yet to be created, set the params variable value to as follows. - Conditional 1.b: If the user is visiting non-CC wiki and the userjs-prevWiki preference has been created, set the params variable value to as follows. - Conditional 1.c: If the user is on CC, replace the CC button on the global nav with the Previous Wiki button. - Conditional 2 : If either 1.a or 1.b happen, use the params variable value to specify the API request and send it. */ mw.loader.using('mw.Api', function {   var currWiki = mw.config.get('wgServer'),        prevWiki = mw.user.options.get('userjs-prevWiki'),        params;    if (currWiki != 'https://community.fandom.com' && prevWiki === null) {       //Cond. 1.a.        params = {            action: 'options',            optionname: 'userjs-prevWiki',            optionvalue: currWiki,            format: 'json'        };    } else if (currWiki != 'https://community.fandom.com') {        //Cond. 1.b.        params = {            action: 'options',            change: 'userjs-prevWiki=' + currWiki,            format: 'json'        };    } else {        //Cond. 1.c        var ccButton = document.querySelector('.global-navigation .wds-dropdown__content a[href*="community.fandom.com"]');        ccButton.textContent = 'Previous Wiki';        ccButton.href = (!prevWiki) ? currWiki : prevWiki;    }    if (currWiki != 'https://community.fandom.com') {        //Cond. 2        var api = new mw.Api;        api.postWithToken('csrf', params).done(function(data) { console.log(data); });   } });