I have a working greasemonkey script that adds a button to a page. When clicked the button scrapes some information from the page, puts it into a variable called str.
Right now I'm printing the variable to the page, which is working fine. I need to eventually make a file with this output from several similar pages.
For example:
output from one page might be "abcdef" and from the second page is "ghijkl". I am copying it one at a time to a text file to make:
abcdef
ghijkl
Is there a way to automatically save these to the same variable and just keep appending the new output to the variable? I know it isn't possible to write to a file from greasemonkey, but don't really know what to do in this situation. There are about 100 pages so I don't want to copy paste 100 times (I'm fine opening each page and clicking the button, that isnt terrible).
This is my code:
// Create a new div to put the links in and append it to the content div
links_div1 = document.createElement('div');//makes a div
//links_div1.setAttribute('class', 'box generic_datatable dataTable');//makes it look the same as rest of page
//links_div1.setAttribute('id', 'normal_wrapper');
//adds div to beginning of content section
var node = document.getElementById('navHeaderCell');
var parentDiv = node.parentNode;
parentDiv.insertBefore(links_div1,node);
//makes buttons in new divs
links_div1.innerHTML += '<table class="box generic_datatable dataTable" id="normal"><thead><tr class="colhead"><th></th></tr></thead><td>Scrape: <button type="button" id="btn_id">scrape</button></td></table>';
//makes them clickable
addButtonListener();
function addButtonListener() {
//first div
document.getElementById("btn_id").addEventListener("click", function(){scrape()}, true);
//alert("function");
}
function scrape() {
//alert(array);
str = array.join('$');
links_div1.innerHTML += str;
}
//collect all the values in a NodeList
var linksToOpen = document.querySelectorAll ("#content_3col>table.form>tbody>tr>td.dash:nth-of-type(2)");
//alert(linksToOpen);
//--- linksToOpen is a NodeList, we want an array of links...
var array = [];
for (var J = 0, numLinks = linksToOpen.length; J < numLinks; ++J) {
array.push (linksToOpen[J].innerHTML.replace(/<[^>]*>/g,''));
}