Skip to content

Commit

Permalink
Add custom youtube query
Browse files Browse the repository at this point in the history
  • Loading branch information
candela97 committed Mar 24, 2024
1 parent b867b9c commit f1422e2
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 42 deletions.
11 changes: 7 additions & 4 deletions src/html/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,13 @@ <h3 data-locale-text="options.store_general_thirdparty">Options for information
<div data-dynamic="showprotondb"></div>
<div data-dynamic="showcompletionistme"></div>
<div data-dynamic="showpcgw"></div>
<div data-dynamic="showyoutube" class="parent_option"></div>
<div id="showyoutube_querystring" class="option option--sub js-sub-option">
<label for="showyoutubequery" data-locale-text="options.search_query_string">Search query string:</label>
<input type="text" id="showyoutubequery" data-setting="showyoutubequery">
<button id="showyoutubequery_default" data-locale-text="theworddefault">Default</button>
</div>
<div data-dynamic="showtwitch"></div>
<div data-dynamic="showyoutube"></div>
<div data-dynamic="showyoutubegameplay"></div>
<div data-dynamic="showyoutubereviews"></div>

<div class="js-customlinks" data-type="app"></div>
<div>
Expand Down Expand Up @@ -270,7 +273,7 @@ <h2 data-locale-text="options.inventory" class="js-section-head">Inventory</h2>
<div id="quickinv_opt" class="option option--sub js-sub-option">
<label for="quickinv_diff" data-locale-text="options.quickinv_diff">Quick Sale modifier:</label>
<input type="number" step="0.01" id="quickinv_diff" data-setting="quickinv_diff">
<button id="quickinv_default" data-locale-text="theworddefault">Default</button>
<button id="quickinv_diff_default" data-locale-text="theworddefault">Default</button>
</div>
<div data-dynamic="show1clickgoo"></div>
<div data-dynamic="showinvnav"></div>
Expand Down
31 changes: 13 additions & 18 deletions src/js/Content/Features/Store/Common/FExtraLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ export default class FExtraLinks extends Feature {
}
}

if (SyncedStorage.get("showyoutube")) {

const query = SyncedStorage.get("showyoutubequery")
.replace("[NAME]", appName ?? "");

links.push({
"iconClass": "as_youtube_btn", // Add prefix to avoid getting targeted by adblockers
"link": `https://www.youtube.com/results?search_query=${encodeURIComponent(query)}`,
"text": Localization.str.view_on_website.replace("__website__", "YouTube"),
"enabled": true,
});
}

// custom app link
for (const customLink of SyncedStorage.get("app_custom_link")) {

Expand Down Expand Up @@ -153,24 +166,6 @@ export default class FExtraLinks extends Feature {
"text": Localization.str.view_on_website.replace("__website__", "Twitch"),
"enabled": isAppPage && appName && SyncedStorage.get("showtwitch"),
},
{
"iconClass": "as_youtube_btn",
"link": `https://www.youtube.com/results?search_query=${encodeURIComponent(appName)}`,
"text": Localization.str.view_on_website.replace("__website__", "YouTube"),
"enabled": isAppPage && appName && SyncedStorage.get("showyoutube"),
},
{
"iconClass": "as_youtube_btn",
"link": `https://www.youtube.com/results?search_query=${encodeURIComponent(`${appName} "PC" Gameplay`)}`,
"text": Localization.str.youtube_gameplay,
"enabled": isAppPage && appName && SyncedStorage.get("showyoutubegameplay"),
},
{
"iconClass": "as_youtube_btn",
"link": `https://www.youtube.com/results?search_query=${encodeURIComponent(`${appName} "PC" Review`)}`,
"text": Localization.str.youtube_reviews,
"enabled": isAppPage && appName && SyncedStorage.get("showyoutubereviews"),
},
];
}
}
5 changes: 5 additions & 0 deletions src/js/Content/Modules/UpdateHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ class UpdateHandler {
SyncedStorage.remove("show_survey_info");
SyncedStorage.remove("show_steamchart_info");
}

if (oldVersion.isSameOrBefore("3.2.0")) {
SyncedStorage.remove("showyoutubegameplay");
SyncedStorage.remove("showyoutubereviews");
}
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/js/Core/Storage/SyncedStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ const DEFAULTS = {
"showoc": true,
"showhltb": true,
"showyoutube": true,
"showyoutubequery": "[NAME] Gameplay",
"showtwitch": true,
"showpcgw": true,
"showcompletionistme": false,
Expand All @@ -116,8 +117,6 @@ const DEFAULTS = {
"showsteamdb": true,
"showbartervg": false,
"showastatslink": true,
"showyoutubegameplay": true,
"showyoutubereviews": true,
"showwsgf": true,
"exfgls": true,
"app_custom_link": [
Expand Down
4 changes: 1 addition & 3 deletions src/js/Options/Modules/Data/OptionsSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,8 @@ export default {
"showprotondb": "options.protondb",
"showcompletionistme": "options.completionistme",
"showpcgw": "options.pcgw",
"showtwitch": "options.twitch",
"showyoutube": "options.youtube",
"showyoutubegameplay": "options.show_youtubegameplay",
"showyoutubereviews": "options.show_youtubereviews",
"showtwitch": "options.twitch",

// store general
"horizontalscrolling": "options.horizontalscrolling",
Expand Down
36 changes: 23 additions & 13 deletions src/js/Options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,25 @@ const Options = (() => {
});
}

function setDefaultHandler(key, DEFAULTS) {
const node = document.getElementById(`${key}_default`);

let _key = key;
if (key.startsWith("highlight") || key.startsWith("tag")) {
_key = `${_key}_color`;
}

node.addEventListener("click", () => {
setValue(`#${_key}`, DEFAULTS[_key]);
});
}

self.init = async() => {
await SyncedStorage;

const currency = ExtensionResources.getJSON("json/currency.json").then(addCurrencies);
await Promise.all([Localization, currency]);
const Defaults = SyncedStorage.defaults;

self.customLinks = [];
for (const container of document.querySelectorAll(".js-customlinks")) {
self.customLinks.push(new CustomLinks(container));
Expand All @@ -305,12 +318,10 @@ const Options = (() => {
(new ChangelogBuilder()).build();
(new LocaleCreditsBuilder()).build();

function addHandlerToSetDefaultColor(key) {
document.getElementById(`${key}_default`)
.addEventListener("click", () => { setValue(`#${key}_color`, Defaults[`${key}_color`]); });
}
const DEFAULTS = SyncedStorage.defaults;

["highlight_owned",
[
"highlight_owned",
"highlight_wishlist",
"highlight_coupon",
"highlight_inv_gift",
Expand All @@ -325,16 +336,15 @@ const Options = (() => {
"tag_inv_guestpass",
"tag_notinterested",
"tag_collection",
"tag_waitlist"].forEach(addHandlerToSetDefaultColor);

document.getElementById("spamcommentregex_default")
.addEventListener("click", () => setValue("#spamcommentregex", "[\\u2500-\\u25FF]"));
document.getElementById("quickinv_default")
.addEventListener("click", () => setValue("#quickinv_diff", "-0.01"));
"tag_waitlist",
"spamcommentregex",
"quickinv_diff",
"showyoutubequery",
].forEach(key => setDefaultHandler(key, DEFAULTS));

document.getElementById("quickinv_diff").addEventListener("blur", () => {
if (isNaN(parseFloat(document.getElementById("quickinv_diff").value))) {
setValue("#quickinv_diff", "-0.01");
setValue("#quickinv_diff", DEFAULTS["quickinv_diff"]);
}
});

Expand Down
3 changes: 1 addition & 2 deletions src/localization/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@
"mp4video": "Force videos to be in MP4 format",
"youtube": "Show YouTube links",
"twitch": "Show Twitch links",
"search_query_string": "Search query string:",
"pcgw": "Show PCGamingWiki links",
"completionistme": "Show Completionist.me links",
"protondb": "Show ProtonDB links",
Expand All @@ -405,8 +406,6 @@
"saving": "Saving...",
"regional_hideworld": "Hide globe indicator",
"show_astatslink": "Show AStats links",
"show_youtubegameplay": "Show \"YouTube Gameplay\" links",
"show_youtubereviews": "Show \"YouTube Reviews\" links",
"openinnewtab": "Open external links in a new tab",
"showbartervg": "Show Barter.vg links",
"guest": "Items you have a guest pass for",
Expand Down

0 comments on commit f1422e2

Please sign in to comment.