// ==UserScript==
// @name Get The Deadites
// @namespace http://blog.nparashuram.com/2009/08/screen-scraping-with-javascript-firebug.html
// @include http://www.pedersonfuneralhome.com/obituaries/ObitSearchList/*
// ==/UserScript==
/*
* Much modified from the original script for a specific site
*/
function loadNextPage(){
var url = "http://www.pedersonfuneralhome.com/obituaries/ObitSearchList/";
var num = parseInt(document.location.href.substring(document.location.href.lastIndexOf("/") + 1));
if (isNaN(num)) {
num = 1;
}
// If the counter exceeds the max number of pages we need to stop loading pages otherwise we go energizer bunny.
if (num < maxPage) {
document.location = url + (num + 1);
// } else {
// Reached last page, need to read LocalStore using JSON.parse
// Create document with URLs retreived from LocalStore and open in browser, user can then use Save Page As ...
}
}
function start(newlyDeads){
// Need to get previous entries from LocalStore (if exists)
// var oldDeads = localStorage.getItem('obits');
// if (typeof oldDeads === undefined) { // No previous data so just store the new stuff
// localStorage.setItem('obits', JSON.stringify(newlyDeads));
// } else {
// Convert to object using JSON.parse
// var tmpDeads = JSON.parse('oldDeads');
// Merge oldDeads and newlyDeads - new merged object stored in first object argument passed
// m(tmpDeads, newlyDeads);
// Save back to LocalStore using JSON.stringify
// localStorage.setItem('obits', JSON.stringify(tmpDeads));
// }
/*
* Dont run a loop, better to run a timeout sort of a function.
* Will not put load on the server
*/
var timerHandler = window.setInterval(function(){
window.clearInterval(timerHandler);
window.setTimeout(loadNextPage, 2000);
}, 1000); // this is the time taken for your next page to load
}
// https://gist.github.com/3rd-Eden/988478
// function m(a,b,c){for(c in b)b.hasOwnProperty(c)&&((typeof a[c])[0]=='o'?m(a[c],b[c]):a[c]=b[c])}
var maxPage;
var records = document.getElementsByTagName("A"); // Grab all Anchors within page
//delete records[12]; // Need to delete "Next" anchor from object (property 13)
var inputs = document.getElementsByTagName("INPUT"); // Grab all the INPUT elements
maxPage = inputs[2].value; // Maximum pages is the value of third INPUT tag
start(records);