-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ZenMarket): add presence (#8185)
* feat(ZenMarket): add presence * chore: replace innertext with textcontent * chore: fix quote complains and semicolon missing * chore: fix some more lint related stuff * chore: remove unneccssary curly brackets * chore: combine all seperate consts statements into one * chore: does not appear on same line * chore: change schema version * chore: combine more consts into one * chore: run prettifier * chore: replace logo with higher quality one and remove function * chore: replace singlequote with quotes * style: prettify * chore: remove unneccsary path * chore: apply all suggestions * chore: fix lint error * chore: run prettifier again
- Loading branch information
Showing
2 changed files
with
292 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"$schema": "https://schemas.premid.app/metadata/1.10", | ||
"author": { | ||
"id": "82662823523516416", | ||
"name": "maroxy" | ||
}, | ||
"service": "ZenMarket", | ||
"description": { | ||
"en": "Where to buy products from Japan? Want to buy from Japanese online stores and ship to your country? ZenMarket is the best Japan proxy shopping service for you!" | ||
}, | ||
"url": "zenmarket.jp", | ||
"matches": [ | ||
"*://zenmarket.jp/*" | ||
], | ||
"version": "1.0.0", | ||
"logo": "https://i.ibb.co/YWQTYzh/cy0lojzy.png", | ||
"thumbnail": "https://i.ibb.co/vHCN9Rf/600x200.jpg", | ||
"color": "#42749A", | ||
"category": "other", | ||
"tags": [ | ||
"store", | ||
"shopping", | ||
"proxy" | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,267 @@ | ||
const presence = new Presence({ | ||
clientId: "971483473024004157", | ||
}), | ||
browsingTimestamp = Math.floor(Date.now() / 1000); | ||
|
||
const enum Assets { | ||
Logo = "https://i.ibb.co/YWQTYzh/cy0lojzy.png", | ||
} | ||
|
||
presence.on("UpdateData", async () => { | ||
const presenceData: PresenceData = { | ||
largeImageKey: Assets.Logo, | ||
startTimestamp: browsingTimestamp, | ||
details: "Browsing ZenMarket", | ||
}, | ||
{ pathname, search, href } = document.location, | ||
path = pathname.replace( | ||
`/${document.querySelector("html").getAttribute("lang")}`, | ||
"" | ||
); | ||
|
||
// Profile | ||
|
||
if (path === "/profile/" || path === "/profile/default.aspx") { | ||
const warehouseTable: HTMLTableElement = document.querySelector( | ||
"#productsBought > div:nth-child(1) > table" | ||
), | ||
cartTable: HTMLTableElement = document.querySelector(".shop-stripped"), | ||
warehouseItems = warehouseTable ? warehouseTable.rows.length : 0, | ||
cartItems = cartTable ? cartTable.rows.length - 1 : 0; | ||
|
||
presenceData.details = "Viewing Account"; | ||
presenceData.state = `${ | ||
warehouseItems > 1 || warehouseItems === 0 | ||
? `${warehouseItems} items` | ||
: `${warehouseItems} item` | ||
} in warehouse || ${ | ||
cartItems > 1 || cartItems === 0 | ||
? `${cartItems} items` | ||
: `${cartItems} item` | ||
} in cart`; | ||
} | ||
|
||
if (path === "/profile/messages.aspx" || path === "/profile/support.aspx") | ||
presenceData.details = "Viewing Messages"; | ||
|
||
if (path === "/profile/actions.aspx") | ||
presenceData.details = "Looking at Events"; | ||
|
||
if (path === "/profile/watchlist.aspx") { | ||
if ( | ||
(search.includes("tab=auctions") && !search.includes("history")) || | ||
!search | ||
) { | ||
const products = document.querySelector( | ||
"#auctions > div:nth-child(2) > .col-md-12" | ||
), | ||
watchCount = products ? products.children.length - 1 : 0; | ||
|
||
presenceData.details = "Looking at watched auction items"; | ||
presenceData.state = `${ | ||
watchCount > 1 || watchCount === 0 | ||
? `${watchCount} items` | ||
: `${watchCount} item` | ||
} on the watchlist`; | ||
} else if (search.includes("tab=auctions") && search.includes("history")) | ||
presenceData.details = "Viewing history of watched auction items"; | ||
else if (search.includes("tab=products")) { | ||
const products = document.querySelector( | ||
"#products > div:nth-child(2) > .col-md-12" | ||
), | ||
watchCount = products ? products.children.length : 0; | ||
|
||
presenceData.details = "Looking at watched items"; | ||
presenceData.state = `${ | ||
watchCount > 1 || watchCount === 0 | ||
? `${watchCount} items` | ||
: `${watchCount} item` | ||
} on the watchlist`; | ||
} else if (search.includes("tab=sellers")) | ||
presenceData.details = "Viewing watched sellers"; | ||
else if (search.includes("tab=recent")) | ||
presenceData.details = "Looking at recently viewed items"; | ||
} | ||
|
||
if (path === "/profile/parcel.aspx") presenceData.details = "Viewing parcels"; | ||
|
||
if (path === "/profile/payments.aspx") | ||
presenceData.details = "Viewing transactions"; | ||
|
||
if (path === "/profile/levels.aspx") { | ||
presenceData.details = "Checking current level"; | ||
presenceData.state = `Current Level: ${ | ||
document.querySelector("#lblCurrentTier").textContent | ||
}`; | ||
} | ||
|
||
if (path === "/profile/settings.aspx") | ||
presenceData.details = "Viewing settings"; | ||
|
||
// Product view | ||
|
||
if (path === "/auction.aspx" && search.includes("itemCode")) { | ||
presenceData.details = `Looking at ${ | ||
document.querySelector("#itemTitle").textContent | ||
}`; | ||
presenceData.state = `Price: ${ | ||
document.querySelector("#lblPriceY").textContent | ||
} || Bids: ${document.querySelector("#bidNum").textContent} || Condition: ${ | ||
document.querySelector("#lblItemStatus").textContent | ||
} || Seller: ${document.querySelector("#seller").textContent}`; | ||
presenceData.buttons = [ | ||
{ | ||
label: "View on ZenMarket", | ||
url: href, | ||
}, | ||
{ | ||
label: "View on Yahoo Auctions", | ||
url: document.querySelector("#productPage").getAttribute("href"), | ||
}, | ||
]; | ||
} | ||
|
||
if (path === "/yshoppingproduct.aspx") { | ||
presenceData.details = `Looking at ${ | ||
document.querySelector("#itemTitle").textContent | ||
}`; | ||
presenceData.state = `Price: ${ | ||
document.querySelector("#lblPrice").textContent | ||
} || Condition: ${ | ||
document.querySelector("#lblItemCondition").textContent | ||
} || Seller: ${document.querySelector("#seller").textContent}`; | ||
presenceData.buttons = [ | ||
{ | ||
label: "View on ZenMarket", | ||
url: href, | ||
}, | ||
{ | ||
label: "View on Yahoo Shopping", | ||
url: document.querySelector("#productPage").getAttribute("href"), | ||
}, | ||
]; | ||
} | ||
|
||
if (path === "/mercariproduct.aspx") { | ||
presenceData.details = `Looking at ${ | ||
document.querySelector("#itemTitle").textContent | ||
}`; | ||
presenceData.state = `Price: ${ | ||
document.querySelector("#lblPrice").textContent | ||
} || Seller: ${document.querySelector("#seller").textContent}`; | ||
presenceData.buttons = [ | ||
{ | ||
label: "View on ZenMarket", | ||
url: href, | ||
}, | ||
{ | ||
label: "View on Mercari", | ||
url: document.querySelector("#productPage").getAttribute("href"), | ||
}, | ||
]; | ||
} | ||
|
||
if (path === "/rakumaproduct.aspx") { | ||
presenceData.details = `Looking at ${ | ||
document.querySelector("#itemTitle").textContent | ||
}`; | ||
presenceData.state = `Price: ${ | ||
document.querySelector("#lblPrice").textContent | ||
} || Seller: ${document.querySelector("#seller").textContent}`; | ||
presenceData.buttons = [ | ||
{ | ||
label: "View on ZenMarket", | ||
url: href, | ||
}, | ||
{ | ||
label: "View on Rakuma", | ||
url: document.querySelector("#productPage").getAttribute("href"), | ||
}, | ||
]; | ||
} | ||
|
||
if (path === "/rakutenproduct.aspx") { | ||
presenceData.details = `Looking at ${ | ||
document.querySelector("#itemTitle").textContent | ||
}`; | ||
presenceData.state = `Price: ${ | ||
document.querySelector("#lblPrice").textContent | ||
} || Seller: ${document.querySelector("#seller").textContent}`; | ||
presenceData.buttons = [ | ||
{ | ||
label: "View on ZenMarket", | ||
url: href, | ||
}, | ||
{ | ||
label: "View on Rakuten", | ||
url: document.querySelector("#productPage").getAttribute("href"), | ||
}, | ||
]; | ||
} | ||
|
||
if (path === "/amazonproduct.aspx") { | ||
const condition: HTMLSpanElement = | ||
document.querySelector("#lblConditionName"); | ||
presenceData.details = `Looking at ${ | ||
document.querySelector("#itemTitle").textContent | ||
}`; | ||
presenceData.state = `Price: ${ | ||
document.querySelector("#lblPrice").textContent | ||
} ${condition ? `|| Condition: ${condition.textContent}` : ""}`; | ||
presenceData.buttons = [ | ||
{ | ||
label: "View on ZenMarket", | ||
url: href, | ||
}, | ||
{ | ||
label: "View on Amazon", | ||
url: document.querySelector("#productPage").getAttribute("href"), | ||
}, | ||
]; | ||
} | ||
|
||
if (path === "/othershopproduct.aspx") { | ||
presenceData.details = `Looking at ${ | ||
document.querySelector("#itemTitle").textContent | ||
}`; | ||
presenceData.state = `Price: ${ | ||
document.querySelector("#lblPrice").textContent | ||
}`; | ||
presenceData.buttons = [ | ||
{ | ||
label: "View on ZenMarket", | ||
url: href, | ||
}, | ||
{ | ||
label: "View on Original page", | ||
url: document.querySelector("#productPage").getAttribute("href"), | ||
}, | ||
]; | ||
} | ||
|
||
if ( | ||
path.includes("/s/") && | ||
path.split("/").length === 4 && | ||
document.querySelector("#itemTitle") | ||
) { | ||
presenceData.details = `Looking at ${ | ||
document.querySelector("#itemTitle").textContent | ||
}`; | ||
presenceData.state = `Price: ${ | ||
document.querySelector("#lblPrice").textContent | ||
} || Seller: ${document.querySelector("#aSeller").textContent}`; | ||
presenceData.buttons = [ | ||
{ | ||
label: "View on ZenMarket", | ||
url: href, | ||
}, | ||
{ | ||
label: "View on ZenPlus", | ||
url: document.querySelector("#itemUrl").getAttribute("href"), | ||
}, | ||
]; | ||
} | ||
|
||
if (presenceData.details) presence.setActivity(presenceData); | ||
else presence.setActivity(); | ||
}); |