Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix translations breaking #649

Merged
merged 1 commit into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"json.schemas": [
{
"fileMatch": ["/features/*/data.json"],
"url": "https://raw.githubusercontent.com/STForScratch/schema/main/feature.json"
}
]
}
58 changes: 33 additions & 25 deletions extras/popup/popup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var clicks = 0
var clicks = 0;

var defaultThemes = [
{
Expand Down Expand Up @@ -64,7 +64,11 @@ async function getFeatureLanguageData() {
var language = chrome.i18n.getUILanguage()?.includes("-")
? chrome.i18n.getUILanguage().split("-")[0]
: chrome.i18n.getUILanguage();
var response = await fetch("/extras/feature-locales/" + language + ".json");
try {
var response = await fetch("/extras/feature-locales/" + language + ".json");
} catch (err) {
return {};
}
if (response.ok) {
return response.json();
} else {
Expand Down Expand Up @@ -459,21 +463,27 @@ document.querySelector(".searchbar").placeholder =

function getWords(text, search) {
if (!search) return true;
if (!search.includes(" ")) return text.toLowerCase().includes(search.toLowerCase());
text = text.replaceAll("\n", " ").replaceAll("Credits:", "").replaceAll("Updated", "").replaceAll("New", "").toLowerCase()
search = search.toLowerCase()
if (!search.includes(" "))
return text.toLowerCase().includes(search.toLowerCase());
text = text
.replaceAll("\n", " ")
.replaceAll("Credits:", "")
.replaceAll("Updated", "")
.replaceAll("New", "")
.toLowerCase();
search = search.toLowerCase();
while (text.includes(" ")) {
text = text.replaceAll(" ", " ")
text = text.replaceAll(" ", " ");
}
var oneWords = text.includes(" ") ? text.split(" ") : [text]

var twoWords = search.includes(" ") ? search.split(" ") : [search]
var oneWords = text.includes(" ") ? text.split(" ") : [text];

var matchWords = oneWords.filter((el) => twoWords.includes(el)).length
var twoWords = search.includes(" ") ? search.split(" ") : [search];

var matchedPercentage = matchWords / twoWords.length
var matchWords = oneWords.filter((el) => twoWords.includes(el)).length;

return matchedPercentage > .5
var matchedPercentage = matchWords / twoWords.length;

return matchedPercentage > 0.5;
}

document.querySelector(".searchbar").addEventListener("input", function () {
Expand All @@ -485,9 +495,7 @@ document.querySelector(".searchbar").addEventListener("input", function () {
}
}
document.querySelectorAll(".feature").forEach(function (el) {
if (
getWords(el.innerText, document.querySelector(".searchbar").value)
) {
if (getWords(el.innerText, document.querySelector(".searchbar").value)) {
el.style.display = null;
} else {
el.style.display = "none";
Expand Down Expand Up @@ -602,7 +610,7 @@ async function getFeatures() {
input.checked = true;
}
if (feature.type.includes("Egg") && !settings.includes(feature.id)) {
div.classList.add("ste-easter-egg")
div.classList.add("ste-easter-egg");
}

input.addEventListener("input", async function () {
Expand All @@ -628,7 +636,7 @@ async function getFeatures() {
var ok = true;
}
if (ok) {
this.parentNode.parentNode.style.display = null
this.parentNode.parentNode.style.display = null;
this.checked = true;
await chrome.storage.sync.set({
features: data + "." + this.parentNode.parentNode.dataset.id,
Expand Down Expand Up @@ -726,9 +734,9 @@ async function getFeatures() {
world: "MAIN",
});
function updateSettingsFunction(feature, name, value) {
ScratchTools.Storage[name] = value
ScratchTools.Storage[name] = value;
if (allSettingChangeFunctions[feature]) {
allSettingChangeFunctions[feature]({key: name, value});
allSettingChangeFunctions[feature]({ key: name, value });
}
}
} catch (err) {
Expand Down Expand Up @@ -1013,15 +1021,15 @@ document.getElementById("campsite")?.addEventListener("click", function () {
});

if (document.querySelector(".main-page")) {
var logo = document.querySelector("div.sticon")
logo.addEventListener("click", function() {
clicks += 1
var logo = document.querySelector("div.sticon");
logo.addEventListener("click", function () {
clicks += 1;
if (clicks > 4) {
clicks = 0
document.querySelector(".buttons .selected").classList.remove("selected")
clicks = 0;
document.querySelector(".buttons .selected").classList.remove("selected");
document.body.dataset.filter = "Egg";
}
})
});
}

if (document.querySelector(".buttons")) {
Expand Down