This is a code that i have used in greasmonkey to download a zip file from a location provided by url at the @include statement.
// ==UserScript==
// @name zipexport
// @namespace refresh page
// @include https://control.com/export.php
// @version 1
// @grant none
// ==/UserScript==
var timerVar= setInterval(function() {DoMeEverySecond (); }, 60000);
function DoMeEverySecond ()
{
setInterval('window.location.reload()',10000);
$(document).ready(function()
{
setTimeout(function(){
document.getElementsByClassName("btn btn-lg btn-primary")[0].click();
}, 1000);});
}
To get some idea, please go through this..
// @include https://control.com/export.php
Use the link of the source page here
setInterval(function() {DoMeEverySecond (); }, 60000);
Helps you to invoke the function DoMeEverySecond (); after 60000ms(60s=1min)
setInterval('window.location.reload()',10000);
Used to reload the page every 10s. It is used by me just to ensure the web page is updated to the latest state(i had a file to download which was updated every hour). You can avoid if this is not needed for you.
$(document).ready(function()
function() will be only called after fully reloading the webpage if we use this statement.
document.getElementsByClassName("btn btn-lg btn-primary")[0].click();
getElementsByClassName/getElementsById etc can be used here based on what can point to the file you wanted to download (Use inspect element by rightclicking in the source page to know if which one of the class/id can point to your zip file).
[0] may help you if you have more than one variable to call under same class.
click()
performs a mouse click in the specified element.(this should help to download the file)