// ==UserScript==
// @name District
// @namespace https://williamsfamilytree.co.uk/vm_scripts
// @version 2019.11.09.1115
// @description Create an array of Districts and Counties from the freeBMD website.
// @author RottenSod
// @match https://www.freebmd.org.uk/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js
// @grant GM_setClipboard
// @grant GM_getResourceText
// @grant GM_addStyle
// ==/UserScript==
(function() {
'use strict';
// find the table of districts
var table = document.getElementsByTagName('table')[0];
// point to the rows in the tablew
var trs = table.getElementsByTagName('tr');
//
// Create a new DIVs at the end of the page
$("body").append('
');
$("body").append('');
// set some variables
var county = "";
var district = "";
var start = "";
var finish = "";
// start off the text for the array
$("#rottensod").append("
MyArray1 = {");
$("#dosnettor").append("
MyArray2 = {");
// loop through each row of the table bar the first two
for (var i=2; is with a length of one as they are empty
if (tds.length > 1) {
// check for something sensible in the
if (tds[0].innerText.length > 3) {
// this will be the county
county = tds[0].innerText;
}
// make sure we are not reading the Start/Finish row
if (tds[1].innerText != "Start/Finish") {
// get the district and start and end dates
district = tds[1].innerText;
start = tds[3].innerText;
finish = tds[5].innerText;
// strip out everything between the brackets i.e. dates
district = district.replace(/ *\([^)]*\) */g, "");
// write the result into the 'array' text
$("#rottensod").append('"'+district + '": "' + county + '", '); //," + start + "," + finish);
$("#dosnettor").append('"'+district + '": "{' + county + '","' + start + '","' + finish + '"}, ');
}
}
}
// finish off the 'array' text
$("#rottensod").append("};
" + trs.length);
$("#dosnettor").append("};
" + trs.length);
})(); |