Skip to content

Instantly share code, notes, and snippets.

@Adrian-Samuel
Created October 7, 2019 16:25
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/e61527793e4c62f591487a3f733e8871 to your computer and use it in GitHub Desktop.
Save Adrian-Samuel/e61527793e4c62f591487a3f733e8871 to your computer and use it in GitHub Desktop.
(async () => {
const domain = window.location.host;
const [RAD, itemID] = window.location.href.match(/\d+/g);
const itemDOMDescription = document.querySelector('.description')
const getItemMatrix = await fetch(`https://${domain}/API/Account/${RAD}/Item/${itemID}.json?load_relations=["ItemAttributes"]`, {
credentials: "same-origin"
});
const itemMatrixData = await getItemMatrix.json();
const dataAttributes = Object.entries(itemMatrixData.Item.ItemAttributes)
.filter(attr => /attribute/g.test(attr))
.reduce((mainWord, currentString) => `${mainWord} ${currentString[1]}`, '')
const itemDescriptionText = itemDOMDescription.innerText
const baseItem = itemDescriptionText.replace(new RegExp(dataAttributes.trim(), 'g'), "").trim()
itemDOMDescription.innerText = baseItem;
itemDOMDescription.insertAdjacentHTML('afterend', `<p style="color:red;font-weight: 800">${dataAttributes}</p>`)
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment