Created
August 29, 2015 05:56
-
-
Save aji/90d3991492f59e397b58 to your computer and use it in GitHub Desktop.
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
// ==UserScript== | |
// @name Amazon.com shortlink | |
// @namespace http://ajitek.net/gm/amazon-shortlink | |
// @description Add <link rel="shortlink" ...> for Amazon.com pages | |
// @include http://amazon.com/*/dp/* | |
// @include http://www.amazon.com/*/dp/* | |
// @include https://amazon.com/*/dp/* | |
// @include https://www.amazon.com/*/dp/* | |
// @include http://amazon.com/*/e/* | |
// @include http://www.amazon.com/*/e/* | |
// @include https://amazon.com/*/e/* | |
// @include https://www.amazon.com/*/e/* | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
window.addEventListener('load', function (e) { | |
document.head.appendChild((function () { | |
var shortlink = document.createElement('link'); | |
shortlink.setAttribute('rel', 'shortlink'); | |
shortlink.setAttribute('href', (function () { | |
var link_parts = (function () { | |
var links = document.getElementsByTagName('link'); | |
for (i in links) { | |
if (links[i].getAttribute('rel') == 'canonical') | |
return links[i].getAttribute('href'); | |
} | |
return ''; | |
}) ().split('/'); | |
var kind = link_parts[link_parts.length - 2]; | |
var asin = link_parts[link_parts.length - 1]; | |
var scheme = link_parts[0]; | |
return scheme + '//amazon.com/-/' + kind + '/' + asin; | |
}) ()); | |
return shortlink; | |
}) ()) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment