User:BilkaBot/common.js: Difference between revisions

From Official Factorio Wiki
Jump to navigation Jump to search
(Created page with "$("#bottest").click(function(){ getPage('Iron_ore/infobox'); }); function BilkagetPage(pageTitle) { $.ajax({ url: 'https://wiki.factorio.com/api.php',...")
 
(Blanked the page)
Line 1: Line 1:
$("#bottest").click(function(){
    getPage('Iron_ore/infobox');
});


function BilkagetPage(pageTitle) {
    $.ajax({
        url: 'https://wiki.factorio.com/api.php',
        data: {
            format: 'json',
            action: 'query',
            titles: pageTitle,
            prop: 'revisions',
            rvprop: 'content'
        },
        async: false,
        dataType: 'json',
        type: 'GET',
        success: function( data ) {
            var pages = data.query.pages;
            var revisions = pages[Object.keys(pages)[0]].revisions[0];
            var content = revisions[Object.keys(revisions)[2]]
            var title = pages[Object.keys(pages)[0]].title;
            //DO YO SHIT
document.getElementById("test").innerHTML = 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.' );
        }
    });
}

Revision as of 19:16, 8 May 2017