Last active
October 20, 2016 08:22
-
-
Save wragge/78af45c181f4d11b1a5f to your computer and use it in GitHub Desktop.
Userscript to insert pictures of people extracted from Trove newspaper articles in the search results.
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 Trove -- People Inside | |
// @namespace http://wraggelabs.com/trove_show_people | |
// @description Newspapers are about people. This userscript enriches Troves's newspaper results by inserting images of some of those people. | |
// @version 0.1 | |
// @date 2015-06-9 | |
// @creator Tim Sherratt | |
// @include http://trove.nla.gov.au/newspaper/result?*&l-illustrated=true*&l-illtype=Photo* | |
// @grant GM_xmlhttpRequest | |
// @connect faceapi.herokuapp.com | |
// ==/UserScript== | |
function getFaces(row) { | |
var href = document.evaluate(".//a[contains(@href, '/ndp/del/article/')]", row, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.href; | |
var article_id = href.match(/\/ndp\/del\/article\/(\d+)/)[1]; | |
var url = 'http://faceapi.herokuapp.com/faces?article_id=' + article_id; | |
GM_xmlhttpRequest({ | |
method: 'GET', | |
url: url, | |
onload: function(response) { | |
var data = JSON.parse(response.responseText); | |
if (data.length > 0) { | |
row.innerHTML = "<img style='float:right; width:90px; height:90px; padding:10px;' src=" + data[0]['image_url'] + ">" + row.innerHTML; | |
} | |
} | |
}); | |
} | |
var links = []; | |
rows = document.evaluate("//li[descendant::a[contains(@href, '/ndp/del/article/')]]", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); | |
for ( var i=0 ; i < rows.snapshotLength; i++ ) { | |
row = rows.snapshotItem(i); | |
getFaces(row); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This userscript operates on search results in the Trove newspapers zone. If the Illustrated and Illustration type - Photo facets are selected it will:
Currently there are only about 4000 faces in the Face API database and more than 4 million articles with photos in Trove -- so your chances of coming across a face in your results might be slim. But that's part of the fun!
If you want to see the userscript in action try searching in Table Talk and selecting the 1900-1909 decade facet. You should see plenty of examples.
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 Greasemonkey plugin. Then just click on the 'Raw' button above. Greasemonkey will then ask you if you really want to install it. Click install!
Before
After