Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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.5
// @date 2020-09-30
// @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="http://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 = 'http://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();
@wragge

This comment has been minimized.

Copy link
Owner Author

@wragge wragge commented Jun 8, 2015

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:

  • If a file is digitised, it retrieves the number of pages in the file and displays it as part of the link to the digitised file. This means you know without clicking through whether the file contains 1 or 300 pages.
  • It also rewrites the link to the digitised file to STOP IT OPENING IN A NEW WINDOW. The default behaviour is just so annoying.
  • On a digitised file view page, the barcode is turned into a link back to the item details page.

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

Before

After

After

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.