Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const getBaseDescription = async() =>{
const baseURL = window.location.origin
const [accountID, itemID] = window.location.href.match(/\d+/g)
const descriptionNode = document.querySelector('.description')
const currentItemURL = `${baseURL}/API/Account/${accountID}/Item/${itemID}.json?load_relations=["ItemAttributes","ItemAttributes.ItemAttributeSet"]`
const itemResponse = await fetch(currentItemURL, { credentials:'same-origin'});
const itemJSON = await itemResponse.json();
const description = itemJSON.Item.description
if(Number(itemJSON.Item.itemMatrixID) > 0){
const attributes = itemJSON.Item.ItemAttributes
const matrixAttributeString = Object.keys(attributes).reduce((matrixString, currentkey, index)=>{
if(index < 3){
if(attributes[currentkey] !== ""){
return index === 0 ?`${matrixString}${attributes[currentkey]}`:`${matrixString} ${attributes[currentkey]}`
}
}
return matrixString
},"")
const baseItemDescription = description.replace(new RegExp(matrixAttributeString, "g"), "")
descriptionNode.innerText = baseItemDescription
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment