Last active
February 25, 2016 05:05
-
-
Save samthecodingman/7cc3e803723946495737 to your computer and use it in GitHub Desktop.
View SAE Paper in SAE Digital Library [Javascript Bookmarklet]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
To illustrate what the bookmarklet does, each part has been replaced with a function that explains what happens:
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.When
isThisTheSAEPapersSite()
istrue
, the URL has"papers.sae.org/"
swapped out with"digitallibrary.sae.org/content/"
and the browser will be redirected to the new URLWhen not on the SAE Papers domain, an error is thrown in the form of a warning dialog.
Note: As this is used as a HREF, HTML character escaping is required for spaces.