From 09e0a3db56b09b031b36dcc3759509d6c84aa8ec Mon Sep 17 00:00:00 2001 From: Yanis Date: Thu, 26 Mar 2026 23:24:55 +0100 Subject: [PATCH 1/4] feat(userscripts): Add loading of subfolder for userscripts Using a feature of Node filesystem which reads every file recursievly. Also extract add method : - readScriptFileAt: Reonsposible for reading the content and push it to the list - loadScripts: Goes through script folder and compile every script --- js/userscripts.js | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/js/userscripts.js b/js/userscripts.js index fa8aa9700..a4e9a0927 100644 --- a/js/userscripts.js +++ b/js/userscripts.js @@ -68,6 +68,7 @@ function urlMatchesPattern (url, pattern) { } const userscripts = { + JS_EXTENSION: ".js", scriptDir: path.join(window.globalArgs['user-data-path'], 'userscripts'), scripts: [], // {options: {}, content} showDirectory: function () { @@ -84,21 +85,9 @@ const userscripts = { } }) }, - loadScripts: function () { - userscripts.scripts = [] - - fs.readdir(userscripts.scriptDir, function (err, files) { - if (err) { - userscripts.ensureDirectoryExists() - return - } else if (files.length === 0) { - return - } - // store the scripts in memory - files.forEach(function (filename) { - if (filename.endsWith('.js')) { - fs.readFile(path.join(userscripts.scriptDir, filename), 'utf-8', function (err, file) { + readScriptFileAt: function(filePath){ + fs.readFile(filePath, 'utf-8', function (err, file) { if (err || !file) { return } @@ -141,6 +130,24 @@ const userscripts = { } } }) + }, + + loadScripts: function () { + userscripts.scripts = [] + + fs.readdir(userscripts.scriptDir, {recursive: true} , function (err, files) { + if (err) { + userscripts.ensureDirectoryExists() + return + } else if (files.length === 0) { + return + } + + // store the scripts in memory + files.forEach(function (file) { + if (file.endsWith(userscripts.JS_EXTENSION)) { + console.log("loading: " + file) + userscripts.readScriptFileAt(path.join(userscripts.scriptDir, file)); } }) }) @@ -184,6 +191,7 @@ const userscripts = { webviews.callAsync(tabId, 'executeJavaScript', [script.content, false, null]) }, onPageLoad: function (tabId) { + console.log("qsdqsd") if (userscripts.scripts.length === 0) { return } From 571dc1e8a14d4010cd3910dcfb36aca2f47291d9 Mon Sep 17 00:00:00 2001 From: Yanis Date: Fri, 27 Mar 2026 00:18:34 +0100 Subject: [PATCH 2/4] fix(userscripts): Fix script loading and remove code smell Since no script have the filename typology implemented, I came to the conclusion regarding actual documentation that there was an issue preventing scripts from loading. Extracted method to get filename without extension to improve readability. NOTE: Might be necessary to be more precise on the [documentation](https://github.com/minbrowser/min/wiki/userscripts) --- js/userscripts.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/js/userscripts.js b/js/userscripts.js index a4e9a0927..3bba845f3 100644 --- a/js/userscripts.js +++ b/js/userscripts.js @@ -86,19 +86,20 @@ const userscripts = { }) }, + extractFileNameNoExtension: function(filename){ + return filename.split(".").at(-1) + }, + readScriptFileAt: function(filePath){ + + var filename = filePath.split("/").at(-1) + fs.readFile(filePath, 'utf-8', function (err, file) { if (err || !file) { return } - - var domain = filename.slice(0, -3) - if (domain.startsWith('www.')) { - domain = domain.slice(4) - } - if (!domain) { - return - } + + var domain = extractFileNameNoExtension(filename) var tampermonkeyFeatures = parseTampermonkeyFeatures(file) if (tampermonkeyFeatures) { @@ -146,7 +147,6 @@ const userscripts = { // store the scripts in memory files.forEach(function (file) { if (file.endsWith(userscripts.JS_EXTENSION)) { - console.log("loading: " + file) userscripts.readScriptFileAt(path.join(userscripts.scriptDir, file)); } }) @@ -191,7 +191,6 @@ const userscripts = { webviews.callAsync(tabId, 'executeJavaScript', [script.content, false, null]) }, onPageLoad: function (tabId) { - console.log("qsdqsd") if (userscripts.scripts.length === 0) { return } From 64d384991e04df9dbdfa68f45b2ddc4fbb7f74fd Mon Sep 17 00:00:00 2001 From: Yanis Date: Fri, 27 Mar 2026 00:35:12 +0100 Subject: [PATCH 3/4] fix(userscript): Fix extract filename method name and add a small log --- js/userscripts.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/userscripts.js b/js/userscripts.js index 3bba845f3..f866cf2ef 100644 --- a/js/userscripts.js +++ b/js/userscripts.js @@ -99,7 +99,7 @@ const userscripts = { return } - var domain = extractFileNameNoExtension(filename) + var domain = userscripts.extractFileNameNoExtension(filename) var tampermonkeyFeatures = parseTampermonkeyFeatures(file) if (tampermonkeyFeatures) { @@ -129,7 +129,9 @@ const userscripts = { name: filename }) } + } + console.log("loaded: " + filename) }) }, From fa02465d67378028494a061f7bcfbded78500e50 Mon Sep 17 00:00:00 2001 From: Yanis Date: Fri, 27 Mar 2026 00:45:03 +0100 Subject: [PATCH 4/4] chore(i18n)(fr): Add translation for 'translatePage' --- localization/languages/fr.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/localization/languages/fr.json b/localization/languages/fr.json index 9289c611b..9c54944ca 100644 --- a/localization/languages/fr.json +++ b/localization/languages/fr.json @@ -27,7 +27,7 @@ "goBack": "Retour", "goForward": "Avancer", "inspectElement": "Inspecter l'élément", - "translatePage": null, // missing translation + "translatePage": "Traduire la page", // missing translation /* searchbar */ "placesPluginOpenAgain": null, // missing translation "placesPluginSwitchToTab": null, // missing translation