Skip to content

Instantly share code, notes, and snippets.

@Adrian-Samuel
Created August 18, 2020 16:43
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 Adrian-Samuel/6188cac509f69e0cff3adf00fb627dd2 to your computer and use it in GitHub Desktop.
Save Adrian-Samuel/6188cac509f69e0cff3adf00fb627dd2 to your computer and use it in GitHub Desktop.
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