MediaWiki:Common.js

From Official Factorio Wiki
Revision as of 22:54, 29 September 2016 by TheWombatGuru (talk | contribs)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
/*$(".navbox").css("background", "red");*/

//Spoiler template JavaScript
$(".spoiler-container .button").click(function() {
  $(this).siblings(".text").toggle("slow");
});

$("#start-edit-test").click(function(){
   extractPageInfo("summary", "content", "159d15f2706c7140ac229e91474d142e57ed8df4+\\");
});

function extractPageInfo(summary, content, editToken ) {
    $.ajax({
        url: 'https://wiki.factorio.com/api.php',
        data: {
            format: 'json',
            action: 'query',
            titles: 'User:TheWombatGuru/Sandbox/Auto_edit_test',
            prop: 'revisions',
            rvprop: 'content'
        },
        dataType: 'json',
        type: 'GET',
        success: function( data ) {
            console.log(data.query.pages[Object.keys(data.query.pages)[0]].revisions[0].*);
            //createNewInfoboxPage(data
            if ( data && data.query && data.query.result == 'Success' ) {
                window.location.reload(); // reload page if edit was successful
            } else if ( data && data.error ) {
                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 editPage(summary, content, editToken ) {
    $.ajax({
        url: 'https://wiki.factorio.com/api.php',
        data: {
            format: 'json',
            action: 'query',
            titles: 'User:TheWombatGuru/Sandbox/Auto_edit_test',
            token: editToken
        },
        dataType: 'json',
        type: 'GET',
        success: function( data ) {
            console.log(data);
            if ( data && data.edit && data.edit.result == 'Success' ) {
                window.location.reload(); // reload page if edit was successful
            } else if ( data && data.error ) {
                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.' );
        }
    });
}