Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple script to add link to link resolver in Summon results
setTimeout(() => {
}, 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 = ''
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

This comment has been minimized.

Copy link
Owner Author

@phette23 phette23 commented Feb 12, 2020

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