MediaWiki:Common.js: Difference between revisions

From Official Factorio Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 24: Line 24:
         type: 'GET',
         type: 'GET',
         success: function( data ) {
         success: function( data ) {
            console.log(data);
             var pages = data.query.pages;
             var pages = data.query.pages;
             var revisions = pages[Object.keys(pages)[0]].revisions[0];
             var revisions = pages[Object.keys(pages)[0]].revisions[0];
             console.log(revisions[Object.keys(revisions)[2]]);
             var content = revisions[Object.keys(revisions)[2]]
             createNewInfoboxPage("test1", "test2");
             createNewInfoboxPage("test1", content);
             if ( data && data.query && data.query.result == 'Success' ) {
             if ( data && data.query && data.query.result == 'Success' ) {
                 window.location.reload(); // reload page if edit was successful
                 window.location.reload(); // reload page if edit was successful
Line 42: Line 43:
}
}


function createNewInfoboxPage(page, content) {
function createNewInfoboxPage(page, contentOfMainPage) {
  console.log("creating new infobox");
  console.log("creating new infobox");
}
}

Revision as of 23:04, 29 September 2016

/* 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: 'Smart Chest',
            prop: 'revisions',
            rvprop: 'content'
        },
        dataType: 'json',
        type: 'GET',
        success: function( data ) {
            console.log(data);
            var pages = data.query.pages;
            var revisions = pages[Object.keys(pages)[0]].revisions[0];
            var content = revisions[Object.keys(revisions)[2]]
            createNewInfoboxPage("test1", content);
            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 createNewInfoboxPage(page, contentOfMainPage) {
 console.log("creating new infobox");
}

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.' );
        }
    });
}