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 16:42, 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);
            alert(data.tokens.edittoken + " " + 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.' );
                }
            });
        }
    })

}