Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@mreidsma mreidsma commented Feb 12, 2020

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