Userscript to show some of the people inside the National Archives of Australia's collections.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name RecordSearch -- People Inside | |
// @namespace http://wraggelabs.com/recordsearch_show_people | |
// @description Records are about people. This userscript enriches the National Archives of Australia's database by inserting images of some of those people. | |
// @version 0.3 | |
// @date 2017-06-22 | |
// @creator Tim Sherratt | |
// @include https://recordsearch.naa.gov.au/SearchNRetrieve/Interface/ListingReports/ItemsListing.aspx* | |
// @include https://recordsearch.naa.gov.au/SearchNRetrieve/Interface/DetailsReports/ItemDetail.aspx* | |
// @grant GM_xmlhttpRequest | |
// @connect invisibleaustralians.org | |
// ==/UserScript== | |
var processed_series = ['ST84/1'] | |
function getLink() { | |
if (type == 'single') { | |
var total = 1; | |
} else { | |
var total = links.length; | |
} | |
if (link < total ) { | |
//getPages(rs_links.snapshotItem(link)); | |
getPages(links[link]); | |
} | |
} | |
function getPages(rs_link) { | |
var barcode = rs_link.match(/\/ViewImage.aspx\?B=(\d+)/)[1]; | |
if (type == 'single') { | |
var url = 'http://invisibleaustralians.org/api/faces/' + barcode + '/?format=json'; | |
} else { | |
var url = 'http://invisibleaustralians.org/api/faces/random/' + barcode + '/?format=json'; | |
} | |
GM_xmlhttpRequest({ | |
method: 'GET', | |
url: url, | |
onload: function(response) { | |
var data = JSON.parse(response.responseText); | |
if (type == 'single') { | |
if (data.length > 0) { | |
cell = document.evaluate('//*[@id="ContentPlaceHolderSNR_ucItemDetails_ctl08"]/tbody/tr/td/div/table/tbody/tr[1]/td[2]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
var faces = ''; | |
var num_faces = data.length; | |
for (i=0; i<num_faces; i++) { | |
faces += '<img style="margin-right:10px;margin-top:10px;" title="Page: ' + data[i].page + '" src="http://invisibleaustralians.org/image/' + data[i].id + '/?width=80">'; | |
} | |
cell.innerHTML = cell.innerHTML + '<p style="margin-top: 10px;">' + faces + '</p>'; | |
} | |
} else { | |
if (data.id) { | |
xpath = "//a[contains(@href, '" + barcode + "')]/img"; | |
img = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
img.setAttribute('src', 'http://invisibleaustralians.org/image/' + data.id + '/?width=80'); | |
img.setAttribute('title', 'Page: ' + data.page); | |
} | |
} | |
link++; | |
getLink(); | |
} | |
}); | |
} | |
var links = []; | |
if (document.location.href.indexOf('ItemDetail.aspx') > 0) { | |
var type = 'single'; | |
series = document.evaluate("//a[contains(@href, '/SeriesDetail.aspx')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.textContent; | |
digitised = document.evaluate("//a[contains(@href, '/ViewImage.aspx')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
if (digitised && processed_series.indexOf(series) != -1) { | |
links.push(digitised.href); | |
} | |
} else { | |
var type = 'multiple' | |
var rows = document.evaluate('//*[@id="ContentPlaceHolderSNR_tblItemDetails"]/tbody/tr', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); | |
for ( var i=0 ; i < rows.snapshotLength; i++ ) { | |
var series = document.evaluate('td[2]', rows.snapshotItem(i), null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.textContent; | |
var digitised = document.evaluate('td[6]/a', rows.snapshotItem(i), null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
if (digitised && processed_series.indexOf(series) != -1) { | |
links.push(digitised.href); | |
} | |
} | |
} | |
var link = 0; | |
getLink(link); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script runs on search results and item details pages in the National Archives of Australia's database RecordSearch. It looks for series that have been processed as part of the Invisible Australians project (currently ST84/1) and performs the following actions:
For some background information see The People Inside.
Search results before
Search results after
Item before
Item after
To install this in Chrome, first add the Tampermonkey extension. Then just click on the 'Raw' button above. Tampermonkey will then ask you if you really want to install it. Click install!
For Firefox, you'll need to install the Tampermonkey extension. Then just click on the 'Raw' button above. Tampermonkey will then ask you if you really want to install it. Click install!