Jump to content

User:Largoplazo/common.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Largoplazo (talk | contribs) at 21:25, 12 January 2014. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// [[User:Lupin/popups.js]]

importScript('User:Lupin/popups.js');

window.popupFixRedirs = true;
window.popupFixDabs = true;

importScript('User:Fox Wilson/delsort.js'); // Deletion sorting script [[WP:FWDS]]

importScript('User:Largoplazo/toplinks.js').onload = function() {
	addTopLink("pt-newpagesfeed", "NewPagesFeed", "/wiki/Special:NewPagesFeed");
};

editToken = "starting value";
function addTrackedItem( summary, content ) {
    // Get token
    $.ajax({
        url: mw.util.wikiScript( 'api' ),
        data: {
            format: 'json',
            action: 'tokens'
        },
        type: 'POST',
        success: function( data ) {
            editToken = (data.tokens.edittoken);
            $.ajax({
                url: mw.util.wikiScript( 'api' ),
                data: {
                    format: 'json',
                    action: 'edit',
                    title: 'User:Largoplazo/Tracking',
                    summary: summary,
                    appendtext: content,
                    token: editToken
                },
                dataType: 'json',
                type: 'POST',
                success: function( data ) {
                    if ( data && data.edit && data.edit.result == 'Success' ) {
                       alert('Done');
                    } else if ( data && data.error ) {
                        alert(editToken);
                        alert( 'Error: API returned error code "' + data.error.code + '": ' + data.error.info );
                    } else {
                        alert( 'Error: Unknown result from API.' );
                    }
                },
                error: function( xhr ) {
                    alert( 'Error: Request failed.' );
                }
            });
        }
    })
}

function trackThisPage() {
	var note = prompt("What do you want to check on this page for?");
	if (!note) return;
	var days = prompt("How many days do you want to wait before checking back?")
	if ((!days) || parseInt(days) == NaN) return;
	
	var summary = "Adding " + window.wgTitle;
	var today = new Date();
	var deferDate = today.getTime() + days * 86400000;
	var content = "\r\n" + today + " : " + deferDate + " : " + note;
	addTrackedItem(summary, content)
	
}