Created
July 9, 2019 17:32
-
-
Save michabbb/9a9296e885c6528205d07f003552fd13 to your computer and use it in GitHub Desktop.
Parse ebay itemid from 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
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