Created
August 30, 2018 09:05
-
-
Save yhira/bbb3cb2a7e82095138e8ebff7763a4d2 to your computer and use it in GitHub Desktop.
CocoonのAmazon商品リンクショートコード作成ブックマークレット
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:(function(){ | |
var host = location.host; | |
if (host == 'www.amazon.co.jp'){ | |
var titleElems = [ | |
document.getElementById('productTitle'), | |
document.getElementById('ebooksProductTitle'), | |
document.getElementById('aiv-content-title'), | |
document.getElementById('title_feature_div') | |
]; | |
var title = titleElems.filter(v => {return v!=null;})[0].innerText.trim().replace(/[\[|\]]/g,''); | |
var matched = location.href.match(/(?:dp|o|gp|-|ASIN|product)\/(B[0-9]{2}[0-9A-Z]{7}|[0-9]{9}(?:X|[0-9]))/); | |
var asin = matched != null ? matched[1] : ''; | |
var shortcode = '[amazon asin="'+asin+'" kw="'+title+'"]'; | |
} else { | |
alert('Error:ブックマークレットのサポート範囲外のページです。'); | |
} | |
if (shortcode){ | |
if(asin) { | |
if (shortcode = prompt('コピーしてください。', shortcode)){ | |
var r = document.createRange(); | |
var text = document.createTextNode(shortcode); | |
r.selectNode(document.body.appendChild(text)); | |
window.getSelection().addRange(r); | |
document.execCommand('copy'); | |
text.remove(); | |
} | |
} else alert('Error:コードが見つかりませんでした。'); | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment