From 8f074bf45e13544a86a36fef6f9ecbabe6733382 Mon Sep 17 00:00:00 2001 From: dogcraft Date: Mon, 1 May 2023 19:37:54 +0800 Subject: [PATCH] fix bug --- server.js | 9 +++++---- user.js | 10 +++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/server.js b/server.js index c938159..c40cfb2 100644 --- a/server.js +++ b/server.js @@ -31,7 +31,7 @@ function dog_add_fy(eldog) { const ctp = eldog.querySelector('div[style="container-type: inline-size;"]') const ctix = ctp.getElementsByTagName('div')[0]; // console.log(ctix); - ctix.setAttribute("class", "fanyi-cont"); + ctix.setAttribute("neko", "fanyi-cont"); const fyc = document.createElement("div"); fyc.setAttribute("class", "fanyi"); fyc.ct=0; @@ -55,7 +55,7 @@ function dog_add_fy_old(eldog) { dogbt.addEventListener('click', dog_fy);//绑定翻译函数 const ctdog=eldog.getElementsByClassName('content')[0]; const ydog = ctdog.getElementsByClassName('text')[0]; - ydog.setAttribute("class", "text fanyi-cont"); + ydog.setAttribute("neko", "text fanyi-cont"); const fyc = document.createElement("div"); fyc.setAttribute("class", "fanyi"); fyc.ct=0; @@ -76,7 +76,7 @@ async function dog_fy() { const dog_fy_el = ldog[0]; if (dog_fy_el.ct == 0) { console.log('还没有翻译'); - const hdog = pdog.getElementsByClassName('fanyi-cont')[0].innerText; + const hdog = pdog.querySelector('div[neko="fanyi-cont"]').innerText; post_dog = { 'c': hdog, 't': lang_dog }; dog_fy_el.innerText = '正在翻译中……'; uiy = await fetch(ApiUrl, { @@ -92,7 +92,8 @@ async function dog_fy() { } else { res_dog = '接口不对劲'; } - dog_fy_el.innerText = `\n${res_dog}`; + dog_fy_el.innerText = `${res_dog}`; + dog_fy_el.style.cssText=" margin-top: 1em; border: dashed 2px;border-radius: 10px;padding: 16px;"; dog_fy_el.ct = 1 this.childNodes[0].setAttribute("class", "ti ti-language-off"); this.style="color: red;"; diff --git a/user.js b/user.js index a082111..b491d6d 100644 --- a/user.js +++ b/user.js @@ -16,7 +16,6 @@ var ApiUrl = 'https://test1-api.dogcraft.top/ts/'; console.log('Misskey Translate Script v2.0'); - ApiUrl = 'https://test1-api.dogcraft.top/ts/'; var cat = localStorage.getItem('lang'); var vdog = localStorage.getItem('v'); @@ -48,7 +47,7 @@ var ApiUrl = 'https://test1-api.dogcraft.top/ts/'; const ctp = eldog.querySelector('div[style="container-type: inline-size;"]') const ctix = ctp.getElementsByTagName('div')[0]; // console.log(ctix); - ctix.setAttribute("class", "fanyi-cont"); + ctix.setAttribute("neko", "fanyi-cont"); const fyc = document.createElement("div"); fyc.setAttribute("class", "fanyi"); fyc.ct = 0; @@ -72,7 +71,7 @@ var ApiUrl = 'https://test1-api.dogcraft.top/ts/'; dogbt.addEventListener('click', dog_fy);//绑定翻译函数 const ctdog = eldog.getElementsByClassName('content')[0]; const ydog = ctdog.getElementsByClassName('text')[0]; - ydog.setAttribute("class", "text fanyi-cont"); + ydog.setAttribute("neko", "text fanyi-cont"); const fyc = document.createElement("div"); fyc.setAttribute("class", "fanyi"); fyc.ct = 0; @@ -93,7 +92,7 @@ var ApiUrl = 'https://test1-api.dogcraft.top/ts/'; const dog_fy_el = ldog[0]; if (dog_fy_el.ct == 0) { console.log('还没有翻译'); - const hdog = pdog.getElementsByClassName('fanyi-cont')[0].innerText; + const hdog = pdog.querySelector('div[neko="fanyi-cont"]').innerText; post_dog = { 'c': hdog, 't': lang_dog }; dog_fy_el.innerText = '正在翻译中……'; uiy = await fetch(ApiUrl, { @@ -109,7 +108,8 @@ var ApiUrl = 'https://test1-api.dogcraft.top/ts/'; } else { res_dog = '接口不对劲'; } - dog_fy_el.innerText = `\n${res_dog}`; + dog_fy_el.innerText = `${res_dog}`; + dog_fy_el.style.cssText = " margin-top: 1em; border: dashed 2px;border-radius: 10px;padding: 16px;"; dog_fy_el.ct = 1 this.childNodes[0].setAttribute("class", "ti ti-language-off"); this.style = "color: red;";