Skip to content

Instantly share code, notes, and snippets.

@mather
Last active December 16, 2015 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mather/5458140 to your computer and use it in GitHub Desktop.
Save mather/5458140 to your computer and use it in GitHub Desktop.
Amazonの商品URLを短くして商品名からリンクします。駄作なので改善案が欲しい。
// ==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));
}
@mather
Copy link
Author

mather commented Jul 28, 2014

Version 0.4

  • 主な用途がツイートだったので、思い切ってツイートボタンに変更。

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