Skip to content

Commit

Permalink
add option to show master duel rarity
Browse files Browse the repository at this point in the history
  • Loading branch information
pivotiiii committed Jan 31, 2025
1 parent 946ce65 commit 8077a02
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
5 changes: 5 additions & 0 deletions SettingsTemplate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ body:
- German
- Portuguese
- Italian
- type: checkbox
attributes:
name: showMDRarity
label: Show Master Duel Rarity
defaultValue: "false"
- type: textBlock
attributes:
description: >-
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ygo-card-search",
"version": "1.1.2",
"version": "1.1.3",
"description": "Plugin for Flow Launcher that searches for Yu-Gi-Oh! cards on ygoprodeck.com",
"main": "./src/main.js",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Name": "Yu-Gi-Oh! card search",
"Description": "Searches for Yu-Gi-Oh! cards on ygoprodeck.com",
"Author": "pivotiiii",
"Version": "1.1.2",
"Version": "1.1.3",
"Language": "JavaScript",
"Website": "https://github.com/pivotiiii/flow_launcher_ygo",
"ExecuteFileName": "src\\main.js",
Expand Down
16 changes: 15 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ const cachePath = path.resolve(__dirname, "cache");
const maxResults = 5;
const cacheImageDimensions = Math.floor(getCurrentResolution().height / 20);

const MDRaritiesMap = {
Common: "C",
Rare: "R",
"Super Rare": "SR",
"Ultra Rare": "UR",
};

const {method, parameters, settings} = JSON.parse(process.argv[2]);

if (method === "query") {
Expand All @@ -39,8 +46,9 @@ async function getCards(query) {
const [apiUrlQuery, apiUrlOptions] = parseQuery(query);
let apiUrlLang = getLang();
const apiUrlNum = `&num=${maxResults}&offset=0`;
const apiUrlMisc = settings.showMDRarity === true ? "&misc=yes" : "";

const apiUrl = apiUrlBase + apiUrlQuery + apiUrlOptions + apiUrlLang + apiUrlNum;
const apiUrl = apiUrlBase + apiUrlQuery + apiUrlOptions + apiUrlLang + apiUrlNum + apiUrlMisc;
//console.log(apiUrl);

const response = await fetch(apiUrl);
Expand All @@ -53,6 +61,7 @@ async function getCards(query) {
const cards = [];

responseJson["data"].forEach(function (card) {
const saveMDRarity = settings.showMDRarity === true && "md_rarity" in card["misc_info"][0];
cards.push({
name: card["name"],
type: card["type"],
Expand All @@ -65,6 +74,7 @@ async function getCards(query) {
url: card["ygoprodeck_url"],
img: card["card_images"][0]["image_url_small"],
id: card["id"],
md_rarity: saveMDRarity === true ? card["misc_info"][0]["md_rarity"] : undefined,
});
});

Expand Down Expand Up @@ -106,6 +116,10 @@ function getCardResult(card, imagePath) {
result.Subtitle = `${card.race} ${card.type}`;
}

if (card.md_rarity !== undefined) {
result.Subtitle = `(${MDRaritiesMap[card.md_rarity] || "?"}) | ${result.Subtitle}`;
}

return result;
}

Expand Down

0 comments on commit 8077a02

Please sign in to comment.