Skip to content

Commit

Permalink
added feature: support for local/custom Apy
Browse files Browse the repository at this point in the history
I'll add basic detection for whether langPairs/ and all work soon
  • Loading branch information
OverPoweredDev committed Aug 1, 2021
1 parent 5c94d84 commit aee8426
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/lib/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,5 +357,12 @@ function isHostname(url) {
let validHostnameRegex = "^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])";
let r = RegExp(validHostnameRegex);

return r.test(url);
}

function isURL(url) {
let validURLRegex = "^(http(s)?:\\/\\/)?(www\\.)?[a-z0-9]+([\\-\\.]{1}[a-z0-9]+)*\\.[a-z]{2,5}(:[0-9]{1,5})?(\\/.*)?$";
let r = RegExp(validURLRegex);

return r.test(url);
}
2 changes: 1 addition & 1 deletion src/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</div>
<div id="apy-input-wrapper">
<div id="add-custom-apy-div" class="input-group mb-3" style="display: none">
<input id="apy-input" type="text" class="form-control no-focus" placeholder="http://localhost:2737/">
<input id="apy-input" type="text" class="form-control no-focus" placeholder="">
<button id="add-apy-url" class="btn btn-sm btn-dark no-focus" type="button">Set Source</button>
</div>
</div>
Expand Down
15 changes: 14 additions & 1 deletion src/settings/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ $("#source-select").on('click', async function (e) {
createDropdown($("#target-language-dropdown"));
});

$('#add-apy-url').on('click', async function () {
let customApyInput = $('#apy-input');
globalSettings.apertiumSource = customApyInput.val();

saveGlobalSettings(globalSettings);
await updateLanguagePairs();
setLastUpdated(new Date().toLocaleString());
createDropdown($("#target-language-dropdown"));
});

$('#add-custom-apy-div').on('click', function (e) {
e.stopPropagation();
});
Expand Down Expand Up @@ -97,15 +107,18 @@ function setDefaultLanguage(defaultLanguage) {

function setApertiumSource(apertiumSource) {
let sourceSelect = $("#source-select");
let customApyInput = $('#apy-input');
customApyInput.attr("placeholder", "http://localhost:2737/");
switch (apertiumSource) {
case "https://apertium.org/apy/":
sourceSelect.val("release").change();
break;
case "https://beta.apertium.org/apy/":
sourceSelect.val("beta").change();
break;
case "Local/Custom Source":
default:
sourceSelect.val("custom").change();
customApyInput.attr("placeholder", apertiumSource);
break;
}
}
Expand Down

0 comments on commit aee8426

Please sign in to comment.