Synced
Under attack mode (bdb9b6a224) Update Locales (97804234f1) IT Translation (58a95aecef) Fix z-index (fd0119bf70) Improvement to under attack mode (411b50178e) Translations (22268c1923) (c72fb9c836)
This commit is contained in:
parent
2ba50bc116
commit
42fb6cf8d6
12 changed files with 552 additions and 444 deletions
|
|
@ -17,6 +17,7 @@ document.addEventListener('DOMContentLoaded', function(){
|
|||
settings: {},
|
||||
sourceLang: "",
|
||||
targetLang: "",
|
||||
apiKey: localStorage.getItem("api_key") || "",
|
||||
|
||||
loadingTranslation: false,
|
||||
inputText: "",
|
||||
|
|
@ -45,6 +46,7 @@ document.addEventListener('DOMContentLoaded', function(){
|
|||
},
|
||||
mounted: function() {
|
||||
const self = this;
|
||||
window._vueApp = self;
|
||||
self.$el.classList.add("loaded");
|
||||
|
||||
const settingsRequest = new XMLHttpRequest();
|
||||
|
|
@ -137,7 +139,7 @@ document.addEventListener('DOMContentLoaded', function(){
|
|||
' target: ' + this.$options.filters.escape(this.targetLang) + ',',
|
||||
' format: "' + (this.isHtml ? "html" : "text") + '",',
|
||||
' alternatives: 3,',
|
||||
' api_key: "' + (localStorage.getItem("api_key") || "") + '"',
|
||||
' api_key: "' + this.apiKey + '"',
|
||||
' }),',
|
||||
' headers: { "Content-Type": "application/json" }',
|
||||
'});',
|
||||
|
|
@ -164,6 +166,9 @@ document.addEventListener('DOMContentLoaded', function(){
|
|||
});
|
||||
return tgtLangs;
|
||||
}
|
||||
},
|
||||
disableInput: function(){
|
||||
return {% if under_attack %}true{% else %}false{% endif %} && this.apiKey === "";
|
||||
}
|
||||
},
|
||||
filters: {
|
||||
|
|
@ -211,6 +216,7 @@ document.addEventListener('DOMContentLoaded', function(){
|
|||
history.pushState(null, '', newRelativePathQuery);
|
||||
},
|
||||
handleInput: function(e){
|
||||
if (this.disableInput) return;
|
||||
this.closeSuggestTranslation(e)
|
||||
|
||||
this.updateQueryParam('source', this.sourceLang)
|
||||
|
|
@ -245,7 +251,7 @@ document.addEventListener('DOMContentLoaded', function(){
|
|||
data.append("target", self.targetLang);
|
||||
data.append("format", self.isHtml ? "html" : "text");
|
||||
data.append("alternatives", 3);
|
||||
data.append("api_key", localStorage.getItem("api_key") || "");
|
||||
data.append("api_key", self.apiKey);
|
||||
if (self.apiSecret) data.append("secret", atob(self.apiSecret));
|
||||
|
||||
request.open('POST', BaseUrl + '/translate', true);
|
||||
|
|
@ -329,7 +335,7 @@ document.addEventListener('DOMContentLoaded', function(){
|
|||
data.append("s", self.translatedText);
|
||||
data.append("source", self.sourceLang);
|
||||
data.append("target", self.targetLang);
|
||||
data.append("api_key", localStorage.getItem("api_key") || "");
|
||||
data.append("api_key", self.apiKey);
|
||||
|
||||
request.open('POST', BaseUrl + '/suggest', true);
|
||||
request.onload = function() {
|
||||
|
|
@ -382,6 +388,7 @@ document.addEventListener('DOMContentLoaded', function(){
|
|||
},
|
||||
translateFile: function(e) {
|
||||
e.preventDefault();
|
||||
if (this.disableInput) return;
|
||||
|
||||
let self = this;
|
||||
let translateFileRequest = new XMLHttpRequest();
|
||||
|
|
@ -392,7 +399,7 @@ document.addEventListener('DOMContentLoaded', function(){
|
|||
data.append("file", this.inputFile);
|
||||
data.append("source", this.sourceLang);
|
||||
data.append("target", this.targetLang);
|
||||
data.append("api_key", localStorage.getItem("api_key") || "");
|
||||
data.append("api_key", this.apiKey);
|
||||
if (self.apiSecret) data.append("secret", self.apiSecret);
|
||||
|
||||
this.loadingFileTranslation = true
|
||||
|
|
@ -537,6 +544,9 @@ function setApiKey(){
|
|||
if (newKey === null) newKey = "";
|
||||
|
||||
localStorage.setItem("api_key", newKey);
|
||||
if (window._vueApp){
|
||||
window._vueApp.apiKey = newKey;
|
||||
}
|
||||
}
|
||||
|
||||
// Color scheme handling
|
||||
|
|
@ -618,4 +628,4 @@ function applyPreferredColorScheme(scheme) {
|
|||
|
||||
applyPreferredColorScheme(getPreferredColorScheme());
|
||||
|
||||
// @license-end
|
||||
// @license-end
|
||||
|
|
@ -151,17 +151,16 @@
|
|||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col s12 m12">
|
||||
<div class="card horizontal">
|
||||
<div class="card-stacked">
|
||||
<div class="card-content">
|
||||
<i class="material-icons">warning</i><p> [[ error ]]</p>
|
||||
<div class="card horizontal">
|
||||
<div class="card-stacked">
|
||||
<div class="card-content">
|
||||
<i class="material-icons">warning</i><p> [[ error ]]</p>
|
||||
</div>
|
||||
<div class="card-action">
|
||||
<a href="#" @click="dismissError">{{ _h("Dismiss") }}</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-action">
|
||||
<a href="#" @click="dismissError">{{ _h("Dismiss") }}</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -171,13 +170,22 @@
|
|||
<div class="section no-pad-bot">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
{% if under_attack %}
|
||||
<div class="card horizontal style="z-index: -1;">
|
||||
<div class="card-stacked">
|
||||
<div class="card-content center">
|
||||
<i class="material-icons" style="position: relative; top: 4px;">warning</i> {{ _h("Due to bot abuse, translation requests are temporarily limited to users with a valid API key. Sorry for the inconvenience!") }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<h3 class="header center">{{ _h("Translation API") }}</h3>
|
||||
<div id="translation-type-btns" class="s12 center" v-if="filesTranslation === true">
|
||||
<button type="button" class="btn btn-switch-type" @click="switchType('text')" :class="{'active': translationType === 'text'}">
|
||||
<button type="button" class="btn btn-switch-type" @click="switchType('text')" :class="{'active': translationType === 'text'}" :disabled="disableInput">
|
||||
<i aria-hidden="true" class="material-icons">title</i>
|
||||
<span class="btn-text">{{ _h("Translate Text") }}</span>
|
||||
</button>
|
||||
<button type="button" class="btn btn-switch-type" @click="switchType('files')" :class="{'active': translationType === 'files'}">
|
||||
<button type="button" class="btn btn-switch-type" @click="switchType('files')" :class="{'active': translationType === 'files'}" :disabled="disableInput">
|
||||
<i aria-hidden="true" class="material-icons">description</i>
|
||||
<span class="btn-text">{{ _h("Translate Files") }}</span>
|
||||
</button>
|
||||
|
|
@ -212,7 +220,7 @@
|
|||
<label for="textarea1" class="sr-only">
|
||||
{{ _h("Text to translate") }}
|
||||
</label>
|
||||
<textarea id="textarea1" :maxLength="charactersLimit" v-model="inputText" @input="handleInput" ref="inputTextarea" dir="auto"></textarea>
|
||||
<textarea id="textarea1" :maxLength="charactersLimit" v-model="inputText" @input="handleInput" ref="inputTextarea" dir="auto" :disabled="disableInput"></textarea>
|
||||
<button class="btn-delete-text" title="{{ _h('Delete text') }}" aria-label="{{ _h('Delete text') }}" @click="deleteText">
|
||||
<i class="material-icons">close</i>
|
||||
</button>
|
||||
|
|
@ -224,7 +232,7 @@
|
|||
<label for="textarea2" class="sr-only">
|
||||
{{ _h("Translated text") }}
|
||||
</label>
|
||||
<textarea id="textarea2" v-model="translatedText" ref="translatedTextarea" dir="auto" v-bind:readonly="suggestions && !isSuggesting"></textarea>
|
||||
<textarea id="textarea2" v-model="translatedText" ref="translatedTextarea" dir="auto" v-bind:readonly="suggestions && !isSuggesting" :disabled="disableInput"></textarea>
|
||||
<div class="actions">
|
||||
<button v-if="suggestions && !loadingTranslation && inputText.length && !isSuggesting" class="btn-action" @click="suggestTranslation" aria-label="{{ _h('Suggest translation') }}">
|
||||
<i class="material-icons">edit</i>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue