PluginProbe ʕ •ᴥ•ʔ
GPTranslate – Multilingual AI Translation for WordPress: Automatically Translate Websites / 2.12
GPTranslate – Multilingual AI Translation for WordPress: Automatically Translate Websites v2.12
2.33.6 2.33.5 2.33.2 2.32.10 2.33 2.33.1 2.32.6 2.32.7 2.32.8 trunk 2.10.3 2.10.4 2.10.5 2.10.6 2.11 2.12 2.13 2.14 2.14.1 2.15 2.15.1 2.16.1 2.16.2 2.17 2.18 2.18.1 2.18.2 2.19 2.20 2.21 2.22 2.23 2.24 2.25 2.25.1 2.25.2 2.26 2.27 2.27.10 2.27.5 2.28 2.28.1 2.29 2.30 2.31 2.32 2.32.5
gptranslate / assets / js / admin.js
gptranslate / assets / js Last commit date
jsonrepair 11 months ago admin.js 11 months ago dom.min.js 11 months ago gptranslate.js 11 months ago index.html 11 months ago responsivevoice.js 11 months ago toast.min.js 11 months ago
admin.js
2 lines
1 function e(e,t){const n=document.getElementById(e+"-container");n.innerHTML="",Object.entries(t).forEach((([e,t])=>{const a=document.createElement("div");a.classList.add("translation-row"),a.innerHTML=`<label class="badge bg-primary">${PLG_GPTRANSLATE_ORIGINAL_TEXT}</label><textarea type="text" class="original">${e}</textarea> ➜ \n <label class="badge bg-primary">${PLG_GPTRANSLATE_TRANSLATED_TEXT}</label><textarea type="text" class="translated">${t}</textarea>\n <button type="button" class="btn btn-danger" onclick="this.parentElement.remove()">${PLG_GPTRANSLATE_DELETE}</button>\n <button type="button" class="group-sync btn btn-warning btn-invisible hasPopover" data-type="translations" title="${PLG_GPTRANSLATE_SYNC_TITLE} - ${PLG_GPTRANSLATE_SYNC_DESC}" aria-label="${PLG_GPTRANSLATE_SYNC}">\n\t\t\t\t\t\t <span class="icon-refresh">↻</span> ${PLG_GPTRANSLATE_SYNC}</button>`,n.appendChild(a)}))}function t(e){const t=document.getElementById(e+"-container"),n={};return t.querySelectorAll("div").forEach((e=>{const t=e.querySelector(".original").value,a=e.querySelector(".translated").value;t&&a&&(n[t]=a)})),JSON.stringify(n)}document.addEventListener("DOMContentLoaded",(()=>{const n=localStorage.getItem("gptranslate_selected_tab");n&&document.getElementById("tab-"+n)&&(document.querySelectorAll(".nav-tab").forEach((e=>e.classList.remove("nav-tab-active"))),document.querySelectorAll(".tab-content").forEach((e=>e.style.display="none")),document.querySelector('a[href="#'+n+'"]').classList.add("nav-tab-active"),document.getElementById("tab-"+n).style.display="block"),"undefined"!=typeof initialTranslations&&(e("translations",initialTranslations),e("alt-translations",initialAltTranslations));const a=document.querySelector("form#edit-translations");a&&a.addEventListener("submit",(e=>{document.getElementById("translations_json").value=t("translations"),document.getElementById("alt_translations_json").value=t("alt-translations")})),document.querySelectorAll('input[type="submit"][data-action]').forEach((e=>{e.addEventListener("click",(function(){const e=this.getAttribute("data-action");document.getElementById("form_action").value=e}))})),document.querySelectorAll("button.btn-adder").forEach((e=>{e.addEventListener("click",(function(){!function(e){const t=document.getElementById(e+"-container"),n=document.createElement("div");n.classList.add("translation-row"),n.innerHTML=`<label class="badge bg-primary">${PLG_GPTRANSLATE_ORIGINAL_TEXT}</label><textarea type="text" class="original"></textarea> ➜ \n <label class="badge bg-primary">${PLG_GPTRANSLATE_TRANSLATED_TEXT}</label><textarea type="text" class="translated"></textarea>\n <button type="button" class="btn btn-danger" onclick="this.parentElement.remove()">${PLG_GPTRANSLATE_DELETE}</button>`,t.insertBefore(n,t.firstChild)}(this.getAttribute("data-addtype"))}))})),document.querySelectorAll("textarea.translated").forEach((function(e,t){e.addEventListener("keyup",(function(e){const t=e.target.closest("div.translation-row").querySelector("button.group-sync");t&&t.classList.remove("btn-invisible")}))}));const o=document.getElementById("checkall");o&&o.addEventListener("change",(function(){document.querySelectorAll('input[name="gptid[]"]').forEach((e=>e.checked=o.checked))})),document.addEventListener("click",(function(e){const t=e.target.closest('button[data-role="search-translations"]');if(t){const e=t.closest("div.gptcard"),n=e.querySelector('input[name="search"]').value,a=e.querySelectorAll("div.translation-row"),o=new RegExp(n,"i");a.forEach((function(e){const t=e.querySelector('textarea[class="original"]').value,n=e.querySelector('textarea[class="translated"]').value;o.test(t)||o.test(n)?e.classList.remove("translation-row-hidden"):e.classList.add("translation-row-hidden")}))}const n=e.target.closest('button[data-role="reset-search"]');if(n){const e=n.closest("div.gptcard");e.querySelector('input[name="search"]').value="";e.querySelectorAll("div.translation-row").forEach((function(e){e.classList.remove("translation-row-hidden")}))}})),document.querySelectorAll("button.group-sync").forEach((function(e,t){e.addEventListener("click",(function(e){const t=e.currentTarget,n=t.querySelector("span.icon-refresh"),a=t.closest("div.translation-row"),o=a.querySelector("textarea.original"),l=a.querySelector("textarea.translated"),r=t.dataset.type,c=o.value,s=l.value,i=document.getElementById("languagetranslated").value;n.classList.add("icon-working");const d={task:"syncTranslation",original:c,translated:s,language_translated:i,translation_type:r},u=`${gptServerSideLink}`,m={method:"POST",body:JSON.stringify(d),headers:{"Content-Type":"application/json; charset=utf-8",Accept:"application/json","x-gptranslate-key":gptranslate_vars.gptApiKey}};fetch(u,m).then((e=>e.json())).then((e=>{if(e.result){const e=document.createElement("label");e.className="gpt-label badge bg-success",e.innerText=PLG_GPTRANSLATE_SYNC_COMPLETED,t.insertAdjacentElement("afterend",e)}else{const e=document.createElement("label");e.className="gpt-label badge bg-danger",e.innerText=PLG_GPTRANSLATE_SYNC_ERROR,t.insertAdjacentElement("afterend",e)}})).catch((e=>{const n=document.createElement("label");n.className="gpt-label badge bg-danger",n.innerText=PLG_GPTRANSLATE_SYNC_ERROR,t.insertAdjacentElement("afterend",n)})).finally((()=>{n.classList.remove("icon-working"),setTimeout((()=>{t.classList.add("btn-invisible"),document.querySelectorAll("label.gpt-label").forEach((e=>e.remove()))}),2e3)}))}))}));const l=document.createElement("div");l.className="custom-tooltip",document.body.appendChild(l),document.querySelectorAll("[title]").forEach((function(e){const t=e.getAttribute("title");e.addEventListener("mouseenter",(function(n){e.setAttribute("data-original-title",t),e.removeAttribute("title"),l.textContent=t,l.style.opacity="1"})),e.addEventListener("mousemove",(function(e){l.style.top=e.pageY+10+"px",l.style.left=e.pageX+10+"px"})),e.addEventListener("mouseleave",(function(){l.style.opacity="0",e.setAttribute("title",e.getAttribute("data-original-title"))}))}));const r=document.getElementById("config-gptranslate"),c=document.querySelector("div.action-buttons-toolbar");if(r){document.querySelectorAll("h2.nav-tab-wrapper a.nav-tab").forEach((function(e,t){e.addEventListener("click",(function(t){const n=e.dataset.click;var a;a=n,document.querySelectorAll(".tab-content").forEach((e=>e.style.display="none")),document.querySelectorAll(".nav-tab").forEach((e=>e.classList.remove("nav-tab-active"))),document.getElementById("tab-"+a).style.display="block",event.currentTarget.classList.add("nav-tab-active"),localStorage.setItem("gptranslate_selected_tab",a)}))}));const s=document.querySelector('select[name="gptranslate_options[google_translate_engine]"]'),i=document.querySelectorAll(".chatgpt_ctrl"),d=document.getElementById("chatgpt_apikey");function u(e){i.forEach((function(t){const n=t.closest("tr")||t.closest(".control-group")||t.closest(".form-group");n&&("0"==e?(n.style.display="",d&&d.setAttribute("data-validation","required")):(n.style.display="none",d&&d.removeAttribute("data-validation")))}))}s&&(u(s.value),s.addEventListener("change",(function(){u(this.value)})));const m=document.getElementById("chatgpt_model"),p=document.querySelector('label[for="chatgpt_apikey"]');if(m&&p){const O=()=>{const e=p.getAttribute("data-original-text")||p.textContent;p.getAttribute("data-original-text")||p.setAttribute("data-original-text",e),p.textContent=e.replace("DeepSeek","{aiengine}").replace("Gemini","{aiengine}").replace("ChatGPT","{aiengine}");const t=m.value;"deepseek-chat"===t?p.textContent=p.textContent.replace("{aiengine}","DeepSeek"):0===t.indexOf("gemini-")?p.textContent=p.textContent.replace("{aiengine}","Gemini"):p.textContent=p.textContent.replace("{aiengine}","ChatGPT")};O(),m.addEventListener("change",O)}const g=document.querySelectorAll('input[name="gptranslate_options[rewrite_language_url]"]'),E=document.querySelectorAll(".urlrewriting");function y(e,t){document.querySelectorAll(`input[name="${e}"]`).forEach((e=>{const n=e.closest("label");e.value===t?(e.checked=!0,n?.classList.add("active")):n?.classList.remove("active")}))}Array.from(g).find((e=>e.checked));g.forEach((e=>{e.addEventListener("change",(function(){var e;e=this.value,E.forEach((t=>{const n=t.closest("tr")||t.closest(".control-group");n&&(n.style.display="1"==e?"":"none")})),"1"==e&&(y("gptranslate_options[detect_current_language]","1"),y("gptranslate_options[autotranslate_detected_language]","1"),y("gptranslate_options[always_detect_autotranslated_language]","1"))}))}));const _=document.querySelectorAll('input[name="gptranslate_options[serverside_translations]"]'),v=document.querySelectorAll(".serverside_translations");function f(e){v.forEach((t=>{const n=t.closest(".form-table tr")||t.closest(".control-group");n&&(n.style.display="1"==e?"":"none")}))}const L=Array.from(_).find((e=>e.checked))?.value;f(L),_.forEach((e=>{e.addEventListener("change",(function(){if(f(this.value),"1"==this.value){const e=document.querySelector('input[name="gptranslate_options[rewrite_language_url]"][value="0"]'),t=document.querySelector('input[name="gptranslate_options[rewrite_language_url]"][value="1"]');e&&t&&(t.checked=!0,e.checked=!1,t.dispatchEvent(new Event("change",{bubbles:!0})))}}))}));const b=document.querySelectorAll('input[name="gptranslate_options[translate_altimages]"]'),h=document.getElementById("css_selector_classes_translate_altimages_excluded")?.closest(".form-table tr");function S(e){h&&(h.style.display="1"==e?"":"none")}const A=Array.from(b).find((e=>e.checked))?.value;S(A),b.forEach((e=>{e.addEventListener("change",(function(){S(this.value)}))}));const T=document.getElementById("serverside_translations_method"),q=document.getElementById("css_selector_serverside_leafnodes_excluded")?.closest(".form-table tr"),w=document.getElementById("serverside_translations_matchquotes1")?.closest("label");function N(e){if(q&&(q.style.display="strireplace"===e?"none":""),"simplehtmldom"===e&&w){const e=w.querySelector("input");e&&(e.checked=!0)}}T&&(N(T.value),T.addEventListener("change",(function(){N(this.value)})));const G=document.querySelectorAll('input[name="gptranslate_options[detect_current_language]"]'),P=document.querySelectorAll('input[name="gptranslate_options[detect_default_language]"]');G.forEach((e=>{e.addEventListener("click",(()=>{if(1===parseInt(e.value)){const e=document.querySelector('input[name="gptranslate_options[detect_default_language]"][value="0"]');e&&!e.checked&&(e.checked=!0)}}))})),P.forEach((e=>{e.addEventListener("click",(()=>{if(1===parseInt(e.value)){const e=document.querySelector('input[name="gptranslate_options[detect_current_language]"][value="0"]');e&&!e.checked&&(e.checked=!0)}}))}));const R=document.getElementById("words_leafnodes_excluded_bylanguage_repeatable-body"),k=document.getElementById("add-repeatable-row"),x=document.getElementById("words_leafnodes_excluded_bylanguage_repeatable");function I(e={}){const t=document.createElement("tr");t.classList.add("repeatable-row");const n=document.querySelector('select[name="gptranslate_options[language]"]'),a=`\n <option value="*">All languages</option>\n ${n?n.innerHTML:""}\n `;t.innerHTML=`\n <td><input type="text" class="widefat word" value="${e.word||""}" /></td>\n <td>\n <select class="widefat lang-original">\n ${a}\n </select>\n </td>\n <td>\n <select class="widefat lang-translated">\n ${a}\n </select>\n </td>\n <td><input type="text" class="widefat optional-translation" value="${e.optionalTranslation||""}" /></td>\n <td>\n <button type="button" class="button button-secondary move-row" draggable="true" title="${PLG_GPTRANSLATE_MOVE}">�
2 </button>\n <button type="button" class="button button-secondary remove-row" title="${PLG_GPTRANSLATE_REMOVE}"></button>\n </td>\n `;const o=t.querySelector(".lang-original"),l=t.querySelector(".lang-translated");return o.value=e.langOriginal||"*",l.value=e.langTranslated||"*",t}function B(){const e=R.querySelectorAll("tr.repeatable-row"),t=[];e.forEach((e=>{t.push({word:e.querySelector(".word").value,langOriginal:e.querySelector(".lang-original").value,langTranslated:e.querySelector(".lang-translated").value,optionalTranslation:e.querySelector(".optional-translation").value})})),x.value=JSON.stringify(t)}k.addEventListener("click",(function(){const e=I();R.appendChild(e),B()})),R.addEventListener("click",(function(e){e.target.classList.contains("remove-row")&&(e.target.closest("tr").remove(),B())})),R.addEventListener("input",(function(){B()}));let C=null;R.addEventListener("dragstart",(function(e){e.target.classList.contains("move-row")&&(C=e.target.closest("tr"),C.style.opacity="0.5")})),R.addEventListener("dragend",(function(){C&&(C.style.opacity="",C=null)})),R.addEventListener("dragover",(function(e){if(!C)return;e.preventDefault();const t=e.target.closest("tr");if(t&&t!==C){const n=t.getBoundingClientRect();e.clientY-n.top>n.height/2?t.after(C):t.before(C)}})),R.addEventListener("drop",(function(){C&&B()})),document.querySelector(".button-import").addEventListener("click",(function(){document.querySelectorAll(".toggle-import").forEach((e=>{e.classList.toggle("hidden")}))}));try{JSON.parse(x.value||"[]").forEach((e=>{const t=I(e);R.appendChild(t)}))}catch($){}}else c&&(document.getElementById("notranslations-notice")&&document.querySelectorAll(".form-filter-container, .action-buttons-toolbar, table.widefat.fixed.striped,div.tablenav").forEach((function(e){e.style.display="none"})),document.querySelector(".button-import").addEventListener("click",(function(){document.querySelectorAll(".toggle-import").forEach((e=>{e.classList.toggle("hidden")}))})),document.getElementById("toggle-migration").addEventListener("click",(function(){const e=document.getElementById("migraterow");e.style.display="none"===e.style.display||""===e.style.display?"flex":"none",e.style.alignItems="center"})),document.getElementById("migrationcancel").addEventListener("click",(function(){document.getElementById("migratetranslations_currentdomain").value="",document.getElementById("migratetranslations_newdomain").value=""})),document.getElementById("migrationconfirm").addEventListener("click",(function(){const e=document.getElementById("migratetranslations_currentdomain").value.trim(),t=document.getElementById("migratetranslations_newdomain").value.trim();if(!e||!t)return void alert("Please enter both domains.");const n=new FormData;n.append("action","gptranslate_migrate_translations"),n.append("old_domain",e),n.append("new_domain",t),n.append("_wpnonce",gptranslate_vars.nonce),fetch(gptranslate_vars.ajaxurl,{method:"POST",body:n}).then((e=>e.json())).then((e=>{const t=document.createElement("div");if(t.className="notice is-dismissible",e.success)t.classList.add("notice-success"),t.innerHTML="<p>"+PLG_GPTRANSLATE_MIGRATION_SUCCESS+"</p>",document.querySelector("#wpcontent").prepend(t),setTimeout((()=>{window.location.reload()}),1500);else{t.classList.add("notice-error");const n=e.data||PLG_GPTRANSLATE_UNKNOWN_ERROR;t.innerHTML="<p>"+PLG_GPTRANSLATE_MIGRATION_FAILED+": "+n+"</p>",document.querySelector("#wpcontent").prepend(t)}})).catch((()=>{const e=document.createElement("div");e.className="notice notice-error is-dismissible",e.innerHTML="<p>"+PLG_GPTRANSLATE_NETWORK_ERROR+"</p>",document.querySelector("#wpcontent").prepend(e)}))})),document.getElementById("bulk-delete-btn").addEventListener("click",(function(){const e=Array.from(document.querySelectorAll('input[name="gptid[]"]:checked')).map((e=>e.value));if(0===e.length)return void alert(PLG_GPTRANSLATE_BULK_DELETE_SELECT_ONE);if(!confirm(PLG_GPTRANSLATE_BULK_DELETE_CONFIRM))return;const t=new FormData;t.append("action","gptranslate_bulk_delete"),t.append("_wpnonce",gptranslate_vars.deletenonce),e.forEach((e=>t.append("gptid[]",e))),fetch(gptranslate_vars.ajaxurl,{method:"POST",body:t}).then((e=>e.json())).then((e=>{const t=document.createElement("div");t.className="notice is-dismissible",e.success?(t.classList.add("notice-success"),t.innerHTML="<p>"+PLG_GPTRANSLATE_BULK_DELETE_SUCCESS+"</p>",document.querySelector("#wpcontent").prepend(t),setTimeout((()=>{window.location.href=window.location.origin+window.location.pathname+"?page=gptranslate"}),250)):(t.classList.add("notice-error"),t.innerHTML="<p>"+PLG_GPTRANSLATE_BULK_DELETE_ERROR+": "+(e.data||PLG_GPTRANSLATE_UNKNOWN_ERROR)+"</p>",document.querySelector("#wpcontent").prepend(t))})).catch((()=>{const e=document.createElement("div");e.className="notice notice-error is-dismissible",e.innerHTML="<p>"+PLG_GPTRANSLATE_BULK_DELETE_NETWORK+"</p>",document.querySelector("#wpcontent").prepend(e)}))})))}));