User:ShutinBot/common.js

$('.toolbar .tools').children('.mytools').after('  My Pages'); $('.custom-menu, .custom-tools-menu').hover(function {   $('.custom-tools-menu').css('display', 'block'); }, function {    setTimeout(function { if(!$('.custom-tools-menu').is(':hover') && !$('.custom-menu').is(':hover')) { $('.custom-tools-menu').css('display', 'none'); }   }, 1000); }); //Userpage $('').html('User Page') .prependTo('#my-pages-menu') .click(function {   $.ajax( { type: 'POST', url: mw.util.wikiScript( 'api' ), dataType: 'json', data: { action: 'edit', title: 'User:Sonoko Bot', summary: 'Creating userpage.', text:'', format: 'json', token: mw.user.tokens.get( 'editToken' ) }   } ).done( function ( data ) { if ( data.edit.result === 'Success' ) { new BannerNotification("Successfully created page!","confirm").show; } else { new BannerNotification("An error occurred.","error").show; }   } ).fail( function ( data ) { new BannerNotification("An error occurred.","error").show; } ); }); //Help $('').html('Help') .prependTo('#my-pages-menu') .click(function {   $.ajax( { type: 'POST', url: mw.util.wikiScript( 'api' ), dataType: 'json', data: { action: 'edit', title: 'User:Sonoko Bot/Help', summary: 'Creating help page.', text:'', format: 'json', token: mw.user.tokens.get( 'editToken' ) }   } ).done( function ( data ) { if ( data.edit.result === 'Success' ) { new BannerNotification("Successfully created page!","confirm").show; } else { new BannerNotification("An error occurred.","error").show; }   } ).fail( function ( data ) { new BannerNotification("An error occurred.","error").show; } ); }); //New Page $(function {   $('').html('New Page')        .prependTo('#my-pages-menu')        .click(function { $.showCustomModal('New Page', ' Please specify the Page name. 

Page\'s Content <textarea id="pagecontent" rows="10" cols="53">\

Summary: <input id="summary" type="text" size="50"> ', { id: 'npModal', buttons: [{ id: 'createPage', defaultButton: true, message: 'Create', handler: function { var pagename = $('#pagename').val; var pagecontent = $('#pagecontent').val; var summary = $('#summary').val; new mw.Api.post({                           action: 'edit',                            title: pagename,                            summary: summary,                            text: pagecontent,                            format: 'json',                            createonly: true,                            token: mw.user.tokens.get('editToken')                        }).done(function(data) {                            if (data.edit.result === 'Success') {                                new BannerNotification("Successfully created page!", "confirm").show;                            } else {                                new BannerNotification("An error occurred.", "error").show;                            }                        }).fail(function(data) {                            new BannerNotification("An error occurred.", "error").show;                        }); }               }, {                    id: 'pnCancel', defaultButton: true, message: 'Cancel', handler: function { $('#pnModal').closeModal; }               }]            });        }); }); //Chat Bot $('', { id: 'qcup', }).html('<a href="#">Chat Bot</a>') .prependTo('#my-pages-menu') .click(function { $.ajax( {   type: 'POST',    url: mw.util.wikiScript( 'api' ),    dataType: 'json',    data: {        action: 'edit',        title: 'User:Sonoko Bot/chat.js',        summary: 'Creating subpage.',        text: 'importScriptPage(\'User:Sonoko Bot/core.javascript\', \'shutinotakus-land\');',        format: 'json',        token: mw.user.tokens.get( 'editToken' )    }    } ).done( function ( data ) {        if ( data.edit.result === 'Success' ) {            new BannerNotification("Successfully created page!","confirm").show;        } else {            new BannerNotification("An error occurred.","error").show;        }    } ).fail( function ( data ) {        new BannerNotification("An error occurred.","error").show;    } ); }); //Logs $('', { id: 'qcup', }).html('<a href="#">Logs</a>') .prependTo('#my-pages-menu') .click(function { $.ajax( {   type: 'POST',    url: mw.util.wikiScript( 'api' ),    dataType: 'json',    data: {        action: 'edit',        title: 'Project:Chat/Logs',        summary: 'Creating Log Index.',        text: ' \n\ <div class="roundtop" style="background:#40e0d0; text-align:center; padding:4px; vertical-align:top; border-radius:5px 5px 0px 0px;">\n\ \'\'\'Chat Log Index\'\'\' \n\ \n\ \n\ This is a chat log index built by Sonoko Bot. Logs are organized from newest to oldest, and are listed in UTC. Log names are formatted as \'\'dd-MMM-yyyy\'\', where hours are listed in a 24 hour format. \'\'\'Do not edit this page\'\'\' unless you are an admin, as a slight mistake can hinder the bot\'s performance. \n\ \n\ <p style="text-align:left;">Click on "expand" to show chat logs. \n\ \n\ \n\ \n\   \n\ ',        format: 'json',        token: mw.user.tokens.get( 'editToken' )    } } ).done( function ( data ) { if ( data.edit.result === 'Success' ) { new BannerNotification("Successfully created page!","confirm").show; } else { new BannerNotification("An error occurred.","error").show; }   } ).fail( function ( data ) { new BannerNotification("An error occurred.","error").show; } ); }); //Log Index $('', {   id: 'qcup', }).html('<a href="#">Log Index</a>') .prependTo('#my-pages-menu') .click(function {   $.ajax( { type: 'POST', url: mw.util.wikiScript( 'api' ), dataType: 'json', data: { action: 'edit', title: 'Project:Chat/Logs/Index', summary: 'Creating Log Index.', text: ' ', format: 'json', token: mw.user.tokens.get( 'editToken' ) }   } ).done( function ( data ) { if ( data.edit.result === 'Success' ) { new BannerNotification("Successfully created page!","confirm").show; } else { new BannerNotification("An error occurred.","error").show; }   } ).fail( function ( data ) { new BannerNotification("An error occurred.","error").show; } ); }); //Seen Logs $('', {   id: 'qcup', }).html('<a href="#">Seen Logs</a>') .prependTo('#my-pages-menu') .click(function {   $.ajax( { type: 'POST', url: mw.util.wikiScript( 'api' ), dataType: 'json', data: { action: 'edit', title: 'Project:Chat/Seen', summary: 'Creating Seen log.', text: '*This is a chatbot unified !seen command database.\n\ \n\ \n\ ',       format: 'json', token: mw.user.tokens.get( 'editToken' ) }   } ).done( function ( data ) { if ( data.edit.result === 'Success' ) { new BannerNotification("Successfully created page!","confirm").show; } else { new BannerNotification("An error occurred.","error").show; }   } ).fail( function ( data ) { new BannerNotification("An error occurred.","error").show; } ); });
 * It\'s supposed to be where the bot stores the data from users and at what timestamp they joined/left chat.\n\
 * Data parsed from this page will be hosted in the bot\'s cache.\n\