Skip to content

Commit

Permalink
fixed inspect in browser / on server
Browse files Browse the repository at this point in the history
  • Loading branch information
gergelyszabo94 committed Dec 5, 2024
1 parent c942145 commit 74d005c
Showing 1 changed file with 28 additions and 110 deletions.
138 changes: 28 additions & 110 deletions extension/src/contentScripts/steam/marketListing.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@ import { overrideCreatePriceHistoryGraph } from 'utils/steamOverriding';
import { listenToAcceptTrade } from 'utils/tradeOffers';
import itemTypes from 'utils/static/itemTypes';

const inBrowserInspectButtonPopupLink = `
<a class="popup_menu_item" id="inbrowser_inspect" href="https://swap.gg/screenshot" target="_blank">
${chrome.i18n.getMessage('inspect_in_browser')}
</a>`;

const onServerInspectButtonPopupLink = `
<a class="popup_menu_item" id="onserver_inspect" href="https://www.cs2inspects.com/" target="_blank">
Inspect on Server...
</a>`;
const dopplerPhase = '<div class="dopplerPhaseMarket"><span></span></div>';

// it takes the visible descriptors and checks if the collection includes souvenirs
Expand Down Expand Up @@ -236,6 +227,34 @@ const addStickers = () => {
DOMPurify.sanitize(`<div class="customNameTag" style="color: var(--steam-nametag-red);" id="customNameTag_${listingID}">${nameTag}</div>`),
);
}

if (listingRow.querySelector('#inspectInBrowser') === null) {
const inspectInGameButton = listingRow.querySelector('div.market_listing_row_action');
if (inspectInGameButton) {
const inspectLink = inspectInGameButton.querySelector('a').getAttribute('href');

inspectInGameButton.style['margin-top'] = '10px';
inspectInGameButton.style['margin-bottom'] = '10px';
inspectInGameButton.style['line-height'] = '15px';
inspectInGameButton.style['text-align'] = 'left';

inspectInGameButton.insertAdjacentHTML(
'afterend',
DOMPurify.sanitize(
`<div class="market_listing_row_action" id="inspectInBrowser" style="line-height: 50px; text-align: left">
<a href="https://swap.gg/screenshot?inspectLink=${inspectLink}" target="_blank">
Inspect in Browser...
</a>
</div>
<div class="market_listing_row_action" id="inspectOnServer" style="line-height: 30px; text-align: left">
<a href="https://www.cs2inspects.com/?apply=${inspectLink}" target="_blank">
Inspect on Server...
</a>
</div>`,
{ ADD_ATTR: ['target'] },
));
}
}
}
},
);
Expand Down Expand Up @@ -885,32 +904,6 @@ if (appID === steamApps.CSGO.appID) {
'beforeend',
DOMPurify.sanitize(customInspectButtons, { ADD_ATTR: ['target'] }),
);

// itemActions.querySelector('#on_server_inspect_button').addEventListener('click', () => {
// document.querySelector('.inspectOnServer').classList.remove('hidden');
// });

// itemActions.insertAdjacentHTML(
// 'afterend',
// DOMPurify.sanitize(`
// <div class="inspectOnServer hidden">
// <div>
// <a href="${inspectServerConnectLink}" class="connectToInspectServer">${inspectServerConnectCommand}</a>
// </div>
// <div
// class="inspectGenCommand clickable"
// title="Generating !gen command..."
// style="margin-top: 5px;">
// Generating !gen command...
// </div>
// </div>`, { ADD_ATTR: ['target'] }),
// );

// const inspectGenCommandEl = document.querySelector('.inspectGenCommand');
// inspectGenCommandEl.addEventListener('click', () => {
// copyToClipboard(inspectGenCommandEl.getAttribute('genCommand'));
// });
// document.querySelector('.connectToInspectServer').setAttribute('href', inspectServerConnectLink);
}
}
}
Expand Down Expand Up @@ -940,81 +933,6 @@ if (appID === steamApps.CSGO.appID) {
));
}
}

// adds the in-browser inspect button to the context menu
document.getElementById('market_action_popup_itemactions')
.insertAdjacentHTML('afterend', DOMPurify.sanitize(
`${inBrowserInspectButtonPopupLink}
${onServerInspectButtonPopupLink}`,
{ ADD_ATTR: ['target'] },
));

// adds the proper link to the context menu before it gets clicked
// needed because the context menu resets when clicked
document.getElementById('inbrowser_inspect').addEventListener('mouseenter', (event) => {
const inspectLink = document.getElementById('market_action_popup_itemactions')
.querySelector('a.popup_menu_item').getAttribute('href');
event.target.setAttribute('href', `https://swap.gg/screenshot?inspectLink=${inspectLink}`);
});

document.getElementById('onserver_inspect').addEventListener('mouseenter', (event) => {
const inspectLink = document.getElementById('market_action_popup_itemactions')
.querySelector('a.popup_menu_item').getAttribute('href');
event.target.setAttribute('href', `https://www.cs2inspects.com/?apply=${inspectLink}`);
});

// document.getElementById('onserver_inspect').addEventListener('click', () => {
// const inspectLink = document.getElementById('market_action_popup_itemactions')
// .querySelector('a.popup_menu_item').getAttribute('href');
// const listingID = getListingIDByInspectLink(inspectLink);
// const listingRow = getElementByListingID(listingID);
// const listings = getListings();

// listingRow.querySelector('.market_listing_game_name').insertAdjacentHTML(
// 'afterend',
// DOMPurify.sanitize(`
// <div class="inspectOnServerListing" style="margin-top: 10px">
// <div>
// <a href="${inspectServerConnectLink}" class="connectToInspectServerListing">${inspectServerConnectCommand}</a>
// </div>
// <div
// class="inspectGenCommandListing clickable"
// title="Generating !gen command..."
// style="margin-top: 5px;">Generating !gen command...
// </div>
// </div>`, { ADD_ATTR: ['target'] }),
// );

// for (const listing of Object.values(listings)) {
// if (listing.listingid === listingID) {
// // collecting listing prices that are in USD
// const price = listing.currencyid === 2001
// ? listing.price + listing.fee
// : listing.converted_currencyid === 2001
// ? listing.converted_price + listing.converted_fee
// : undefined;

// floatQueue.jobs.push({
// type: 'market_per_listing_gencommand',
// assetID: listing.asset.id,
// inspectLink,
// listingID,
// price,
// callBackFunction: dealWithNewFloatData,
// });
// }
// }
// if (!floatQueue.active) workOnFloatQueue();

// listingRow.querySelector('.connectToInspectServerListing').setAttribute('href', inspectServerConnectLink);

// const inspectGenCommandEl = listingRow.querySelector('.inspectGenCommandListing');

// inspectGenCommandEl.addEventListener('click', () => {
// copyToClipboard(inspectGenCommandEl.getAttribute('genCommand'));
// });
// document.getElementById('market_action_popup').style.display = 'none';
// });
}

if (isCommodityItem) {
Expand Down

0 comments on commit 74d005c

Please sign in to comment.