User:DannyS712 test/remind me.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:DannyS712 test/remind me. |
RemindMe_config = {
name: "[[User:DannyS712/Remind Me.js|Remind me]]",
version: 1.0,
debug: true
};
var user = "";
mw.loader.using( 'mediawiki.util', function () {
importScript('User:DannyS712 test/JSON.js');
$(document).ready( function () {
var link = mw.util.addPortletLink( 'p-cactions', null, 'Remind me', 'ca-add-reminder', 'Reminder to check this page');
$( link ).click( function ( event ) {
event.preventDefault();
add_reminder();
} );
} );
} );
function add_reminder(){
user = mw.config.get( 'wgUserName' );
var location = "User:" + user + "/remind.json";
console.log( location );
var reminder_text = prompt("What would you like the reminder to say?", "Check this page");
var reminder_wait = parseInt(prompt("How many days from now would you like to be reminded?", "10"), 10);
var new_reminder = {
page: get_pretty_page(),
time: (new Date()).getTime(),
wait: reminder_wait*86400000,
text: reminder_text
};
add_the_reminder ( location, new_reminder );
}
function add_the_reminder ( location, new_reminder ){
var arr_JSONed = get_JSON( location );
if (RemindMe_config.debug) console.log( arr_JSONed );
arr_JSONed.push( {page: new_reminder.page, start: new_reminder.time + new_reminder.wait, custom: new_reminder.text, id: user + "_" + new_reminder.time} );
if (RemindMe_config.debug) console.log( "New: " );
if (RemindMe_config.debug) console.log( arr_JSONed );
var new_JSON = JSON.stringify( arr_JSONed, null, 2 );
if (RemindMe_config.debug) console.log( new_JSON );
set_JSON( location, new_JSON, "add a reminder for " + new_reminder.page, 'Reminder scheduled' );
}
function get_pretty_page (){
var page_name = mw.config.get( 'wgPageName' );
var new_name = page_name.replace( /_/g, ' ' );
return new_name;
}