-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGreasemonkey_FamilySearch.js
More file actions
78 lines (70 loc) · 3.26 KB
/
Greasemonkey_FamilySearch.js
File metadata and controls
78 lines (70 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// ==UserScript==
// @name FamilySearch source info
// @namespace https://www.familysearch.org/
// @description adding microfilm and page number to source information
// @match https://www.familysearch.org/*
// @include https://www.familysearch.org/
// ==/UserScript==
window.setTimeout(addFilmInfo, 2000);
function addFilmInfo()
{
if((window.location +"").indexOf("ark") > 0)
{
var strFilmNumberPrefix = "filmNumber=";
var filmNumber;
var pageNumber;
for(var i=0; aNode = document.getElementsByTagName("a")[i]; i++)
{
var indexOfFilmNr = aNode.href.indexOf(strFilmNumberPrefix);
if(indexOfFilmNr > 0)
{
filmNumber = aNode.innerHTML;
var tbody = aNode.parentNode.parentNode.parentNode.parentNode;
//iterate over all table cells, assuming the last one without link is the image number
for(var j=0; trNode = tbody.childNodes[j]; j++)
{
secondTd= trNode.childNodes[1].childNodes[0]
if(secondTd.innerHTML.indexOf("<a") == -1)
{
pageNumber = secondTd.innerHTML;
}
}
break;
/* above code navigates through this DOM tree:
<table class="css-gx1ll4">
<tbody><!-- this is the tbody after calling parentNode 4 times -->
<tr class="css-17zuftn">
<th scope="row" class="css-18jjc9d"><span secondary="" class="css-wikv0x"><strong>Digitale Ordnernummer</strong></span></th>
<td class="css-18jjc9d"><span secondary="" class="css-wikv0x"><!-- there are iterated in order to find an optional page number --><a href="https://www.familysearch.org/search/record/results?q.filmNumber=4122953" class="css-1ejm1ub-linkCss"><!-- this is the film number -->4122953</a></span></td>
</tr>
<tr class="css-17zuftn">
<th scope="row" class="css-18jjc9d"><span secondary="" class="css-wikv0x"><strong>GS-Filmnummer</strong></span></th>
<td class="css-18jjc9d"><span secondary="" class="css-wikv0x"><!-- and this one --><a href="https://www.familysearch.org/search/record/results?q.filmNumber=1946775" class="css-1ejm1ub-linkCss">1946775</a></span></td>
</tr>
<tr class="css-17zuftn">
<th scope="row" class="css-18jjc9d"><span secondary="" class="css-wikv0x"><strong>Aufnahmenummer</strong></span></th><!-- child 0 -->
<td class="css-18jjc9d">
<span secondary="" class="css-wikv0x"><!-- and this one -->00290</span> <tr class="css-17zuftn">
</td>
</tr>
</tbody>
</table>*/
}
}
var pageNumberInt = parseInt(pageNumber, 10);
var filmInfo = "FHL microfilm " + parseInt(filmNumber, 10);
if(!isNaN(pageNumberInt)) //not all sources have image numbers
{
filmInfo = filmInfo + ", image " + pageNumberInt;
}
/* "Deutschland, Rheinland-Pfalz, Diözese Mainz, Katholische Kirchenbücher, 1540-1952", database, FamilySearch (https://www.familysearch.org/ark:/61903/1:1:DTBJ-FL3Z : 8 December 2020), Georg Fertig, 1831. */
var citation = document.getElementById('citation').innerHTML;
//already has microfilm number?
if(citation.indexOf("FHL microfilm") == -1)
{
// now let's insert the filmInfo before the name
//and replace the existing citation by the new one
document.getElementById('citation').innerHTML = citation.replace("),", "), " + filmInfo +",");
}
}
}