Skip to content

Instantly share code, notes, and snippets.

@samthecodingman
Last active February 25, 2016 05:05
Show Gist options
  • Save samthecodingman/7cc3e803723946495737 to your computer and use it in GitHub Desktop.
Save samthecodingman/7cc3e803723946495737 to your computer and use it in GitHub Desktop.
View SAE Paper in SAE Digital Library [Javascript Bookmarklet]
javascript:(window.location.href.indexOf("papers.sae.org/")>-1)?window.location.assign(window.location.href.replace("papers.sae.org/","digitallibrary.sae.org/content/")):alert("Error:%20This%20bookmark%20does%20not%20work%20when%20not%20on%20the%20papers.sae.org%20domain");
@samthecodingman
Copy link
Author

View SAE Paper in SAE Digital Library

Have you ever used Google to find a SAE Technical Paper? Does it bug you that even if you have access rights to the paper, the site doesn't let you access/download it? Well this bookmarklet solves that issue. When clicked whilst on a landing page for an SAE Paper from a Google search (or whenever on http://papers.sae.org), you will be redirected to the equivalent paper in the SAE Digital Library (http://digitallibrary.sae.org).

How to use

To use this bookmarklet, add it as a Bookmark to your favourites bar of your browser under the 'URL' or 'Location' field. When clicked, the Javascript function will run and reload the page in the SAE digital library if able.

Why use a bookmarklet?

Well, in comparison to a full plugin, a bookmarklet consists of a small amount of text that just performs the function you need. It may not be as pretty as a plugin, but it doesn't require updating, doesn't have version incompatibilities and most importantly won't actually read any of the page's contents. So there is zero snooping/logging/tracking risk.

How it works

On the surface...
The bookmarklet is actually quite primitive and simplistic, consisting of some simple error checking using the ternary operator:

statement ? doIfTrue() : doIfFalse();

To illustrate what the bookmarklet does, each part has been replaced with a function that explains what happens:

isThisTheSAEPapersSite() ? redirectToSAEDigitalLibrary() : showAnErrorMsg()

A more in depth look...
Using that analogy, isThisTheSAEPapersSite() checks if the current page is the SAE Papers site by searching for the substring "papers.sae.org/" in the page URL.

window.location.href.indexOf("papers.sae.org/")>-1

When isThisTheSAEPapersSite() is true, the URL has "papers.sae.org/" swapped out with "digitallibrary.sae.org/content/" and the browser will be redirected to the new URL

window.location.assign(window.location.href.replace("papers.sae.org/","digitallibrary.sae.org/content/"));

When not on the SAE Papers domain, an error is thrown in the form of a warning dialog.

alert("Error:%20This%20bookmark%20does%20not%20work%20when%20not%20on%20the%20papers.sae.org%20domain");

Note: As this is used as a HREF, HTML character escaping is required for spaces.

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