// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0 // API host/endpoint var BaseUrl = window.location.protocol + "//" + window.location.host + "{{ url_prefix }}" ; var htmlRegex = /<(.*)>.*?|<(.*)\/>/; document.addEventListener('DOMContentLoaded', function(){ var sidenavElems = document.querySelectorAll('.sidenav'); var sidenavInstances = M.Sidenav.init(sidenavElems); var app = new Vue({ el: '#app', delimiters: ['[[',']]'], data: { BaseUrl: BaseUrl, loading: true, error: "", langs: [], settings: {}, sourceLang: "", targetLang: "", loadingTranslation: false, inputText: "", inputTextareaHeight: 250, savedTanslatedText: "", translatedText: "", output: "", charactersLimit: -1, detectedLangText: "", copyTextLabel: {{ _e("Copy text") }}, suggestions: false, isSuggesting: false, supportedFilesFormat : [], translationType: "text", inputFile: false, loadingFileTranslation: false, translatedFileUrl: false, filesTranslation: true, frontendTimeout: 500, apiSecret: "{{ api_secret }}" }, mounted: function() { const self = this; self.$el.classList.add("loaded"); const settingsRequest = new XMLHttpRequest(); settingsRequest.open("GET", BaseUrl + "/frontend/settings", true); const langsRequest = new XMLHttpRequest(); langsRequest.open("GET", BaseUrl + "/languages", true); settingsRequest.onload = function() { if (this.status >= 200 && this.status < 400) { self.settings = JSON.parse(this.response); self.sourceLang = self.settings.language.source.code; self.targetLang = self.settings.language.target.code; self.charactersLimit = self.settings.charLimit; self.suggestions = self.settings.suggestions; self.supportedFilesFormat = self.settings.supportedFilesFormat; self.filesTranslation = self.settings.filesTranslation; self.frontendTimeout = self.settings.frontendTimeout; if (langsRequest.response) { handleLangsResponse(self, langsRequest); } else { langsRequest.onload = function() { handleLangsResponse(self, this); var hostname = window.location.hostname.toLowerCase(); if (hostname.indexOf("libretranslate.") === 0 && !hostname.endsWith(".com")){ self.error = "This website might be in violation of our trademark guidelines: https://github.com/LibreTranslate/LibreTranslate/blob/main/TRADEMARK.md"; } } } } else { self.error = {{ _e("Cannot load %(url)s", url="/frontend/settings") }}; self.loading = false; } }; settingsRequest.onerror = function() { self.error = {{ _e("Cannot load %(url)s", url="/frontend/settings") }}; self.loading = false; }; langsRequest.onerror = function() { self.error = {{ _e("Cannot load %(url)s", url="/languages") }}; self.loading = false; }; settingsRequest.send(); langsRequest.send(); }, updated: function(){ if (this.isSuggesting) return; M.FormSelect.init(this.$refs.sourceLangDropdown); M.FormSelect.init(this.$refs.targetLangDropdown); if (this.$refs.inputTextarea){ this.$refs.inputTextarea.focus() if (this.inputText === ""){ this.$refs.inputTextarea.style.height = this.inputTextareaHeight + "px"; this.$refs.translatedTextarea.style.height = this.inputTextareaHeight + "px"; } else{ this.$refs.inputTextarea.style.height = this.$refs.translatedTextarea.style.height = "1px"; this.$refs.inputTextarea.style.height = Math.max(this.inputTextareaHeight, this.$refs.inputTextarea.scrollHeight + 32) + "px"; this.$refs.translatedTextarea.style.height = Math.max(this.inputTextareaHeight, this.$refs.translatedTextarea.scrollHeight + 32) + "px"; } } // Update "selected" attribute (to overcome a vue.js limitation) // but properly display checkmarks on supported browsers. // Also change the