RecordSearch Show Pages Userscript
// ==UserScript== | |
// @name RecordSearch Show Pages | |
// @namespace http://timsherratt.org/recordsearch_show_pages | |
// @description Shows the number of pages in a digitised file in the NAA's RecordSearch database | |
// @version 0.6 | |
// @date 2021-02-24 | |
// @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* | |
// @include https://recordsearch.naa.gov.au/SearchNRetrieve/Interface/ViewImage.aspx* | |
// @include https://recordsearch.naa.gov.au/NameSearch/Interface/ItemDetail.aspx* | |
// @include https://recordsearch.naa.gov.au/NameSearch/Interface/ItemsListing.aspx* | |
// @grant GM_xmlhttpRequest | |
// @connect recordsearch.naa.gov.au | |
// ==/UserScript== | |
function getPageType() { | |
let type; | |
if (document.location.href.indexOf('ItemDetail.aspx') > 0) { | |
type = 'single'; | |
} else if (document.location.href.indexOf('ViewImage.aspx') > 0) { | |
type = 'digitised'; | |
} | |
else { | |
type = 'multiple'; | |
} | |
return type; | |
} | |
function processPage() { | |
let type = getPageType(); | |
if (type == 'single' || type == 'multiple') { | |
let rs_links = document.evaluate("//a[contains(@href, '/ViewImage.aspx?B=')]", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); | |
if (type == 'single') { | |
addPageLinks(rs_links.snapshotItem(0), type); | |
} | |
else if (type == 'multiple') { | |
let total = rs_links.snapshotLength; | |
for (let i = 0; i < total; i++) { | |
addPageLinks(rs_links.snapshotItem(i), type); | |
} | |
} | |
} | |
else if (type == 'digitised') { | |
addBarcodeLink(); | |
} | |
} | |
function addBarcodeLink() { | |
let barcodeElement = document.evaluate("//span[@id='lblBarcode']", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0); | |
let barcode = barcodeElement.innerText; | |
barcodeElement.innerHTML = '<a href="https://recordsearch.naa.gov.au/scripts/AutoSearch.asp?O=I&Number=' + barcode + '">' + barcode + '</a>'; | |
} | |
function addPageLinks(rs_link, type) { | |
let pages; | |
let barcode = rs_link.href.match(/\/ViewImage.aspx\?B=(\d+)/)[1]; | |
let url = 'https://recordsearch.naa.gov.au/SearchNRetrieve/Interface/ViewImage.aspx?B=' + barcode; | |
GM_xmlhttpRequest({ | |
method: 'GET', | |
url: url, | |
onload: function(response) { | |
var item = response.responseText; | |
if (item.match(/<span id="lblEndPage">(\d+)<\/span>/i)) { | |
pages = item.match(/<span id="lblEndPage">(\d+)<\/span>/i)[1]; | |
} else { | |
pages = '1'; | |
} | |
if (type == 'single') { | |
rs_link.innerHTML = rs_link.innerHTML + ' (' + pages + ' pages)'; | |
rs_link.href = url; | |
} else { | |
rs_link.innerHTML = rs_link.innerHTML + '<br />' + pages + ' pages'; | |
rs_link.setAttribute('onclick',''); | |
} | |
} | |
}); | |
} | |
processPage(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
This script runs on search results, item details, and digitised file view pages in the National Archives of Australia's database RecordSearch.
It does three things:
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 either the Tampermonkey or Greasemonkey plugins. Then just click on the 'Raw' button above. Your userscript manager will then ask you if you really want to install it. Click install!
Before
After