前提
DeepL Code BlockerのようなChrome拡張機能の作り方を教えて欲しいです。
私はDeepL Chrome 拡張機能のヘビーユーザーですが、GitHubでの使い勝手が良くないです。翻訳が不要な単語(例えばFlutter, Goなど)やリポジトリのタイトルまで翻訳してGithubのページを非常に見づらくしてしまいます。
DeepL Code Blocker( https://chrome.google.com/webstore/detail/deepl-code-blocker/blmfehnodbgjheaofcecmjbbapmaikap?hl=ja )のようなChrome拡張機能を開発しようと思っています。
DeepLやGoogle翻訳から特定の単語群を翻訳させないようなアプローチは具体的にはどのように行えばいいでしょうか。私はTypeScriptやJavaScriptはあまり詳しくありません。
deeple code blockerで動いているスクリプト
javascript
1(() => { 2 "use strict"; 3 class e { 4 static isElement(e) { 5 return 1 === e.nodeType; 6 } 7 } 8 const t = (e, t) => { 9 const n = [...e.childNodes]; 10 for (; n.length; ) { 11 const e = n.shift(); 12 if (!e) break; 13 if (t(e)) return !0; 14 n.concat(e.childNodes ? [...e.childNodes] : []); 15 } 16 return !1; 17 }; 18 [ 19 ...[...document.getElementsByTagName("code")].filter( 20 (n) => !t(n, (t) => e.isElement(t) && "PRE" === t.tagName) 21 ), 22 ...[...document.getElementsByTagName("pre")].filter( 23 (n) => !t(n, (t) => e.isElement(t) && "CODE" === t.tagName) 24 ), 25 ].forEach((e) => 26 ((e) => { 27 ((e) => { 28 const t = (e) => { 29 const t = window.getComputedStyle(e); 30 [ 31 "background-color", 32 "display", 33 "color", 34 "letter-spacing", 35 "line-height", 36 "content-wrap", 37 "font-size", 38 "font-weight", 39 "font", 40 ].forEach((n) => { 41 e.style.setProperty(n, t.getPropertyValue(n)); 42 }); 43 }, 44 n = [{ element: e, visited: !1 }]; 45 for (; n.length; ) { 46 const e = n.pop(); 47 if (!e) continue; 48 const o = [...e.element.children].flatMap((e) => 49 e instanceof HTMLElement ? [e] : [] 50 ); 51 if (e.visited || !o.length) t(e.element); 52 else { 53 const t = [ 54 { element: e.element, visited: !0 }, 55 ...o.map((e) => ({ element: e, visited: !1 })), 56 ]; 57 n.push(...t); 58 } 59 } 60 })(e); 61 const t = document.createElement("div"); 62 (t.style.display = window.getComputedStyle(e).display), 63 (t.attachShadow({ mode: "closed" }).innerHTML = e.outerHTML), 64 e.replaceWith(t); 65 })(e) 66 ); 67})(); 68
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/11/17 16:25
2022/11/17 16:28
2022/11/17 21:46