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