Skip to content

Instantly share code, notes, and snippets.

@michabbb
Created July 9, 2019 17:32
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 michabbb/9a9296e885c6528205d07f003552fd13 to your computer and use it in GitHub Desktop.
Save michabbb/9a9296e885c6528205d07f003552fd13 to your computer and use it in GitHub Desktop.
Parse ebay itemid from url
parseUrlForEbayItemId(url) {
if (url) {
if (url.toLowerCase()
.indexOf('ebay') >= 0) {
console.log('ebay found');
// this url is on ebay, try to get the item id
const splited = url.split('/');
// search for "/itm/"
if (splited.indexOf('itm') > 0) {
console.log('itm found');
// get last part of "/"
let itemId = splited[splited.length - 1];
// truncate if needed
if (itemId.indexOf('?') > 0) {
if ((itemId.toLowerCase()
.indexOf('ebayisapi.dll') >= 0) && (itemId.toLowerCase()
.indexOf('&item=') >= 0)) {
// get the id from item params
itemId = itemId.split('&item=')[1];
// trunc other params if needed
itemId = itemId.split('&')[0];
} else {
// get the id from truncated string before "?"
itemId = itemId.split('?')[0];
}
}
// remove "#..." if needed
itemId = itemId.split('#')[0];
return itemId;
}
if ((url.toLowerCase().indexOf('ebayisapi.dll') >= 0) && (url.toLowerCase().indexOf('&item=') >= 0)) {
const itemId = url.split('&item=')[1];
return itemId.split('&')[0];
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment