Execute multiple functions when the page loads

0

I'm doing some JavaScript studies and would like to know how to make my browser create a window , and perform a series of functions as soon as it > fully loaded .

I'm running all the codes through the browser console

//Pretendo fazer um loop para que essas funções rodem até que o array acabe.
function configCustomPost (i) {
   //Caso a pagina esteja carregada execute
   redirectFunc(i);

   //Isso gera uma troca de pagina, então quando a nova pagina estiver carregada execute
   setTimeout(function(){firstClick()} , 10000);

   //Isso tbm gera uma troca de pagina, então quando a nova pagina estiver carregada execute
   setTimeout(function(){secondClick()} , 30000);
}

Complete:

i = 0;
href_init = 'http://localhost/novosite/wp-admin/admin.php?page=pods-add-new' ;
post_sing = ['a','b','c','d','e','f','g','h','i']; 
post_plur = ['a','b','c','d','e','f','g','h','i']; 
menu_pai = "pods-settings-unidade_1";
var k = window.open(href_init);

function configCustomPost (i) {

    redirectFunc(i);
    setTimeout(function(){firstClick()} , 10000);
    setTimeout(function(){secondClick()} , 30000);
    setTimeout(function(){},40000);
}

function redirectFunc(i){
   sing = post_sing[i]; 
   plur = post_plur[i];
   k.location = href_init;  
}

function firstClick(){
    k.jQuery("a[href='#pods-wizard-create']").click();
    k.jQuery("#pods-form-ui-create-label-singular").val(sing);
    k.jQuery("#pods-form-ui-create-label-plural").val(plur);
    k.jQuery("#pods-form-ui-create-name").val(plur);
    k.jQuery("#pods-wizard-next").click();  
}

function secondClick() {
    k.jQuery("[href='#pods-advanced']").click();
    k.jQuery("#pods-form-ui-supports-author").click();
    k.jQuery("#pods-form-ui-supports-thumbnail").click();
    k.jQuery("#pods-form-ui-supports-excerpt").click();
    k.jQuery("#pods-form-ui-supports-trackbacks").click();
    k.jQuery("#pods-form-ui-supports-custom-fields").click();
    k.jQuery("#pods-form-ui-supports-comments").click();
    k.jQuery("#pods-form-ui-supports-revisions").click();
    k.jQuery("#pods-form-ui-supports-page-attributes").click();
    k.jQuery("#pods-form-ui-supports-post-formats").click();
    k.jQuery("#pods-form-ui-built-in-taxonomies-category").click();
    // 
    k.jQuery("[href='#pods-admin-ui']").click();

    if((sing).length > 30){
        k.jQuery("#pods-form-ui-description").val(sing);
    }

    k.jQuery("#pods-form-ui-show-in-admin-bar").click();
    k.jQuery("#pods-form-ui-menu-location-custom").val(menu_pai);
    // 
    k.jQuery("[href='#pods-labels']").click();
    k.jQuery("#pods-form-ui-label-all-items").val('Posts '+sing);
    k.jQuery(".button-primary").click();

    i++;
}
    
asked by anonymous 18.08.2017 / 15:52

2 answers

0

You can listen for the DOMContentLoaded event, this is called when the page loads. After listening, execute the codes you need. It would look like this:

// Declare suas funções antes...
/* ... */

document.addEventListener('DOMContentLoaded', function(){ 

    /* Qualquer outro código que será executado quando a página estiver carregada */
    // Loop citado...
    for(i=0;i<=10;i++)
    {
        configCustomPost (i);
    }        
}, false);
    
18.08.2017 / 16:00
0
$(document).ready(){
  //a chamada de todas as suas funções, ex:
    conecta();
    imprimeConsole();
    removeCache();
}
  • Must be after configuring / defining all functions, such as one of the last, but the last executed script
18.08.2017 / 16:27