tampermonkey-scripts
tampermonkey-scripts copied to clipboard
Add an Additional Button for Just Item Number?
Could you modify the code and add a button (next to the original) that copies only the ID (item number)?
Which script are you referring to?
Sorry, GitHub is not sending me notifications. Anyway, the eBay JavaScript, where it copies the eBay short URL. I would like it to just copy the item number.
I added the following code but it doesn't seem to work... I am missing something simple?
// http://icons.iconarchive.com/icons/yusuke-kamiyamane/fugue/16/edit-number-icon.png
var copyNumberIcon = "url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAALZJREFUeNpi/P//PwMlgImBQkCxAQwgL4AwIyMjOtYG4jVQGoUP0wPC+FxgCsS/gPgqDj5BL3gC8R48fDBghMUCExPYLD0gbifk7X///nkTCoM0IN6Ii09MGPgD8Q48fJxeOExExOUBvXAenxfygXgfHj52LyAl6Qgg3opkI5wP04QMWJDYzEBJOyAtC8S3gVgKGiswvggQfwTi31jDAOg0ZiDFB8ScOPz+C2YAsisYBzw3AgQYAPe7bHJIc8toAAAAAElFTkSuQmCC')"
var copyNumberButton = '<div style="float:left"><a rel="nofollow" href="javascript:;" ' +
'class="copy-number" aria-label="Copy item number url to clipboard" ' +
'title="Copy item number to clipboard" target="_blank"><span class="copy-item-number"/></a></div>';
function tryItemNumber(url) {
var urlPattern = /ebay\.(com|de|co\.uk)\/itm/;
if(urlPattern.test(url)) {
var id = url.match(/\/(\d{12})(\?|$)/)[1];
return id;f
} else {
return url;
}
}
// and down in the main section
addGlobalStyle('.copy-item-number { background: ' + copyNumberIcon + '; width: 18px; height: 18px; float: left; background-size: contain;}');
addGlobalStyle('.copy-number { margin-right: 3px; }');
$('div.social-widget > div')[0].style.float = "left";
$('div.social-widget').prepend(copyNumberButton);
$('.copy-number')[0].addEventListener('click', function(event) {
copyTextToClipboard(tryItemNumber(document.location.href));