Last active
December 16, 2015 15:49
-
-
Save mather/5458140 to your computer and use it in GitHub Desktop.
Amazonの商品URLを短くして商品名からリンクします。駄作なので改善案が欲しい。
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 Shorten URL Clipper | |
// @namespace https://gist.github.com/mather | |
// @version 0.4 | |
// @updateURL https://gist.github.com/mather/5458140/raw/amazon_shorten.user.js | |
// @description Amazon商品のショートURLを作成して、商品名を含めたツイートボタンを作成します。 | |
// @match http://www.amazon.co.jp/* | |
// @match http://www.amazon.com/* | |
// @copyright 2013+, mather | |
// ==/UserScript== | |
function getDomain() { | |
var domain = document.location.hostname; | |
if(domain == "www.amazon.co.jp") { return "amazon.jp"; } | |
if(domain == "www.amazon.com") { return "amazon.com"; } | |
return domain; | |
} | |
function createShortenUri(asin) { | |
return "http://" + getDomain() + "/dp/" + asin + "/"; | |
} | |
function createTweetButton(url) { | |
var aTag = document.createElement("a"); | |
aTag.className = "twitter-share-button"; | |
aTag.setAttribute("href", "https://twitter.com/share"); | |
aTag.setAttribute("data-url", url); | |
aTag.setAttribute("data-text", document.getElementById("btAsinTitle").innerText); | |
aTag.setAttribute("data-lang", "en"); | |
aTag.setAttribute("data-count", "none"); | |
aTag.innerText = "Tweet"; | |
var scriptTag = document.createElement("script"); | |
scriptTag.innerText = "!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');"; | |
document.getElementById("btAsinTitle").appendChild(aTag); | |
document.getElementById("btAsinTitle").appendChild(scriptTag); | |
} | |
var asinElem = document.getElementById("ASIN"); | |
if (asinElem != null && asinElem.value != undefined) { | |
createTweetButton(createShortenUri(asinElem.value)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Version 0.4