User:Technical 13/SandBox/wikiSwitcher.js
/* GLOBAL (needed???) */
var pageTitle = mw.config.get( 'wgTitle' );
var currUser = mw.config.get( 'wgUserName' );
if ( pageTitle === currUser && mw.config.get( 'wgNamespaceNumber' ) === 2 ) {
var pageID = 0;
if ( typeof(editAvailable) == 'undefined' || editAvailable === '' ) { var editAvailable = "User:" + currUser + "/Availability"; }
else { editAvailable = "User:" + currUser + "/" + editAvailable; }
getPageText();
loadAvailabilities();
}
/* GLOBAL */
function jqEsc( expression ) {
return expression.replace( /[!"#$%&'()*+,.\/:;<=>?@\[\\\]^`{|}~]/g, '\\$&' );
}
function getPageText() {
return $.ajax({
url: mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/api.php?titles=' + editAvailable.replace(' ','_') + '&action=query&prop=revisions&rvprop=content&format=json&indexpageids=true',
dataType: 'json',
success: function(response){
pageID = response.query.pageids;
var pageCurrText = response.query.pages[pageID].revisions[0]['*'];
var currStatus = pageCurrText.substring( pageCurrText.indexOf( "|" )+1, pageCurrText.length-2 );
console.warn( 'Starting status: %s', currStatus );
if( currStatus.indexOf( "|" ) != '-1' ){
console.warn( 'Extra parameter: true' );
if ( currStatus.indexOf( "=" ) != '-1' ){
console.warn( 'Extra parameter isBool: true' );
var currStatusExtraPara = currStatus.substring( currStatus.indexOf( "|" )+1, currStatus.indexOf( "=" ) );
var currStatusExtraVal = currStatus.substring( currStatus.indexOf( "=" )+1, currStatus.length );
if ( currStatusExtraVal == '' && currStatusExtraVal == '0' ){
currStatusExtraVal = 'false';
} else {
currStatusExtraVal = 'true';
}
console.warn( 'currStatusExtraPara: %s\ncurrStatusExtraVal: %s', currStatusExtraPara, currStatusExtraVal );
} else {
console.warn( 'Extra parameter isBool: false' );
var currStatusExtraPara = currStatus.substring( currStatus.indexOf( "|" )+1, currStatus.length );
console.warn( 'currStatusExtraPara: %s', currStatusExtraPara );
}
currStatus = currStatus.substring( 0, currStatus.indexOf( "|" ) );
console.warn( 'currStatus: %s', currStatus );
} else {
console.warn( 'Extra parameter: false' );
}
},
error: function(response){
console.log( 'Failed! Page contains:\n%o', response );
var pageCurrText = '';
}
});
}
function loadAvailabilities() {
var linkAvailable = mw.util.addPortletLink(
'p-personal',
'#',
'Update status',
'pt-available',
'Set wikiBreak status',
null,
'#pt-watchlist'
);
$( linkAvailable ).click( function ( e ) {
e.preventDefault();
/* STUFF TO DO */alert( "You should know this isn't ready yet fool!!!" )/* STUFF TO DO */
});
}
function editThePage( newPageText, pageSummary ) {
var anEditToken = mw.user.tokens.get( 'editToken' );
console.log( 'Got token: %s', anEditToken );
pageSummary = pageSummary.substring(0, 189) + " - [[User:Technical 13/Scripts/wikiSwitcher|wiki break switcher]]";
console.log( 'Edit summary:\n%s\nNew content:\n%s', pageSummary, newPageText )
var request = {
'action': 'edit',
'title': pageTitle,
'text': newPageText,
'summary': pageSummary,
'token': anEditToken
}
var api = new mw.Api();
api.post(request)
}
function changeAvailability() {
console.log( 'Setting availability to %s', availability );
//<nowiki> Set up the new template to use
var pageNewText = '{{' + 'WikibreakSwitch|' + availability + '}}';
//</nowiki>
editThePage( pageNewText, currUser + ' is now ' + availability );
}
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.