Skip to content

Instantly share code, notes, and snippets.

@mreidsma
Last active March 6, 2020 15:55
Show Gist options
  • Save mreidsma/a8004441b1375ba869f4a31606934654 to your computer and use it in GitHub Desktop.
Save mreidsma/a8004441b1375ba869f4a31606934654 to your computer and use it in GitHub Desktop.
Simple script to add link to link resolver in Summon results
setTimeout(function() {
libMyScope = angular.element('html').scope();
libScope( );
}, 1000);
function libScope(){
console.log('initialising...');
// WATCH FOR RESULTS FEED CHANGES...
libMyScope.$watchCollection('feed', function(){
// give AngularJS time to update the DOM
// Probably need to wait a few seconds before running this to make sure thje DOM loads
setTimeout(function() {
// Get all the results
const results = document.querySelectorAll('#results > div.inner > ul > li');
const linkResolver = 'https://VQ9XH3GM7U.search.serialssolutions.com'; // Link resolver base URL, no trailing space
const linkLabel = 'All Full Text Options'; // The text you want to appear for your new link
// Get OpenURL and add link to result
for (const singleResult of results) {
// Get the OpenURL in a variable
var OpenURLSpan = singleResult.querySelector('span.Z3988');
if(singleResult.querySelectorAll('.fulltext-hack').length === 0) {
// If this result has an Open URL, do the thing
if (typeof(OpenURLSpan) != 'undefined' && OpenURLSpan != null) {
console.log('This has no link.');
var OpenURL = OpenURLSpan.title;
// Echo the value of the OpenURL to the console
console.log(OpenURL);
// Cheating by using jQuery - add a new link to the right of the Full Text Online link as a proof of concept.
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></div>');
}
}
}
}, 500); // Wait a second and a half before running this on page load
console.log('Scope.feed changed! - loading finished');
});
};
@mreidsma
Copy link
Author

Added &newui=1clickoff to the URL parameter to force 1-click off on a link-by-link basis.

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