Skip to content

Instantly share code, notes, and snippets.

@phette23
Forked from mreidsma/all_full_text.js
Last active February 12, 2020 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phette23/3f1e6264f79eadb567193d5139cce57d to your computer and use it in GitHub Desktop.
Save phette23/3f1e6264f79eadb567193d5139cce57d to your computer and use it in GitHub Desktop.
Simple script to add link to link resolver in Summon results
setTimeout(() => {
libScope(angular.element('html').scope());
}, 1000);
function libScope(scope) {
// Watch results feed for changes...
scope.$watchCollection('feed', () => {
// give AngularJS time to update the DOM
// Probably need to wait a few seconds before running this to make sure the DOM loads
setTimeout(function() {
// Get all the results
const results = document.querySelectorAll('#results > div.inner > ul > li')
const linkResolver = 'https://ey7mr5fu9x.search.serialssolutions.com'
const linkLabel = 'All Full Text Options'
// Get OpenURL and add link to result
for (const result of results) {
// Get the OpenURL in a variable
var OpenURLSpan = result.querySelector('span.Z3988');
if (OpenURLSpan && !result.querySelector('.fulltext-hack')) {
var OpenURL = OpenURLSpan.title
// add a new link to the right of the Full Text Online link
jQuery(OpenURLSpan).after(`<div class="fulltext-hack availability" style="margin-left:1.1em;"><a tabindex="0" target="_blank" class="availabilityLink" href="${linkResolver}/?${OpenURL}&newui=1clickoff">${linkLabel}</a></div>`)
}
}
}, 500) // Wait a second and a half before running this on page load
})
}
@phette23
Copy link
Author

Just testing if a record has an OpenURL isn't good enough—you'll end up with links for all your catalog records, too. So you probably want to check the record's type before adding the fulltext-hack link. Rather than use the DOM for this and the OpenURL, you can get a record's data via angular with angular.element('.documentSummary').scope().document (results list is structured li > div.documentSummary)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment