Skip to content

Commit

Permalink
Added fallbacks to obtaining the customerId and marketId information …
Browse files Browse the repository at this point in the history
…from the page.
  • Loading branch information
FMaz008 committed Oct 5, 2024
1 parent c3667f4 commit 7c500ed
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
43 changes: 26 additions & 17 deletions scripts/bootloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const VINE_INFO_TITLE = "Vine Helper update info";
const GDPR_TITLE = "Vine Helper - GDPR";

var websiteOpts = null;
var vvpContext = null;
var marketplaceId = null;
var customerId = null;

//Do not run the extension if ultraviner is running
if (!ultraviner) {
Expand All @@ -44,6 +47,16 @@ if (!ultraviner) {

//Initiate the extension
async function init() {
//Obtain the marketplaceId
try {
vvpContext = JSON.parse(document.querySelector('script[data-a-state=\'{"key":"vvp-context"}\'').innerHTML);

marketplaceId = vvpContext.marketplaceId;
customerId = vvpContext.customerId;
} catch (err) {
//Do nothing
}

//Wait for the config to be loaded before running this script
showRuntime("BOOT: Waiting on preboot to complete...");
while (!Settings.isLoaded() || !prebootCompleted) {
Expand Down Expand Up @@ -102,15 +115,12 @@ function displayAccountData() {
container.id = "account-extra-stats";
parentContainer.append(container);

let json = JSON.parse(document.getElementsByClassName("vvp-body")[0].childNodes[0].innerHTML);

let date;
let div;

div = document.createElement("div");
div.innerHTML =
"<h4>Vine Helper extra stats:</h4><strong>Customer Id: </strong><span class='masked-text'>" +
escapeHTML(json.customerId) +
escapeHTML(customerId) +
"</span><br /><br />";
container.appendChild(div);

Expand All @@ -121,15 +131,15 @@ function displayAccountData() {
};

for (const [key, value] of Object.entries(additionalStats)) {
date = new Date(json.voiceDetails[key]).toLocaleString(vineLocale);
date = new Date(vvpContext.voiceDetails[key]).toLocaleString(vineLocale);
div = document.createElement("div");
div.innerHTML = `<strong>${value}:</strong><br /> ${date}<br/><br />`;
container.appendChild(div);
}

div = document.createElement("div");
div.innerHTML =
"<strong>Re-evaluation in progress:</strong> " + escapeHTML(json.voiceDetails.isTierEvaluationInProgress);
"<strong>Re-evaluation in progress:</strong> " + escapeHTML(vvpContext.voiceDetails.isTierEvaluationInProgress);
container.appendChild(div);
}

Expand Down Expand Up @@ -917,6 +927,12 @@ window.addEventListener("message", async function (event) {

if (event.data.type && event.data.type == "websiteOpts") {
websiteOpts = event.data.data;
if (!marketplaceId) {
marketplaceId = websiteOpts.obfuscatedMarketId;
}
if (!customerId) {
customerId = websiteOpts.customerId;
}
showRuntime("BOOT: Opts data obtained from inj.js.");

//Check the current URL for the following pattern:
Expand Down Expand Up @@ -1358,8 +1374,8 @@ async function handleModalNavigation(event) {
}

function openDynamicModal(asin, queue, isParent, enrollmentGUID) {
if (websiteOpts == null) {
console.error("Failed to fetch opts data");
if (!marketplaceId || customerId) {
console.error("Failed to fetch opts/vvp-context data");
}

const recommendationTypes = {
Expand All @@ -1384,17 +1400,10 @@ function openDynamicModal(asin, queue, isParent, enrollmentGUID) {
if (recommendationType == "VENDOR_TARGETED") {
btn.dataset.recommendationType = recommendationType;
btn.dataset.recommendationId =
websiteOpts.obfuscatedMarketId +
"#" +
asin +
"#" +
websiteOpts.customerId +
"#vine.enrollment." +
enrollmentGUID;
marketplaceId + "#" + asin + "#" + customerId + "#vine.enrollment." + enrollmentGUID;
} else {
btn.dataset.recommendationType = recommendationType;
btn.dataset.recommendationId =
websiteOpts.obfuscatedMarketId + "#" + asin + "#vine.enrollment." + enrollmentGUID;
btn.dataset.recommendationId = MarketplaceId + "#" + asin + "#vine.enrollment." + enrollmentGUID;
}
container2.appendChild(btn);
document.getElementById("vvp-items-grid").appendChild(container1);
Expand Down
6 changes: 5 additions & 1 deletion scripts/inj.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ async function testVariants(content) {
}

//Send the opts options containing the customerId and obfuscatedMarketId
if (opts !== undefined) {
if (typeof opts !== "undefined") {
window.postMessage({ type: "websiteOpts", data: opts }, "/");
} else if (typeof fwcimData === "object" && typeof ue_mid === "string") {
//Mobile often doesn't have opts, but will have fwcimData and ue_mid
let opts = { obfuscatedMarketId: ue_mid, customerId: fwcimData.customerId };
window.postMessage({ type: "websiteOpts", data: opts }, "/");
}

0 comments on commit 7c500ed

Please sign in to comment.