-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js.bak
50 lines (45 loc) · 2 KB
/
content.js.bak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Function to extract item data from the page
function extractItemData() {
const items = document.querySelectorAll('.item-card');
const itemData = [];
items.forEach(item => {
const itemType = item.querySelector('p.size-small.font-bold').textContent;
const itemName = item.querySelector('p.size-medium.font-bold.text-light-1').textContent;
const itemCondition = item.querySelector('p.size-small.font-bold.flex-shrink-0.uppercase').textContent;
const itemPrice = item.querySelector('span.font-numeric.inline-flex.items-baseline.justify-center.font-bold.text-large div.font-numeric').textContent;
const formattedName = `${itemType} | ${itemName} (${itemCondition})`;
itemData.push({ name: formattedName, price: itemPrice });
});
return itemData;
}
// Function to inject API data into the page
function injectApiData(apiData) {
const items = document.querySelectorAll('.item-card');
items.forEach((item, index) => {
const buffPercentageElement = document.createElement('div');
buffPercentageElement.textContent = `Buff Percentage: ${apiData[index].buffPercentage}%`;
item.appendChild(buffPercentageElement);
const buffLiquidityElement = document.createElement('div');
buffLiquidityElement.textContent = `Buff Liquidity: ${apiData[index].buffLiquidity}`;
item.appendChild(buffLiquidityElement);
});
}
// Observe changes in the DOM
const observer = new MutationObserver(async (mutations) => {
mutations.forEach(async (mutation) => {
if (mutation.type === 'childList') {
const itemData = extractItemData();
const apiData = await makeApiCall(itemData);
injectApiData(apiData);
}
});
});
// Start observing the target node for changes
const targetNode = document.querySelector('body');
observer.observe(targetNode, { childList: true, subtree: true });
// Run the initial data injection
window.addEventListener('DOMContentLoaded', async () => {
const itemData = extractItemData();
const apiData = await makeApiCall(itemData);
injectApiData(apiData);
});