Last active
January 5, 2017 17:45
-
-
Save reefdog/8b00b7ad885563213817fb929573fca8 to your computer and use it in GitHub Desktop.
Redirect static DocumentCloud asset links to the canonical HTML page
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
/*! | |
* Platformer | |
* Redirect static DocumentCloud asset links to the canonical HTML page. | |
* | |
* Say you're at `https://assets.documentcloud.org/documents/282753/lefler-thesis.pdf` | |
* and you want to view the original DocumentCloud page for that document. Click your | |
* Platformer bookmarklet. It transforms that URL to the URL for the original document | |
* on documentcloud.org. | |
* | |
* To use, create a bookmark with the following address (sans backticks): | |
* `javascript:(function(){var pattern=/^https?:\/\/(s3\.amazonaws\.com\/s3|s3|assets)\.documentcloud\.org\/documents\/([0-9]+)\/(pages\/)?(.+)(\-p([0-9]+)(\-([a-z]+))?)?\.([a-z]{3})$/,current=window.location.href,platformed=current.replace(pattern,"https://www.documentcloud.org/documents/$2-$4.html");current==platformed?alert("Hmm, we weren’t able to transform this URL. Please send it to the dev team for inspection."):window.location=platformed;})();` | |
* | |
* TODO: | |
* - Make a GH page with link people can drag to their bookmark bar | |
* | |
* @license (c) 2016 Justin Reese, DocumentCloud | |
* Platformer may be freely distributed under the MIT license. | |
* | |
*/ | |
var pattern = /^https?:\/\/(s3\.amazonaws\.com\/s3|s3|assets)\.documentcloud\.org\/documents\/([0-9]+)\/(pages\/)?(.+)(\-p([0-9]+)(\-([a-z]+))?)?\.([a-z]{3})$/; | |
var current = window.location.href; | |
var platformed = current.replace(pattern, 'https://www.documentcloud.org/documents/$2-$4.html'); | |
if (current == platformed) { | |
alert('Hmm, we weren’t able to transform this URL. Please send it to the dev team for inspection.'); | |
} else { | |
window.location = platformed; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment