From 511ee3303f35f8b912c010dc1b0c9c647ee5167a Mon Sep 17 00:00:00 2001 From: makinzm Date: Wed, 25 Dec 2024 06:35:47 +0900 Subject: [PATCH] fix: included rendering --- dist/options/options.js | 2 +- src/options/options.ts | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/dist/options/options.js b/dist/options/options.js index af81234..7c3a734 100644 --- a/dist/options/options.js +++ b/dist/options/options.js @@ -1 +1 @@ -(()=>{"use strict";var e={379:function(e,t){var n=this&&this.__awaiter||function(e,t,n,o){return new(n||(n=Promise))((function(i,d){function l(e){try{c(o.next(e))}catch(e){d(e)}}function a(e){try{c(o.throw(e))}catch(e){d(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,a)}c((o=o.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.LocalDatabase=void 0,t.LocalDatabase=class{constructor(){this.STORAGE_KEY="word_entries",this.EXCLUDED_DOMAIN_KEY="excluded_domains",this.INCLUDED_DOMAIN_KEY="included_domains"}getAll(){return n(this,void 0,void 0,(function*(){console.log("Getting all entries from storage...");const e=yield chrome.storage.local.get(this.STORAGE_KEY);return console.log("All entries:",e),e[this.STORAGE_KEY]||[]}))}save(e){return n(this,void 0,void 0,(function*(){const t=yield this.getAll(),n=t.findIndex((t=>t.key===e.key));n>-1?t[n]=e:t.push(e),yield chrome.storage.local.set({[this.STORAGE_KEY]:t})}))}delete(e){return n(this,void 0,void 0,(function*(){const t=(yield this.getAll()).filter((t=>t.key!==e));yield chrome.storage.local.set({[this.STORAGE_KEY]:t})}))}getAllExcludedDomains(){return n(this,void 0,void 0,(function*(){return(yield chrome.storage.local.get(this.EXCLUDED_DOMAIN_KEY))[this.EXCLUDED_DOMAIN_KEY]||[]}))}addExcludedDomain(e){return n(this,void 0,void 0,(function*(){const t=yield this.getAllExcludedDomains();t.some((t=>t.domain===e))||(t.push({domain:e}),yield chrome.storage.local.set({[this.EXCLUDED_DOMAIN_KEY]:t}))}))}removeExcludedDomain(e){return n(this,void 0,void 0,(function*(){const t=(yield this.getAllExcludedDomains()).filter((t=>t.domain!==e));yield chrome.storage.local.set({[this.EXCLUDED_DOMAIN_KEY]:t})}))}getAllIncludedDomains(){return n(this,void 0,void 0,(function*(){return(yield chrome.storage.local.get(this.INCLUDED_DOMAIN_KEY))[this.INCLUDED_DOMAIN_KEY]||[]}))}addIncludedDomain(e){return n(this,void 0,void 0,(function*(){const t=yield this.getAllIncludedDomains();t.some((t=>t.domain===e))||(t.push({domain:e}),yield chrome.storage.local.set({[this.INCLUDED_DOMAIN_KEY]:t}))}))}removeIncludedDomain(e){return n(this,void 0,void 0,(function*(){const t=(yield this.getAllIncludedDomains()).filter((t=>t.domain!==e));yield chrome.storage.local.set({[this.INCLUDED_DOMAIN_KEY]:t})}))}}},115:function(e,t,n){var o=this&&this.__awaiter||function(e,t,n,o){return new(n||(n=Promise))((function(i,d){function l(e){try{c(o.next(e))}catch(e){d(e)}}function a(e){try{c(o.throw(e))}catch(e){d(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,a)}c((o=o.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const i=new(n(379).LocalDatabase),d=document.getElementById("dateFrom"),l=document.getElementById("dateTo"),a=document.getElementById("filterButton"),c=document.getElementById("prioritySort"),r=document.getElementById("wordsTableBody");let s=[];function u(){return o(this,arguments,void 0,(function*(e={}){let t=yield i.getAll();e.from&&(t=t.filter((t=>new Date(t.addedDate)>=e.from))),e.to&&(t=t.filter((t=>new Date(t.addedDate)<=e.to))),e.prioritySort?t.sort(((t,n)=>"asc"===e.prioritySort?t.priority===n.priority?new Date(t.addedDate).getTime()-new Date(n.addedDate).getTime():t.priority-n.priority:"desc"===e.prioritySort?t.priority===n.priority?new Date(n.addedDate).getTime()-new Date(t.addedDate).getTime():n.priority-t.priority:0)):t.sort(((e,t)=>e.priority===t.priority?new Date(t.addedDate).getTime()-new Date(e.addedDate).getTime():t.priority-e.priority)),s=t,v()}))}let m=1;const h=10,y=document.getElementById("pagination");function p(){y.innerHTML="";const e=Math.ceil(s.length/h),t=document.createElement("button");t.textContent="前へ",t.className="pagination-button",t.disabled=1===m,t.addEventListener("click",(()=>{m>1&&(m--,v(),p())})),y.appendChild(t);const n=document.createElement("button");n.textContent="次へ",n.className="pagination-button",n.disabled=m===e,n.addEventListener("click",(()=>{m${e.key}\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n ${new Date(e.addedDate).toLocaleString()}\n \n \n \n \n \n \n \n `,t.querySelector(".add-example").addEventListener("click",(()=>{const t=prompt("新しい例文を入力してください:");t&&(e.examples.push(t),v())})),t.querySelectorAll(".delete-example").forEach((t=>{t.addEventListener("click",(()=>{const n=Number(t.getAttribute("data-index"));e.examples.splice(n,1),v()}))})),t.querySelector(".save-changes").addEventListener("click",(()=>o(this,void 0,void 0,(function*(){const n=t.querySelector(".note-area"),o=t.querySelector(".priority-select");e.note=n.value,e.priority=Number(o.value),yield i.save(e),console.log("保存しました")})))),t.querySelector(".delete-key").addEventListener("click",(()=>o(this,void 0,void 0,(function*(){yield i.delete(e.key),u()})))),r.appendChild(t)}p()}a.addEventListener("click",(()=>{u({from:d.value?new Date(d.value):void 0,to:l.value?new Date(l.value):void 0,prioritySort:c.value})}));const g=document.getElementById("excludedDomainInput"),E=document.getElementById("addExcludedDomainButton"),D=document.getElementById("excludedDomainList");function f(){return o(this,void 0,void 0,(function*(){const e=yield i.getAllExcludedDomains();D.innerHTML="";for(const t of e){const e=document.createElement("li");e.textContent=t.domain;const n=document.createElement("button");n.textContent="削除",n.addEventListener("click",(()=>o(this,void 0,void 0,(function*(){yield i.removeExcludedDomain(t.domain),f()})))),e.appendChild(n),D.appendChild(e)}}))}E.addEventListener("click",(()=>o(void 0,void 0,void 0,(function*(){const e=g.value.trim();e&&(yield i.addExcludedDomain(e),g.value="",f())}))));const x="domainFilterMode",I=document.getElementById("radioExclude"),_=document.getElementById("radioInclude"),k=document.getElementById("excludeSettings"),b=document.getElementById("includeSettings");function L(e){"exclude"===e?(k.style.display="block",b.style.display="none"):(k.style.display="none",b.style.display="block"),localStorage.setItem("domainFilterMode",e)}I.addEventListener("change",(()=>L("exclude"))),_.addEventListener("change",(()=>L("include"))),"exclude"===(localStorage.getItem("domainFilterMode")||"include")?(I.checked=!0,L("exclude")):(_.checked=!0,L("include")),f(),u(),function(){o(this,void 0,void 0,(function*(){var e;"include"===(null!==(e=(yield chrome.storage.local.get(x))[x])&&void 0!==e?e:"exclude")?_.checked=!0:I.checked=!0}))}(),function(){[I,_].forEach((e=>{e.addEventListener("change",(()=>o(this,void 0,void 0,(function*(){e.checked&&(yield chrome.storage.local.set({[x]:e.value}))}))))}))}()}},t={};!function n(o){var i=t[o];if(void 0!==i)return i.exports;var d=t[o]={exports:{}};return e[o].call(d.exports,d,d.exports,n),d.exports}(115)})(); \ No newline at end of file +(()=>{"use strict";var e={379:function(e,t){var n=this&&this.__awaiter||function(e,t,n,o){return new(n||(n=Promise))((function(i,d){function l(e){try{c(o.next(e))}catch(e){d(e)}}function a(e){try{c(o.throw(e))}catch(e){d(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,a)}c((o=o.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.LocalDatabase=void 0,t.LocalDatabase=class{constructor(){this.STORAGE_KEY="word_entries",this.EXCLUDED_DOMAIN_KEY="excluded_domains",this.INCLUDED_DOMAIN_KEY="included_domains"}getAll(){return n(this,void 0,void 0,(function*(){console.log("Getting all entries from storage...");const e=yield chrome.storage.local.get(this.STORAGE_KEY);return console.log("All entries:",e),e[this.STORAGE_KEY]||[]}))}save(e){return n(this,void 0,void 0,(function*(){const t=yield this.getAll(),n=t.findIndex((t=>t.key===e.key));n>-1?t[n]=e:t.push(e),yield chrome.storage.local.set({[this.STORAGE_KEY]:t})}))}delete(e){return n(this,void 0,void 0,(function*(){const t=(yield this.getAll()).filter((t=>t.key!==e));yield chrome.storage.local.set({[this.STORAGE_KEY]:t})}))}getAllExcludedDomains(){return n(this,void 0,void 0,(function*(){return(yield chrome.storage.local.get(this.EXCLUDED_DOMAIN_KEY))[this.EXCLUDED_DOMAIN_KEY]||[]}))}addExcludedDomain(e){return n(this,void 0,void 0,(function*(){const t=yield this.getAllExcludedDomains();t.some((t=>t.domain===e))||(t.push({domain:e}),yield chrome.storage.local.set({[this.EXCLUDED_DOMAIN_KEY]:t}))}))}removeExcludedDomain(e){return n(this,void 0,void 0,(function*(){const t=(yield this.getAllExcludedDomains()).filter((t=>t.domain!==e));yield chrome.storage.local.set({[this.EXCLUDED_DOMAIN_KEY]:t})}))}getAllIncludedDomains(){return n(this,void 0,void 0,(function*(){return(yield chrome.storage.local.get(this.INCLUDED_DOMAIN_KEY))[this.INCLUDED_DOMAIN_KEY]||[]}))}addIncludedDomain(e){return n(this,void 0,void 0,(function*(){const t=yield this.getAllIncludedDomains();t.some((t=>t.domain===e))||(t.push({domain:e}),yield chrome.storage.local.set({[this.INCLUDED_DOMAIN_KEY]:t}))}))}removeIncludedDomain(e){return n(this,void 0,void 0,(function*(){const t=(yield this.getAllIncludedDomains()).filter((t=>t.domain!==e));yield chrome.storage.local.set({[this.INCLUDED_DOMAIN_KEY]:t})}))}}},115:function(e,t,n){var o=this&&this.__awaiter||function(e,t,n,o){return new(n||(n=Promise))((function(i,d){function l(e){try{c(o.next(e))}catch(e){d(e)}}function a(e){try{c(o.throw(e))}catch(e){d(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,a)}c((o=o.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const i=new(n(379).LocalDatabase),d=document.getElementById("dateFrom"),l=document.getElementById("dateTo"),a=document.getElementById("filterButton"),c=document.getElementById("prioritySort"),r=document.getElementById("wordsTableBody");let s=[];function u(){return o(this,arguments,void 0,(function*(e={}){let t=yield i.getAll();e.from&&(t=t.filter((t=>new Date(t.addedDate)>=e.from))),e.to&&(t=t.filter((t=>new Date(t.addedDate)<=e.to))),e.prioritySort?t.sort(((t,n)=>"asc"===e.prioritySort?t.priority===n.priority?new Date(t.addedDate).getTime()-new Date(n.addedDate).getTime():t.priority-n.priority:"desc"===e.prioritySort?t.priority===n.priority?new Date(n.addedDate).getTime()-new Date(t.addedDate).getTime():n.priority-t.priority:0)):t.sort(((e,t)=>e.priority===t.priority?new Date(t.addedDate).getTime()-new Date(e.addedDate).getTime():t.priority-e.priority)),s=t,p()}))}let m=1;const h=10,y=document.getElementById("pagination");function v(){y.innerHTML="";const e=Math.ceil(s.length/h),t=document.createElement("button");t.textContent="前へ",t.className="pagination-button",t.disabled=1===m,t.addEventListener("click",(()=>{m>1&&(m--,p(),v())})),y.appendChild(t);const n=document.createElement("button");n.textContent="次へ",n.className="pagination-button",n.disabled=m===e,n.addEventListener("click",(()=>{m${e.key}\n \n \n \n \n \n \n \n \n \n \n
    \n ${e.examples.map(((e,t)=>`\n
  • ${e}
  • \n `)).join("")}\n
\n \n \n \n \n \n ${new Date(e.addedDate).toLocaleString()}\n \n \n \n \n \n \n \n `,t.querySelector(".add-example").addEventListener("click",(()=>{const t=prompt("新しい例文を入力してください:");t&&(e.examples.push(t),p())})),t.querySelectorAll(".delete-example").forEach((t=>{t.addEventListener("click",(()=>{const n=Number(t.getAttribute("data-index"));e.examples.splice(n,1),p()}))})),t.querySelector(".save-changes").addEventListener("click",(()=>o(this,void 0,void 0,(function*(){const n=t.querySelector(".note-area"),o=t.querySelector(".priority-select");e.note=n.value,e.priority=Number(o.value),yield i.save(e),console.log("保存しました")})))),t.querySelector(".delete-key").addEventListener("click",(()=>o(this,void 0,void 0,(function*(){yield i.delete(e.key),u()})))),r.appendChild(t)}v()}a.addEventListener("click",(()=>{u({from:d.value?new Date(d.value):void 0,to:l.value?new Date(l.value):void 0,prioritySort:c.value})}));const E=document.getElementById("excludedDomainInput"),g=document.getElementById("addExcludedDomainButton"),D=document.getElementById("excludedDomainList");function f(){return o(this,void 0,void 0,(function*(){const e=yield i.getAllExcludedDomains();D.innerHTML="";for(const t of e){const e=document.createElement("li");e.textContent=t.domain;const n=document.createElement("button");n.textContent="削除",n.addEventListener("click",(()=>o(this,void 0,void 0,(function*(){yield i.removeExcludedDomain(t.domain),f()})))),e.appendChild(n),D.appendChild(e)}}))}g.addEventListener("click",(()=>o(void 0,void 0,void 0,(function*(){const e=E.value.trim();e&&(yield i.addExcludedDomain(e),E.value="",f())}))));const I=document.getElementById("includedDomainInput"),x=document.getElementById("addIncludedDomainButton"),k=document.getElementById("includedDomainList");function _(){return o(this,void 0,void 0,(function*(){const e=yield i.getAllIncludedDomains();k.innerHTML="";for(const t of e){const e=document.createElement("li");e.textContent=t.domain;const n=document.createElement("button");n.textContent="削除",n.addEventListener("click",(()=>o(this,void 0,void 0,(function*(){yield i.removeIncludedDomain(t.domain),_()})))),e.appendChild(n),k.appendChild(e)}}))}x.addEventListener("click",(()=>o(void 0,void 0,void 0,(function*(){const e=I.value.trim();e&&(yield i.addIncludedDomain(e),I.value="",_())}))));const L="domainFilterMode",b=document.getElementById("radioExclude"),A=document.getElementById("radioInclude"),w=document.getElementById("excludeSettings"),C=document.getElementById("includeSettings");function M(e){"exclude"===e?(w.style.display="block",C.style.display="none"):(w.style.display="none",C.style.display="block"),localStorage.setItem("domainFilterMode",e)}b.addEventListener("change",(()=>M("exclude"))),A.addEventListener("change",(()=>M("include"))),"exclude"===(localStorage.getItem("domainFilterMode")||"include")?(b.checked=!0,M("exclude")):(A.checked=!0,M("include")),f(),_(),u(),function(){o(this,void 0,void 0,(function*(){var e;"include"===(null!==(e=(yield chrome.storage.local.get(L))[L])&&void 0!==e?e:"exclude")?A.checked=!0:b.checked=!0}))}(),function(){[b,A].forEach((e=>{e.addEventListener("change",(()=>o(this,void 0,void 0,(function*(){e.checked&&(yield chrome.storage.local.set({[L]:e.value}))}))))}))}()}},t={};!function n(o){var i=t[o];if(void 0!==i)return i.exports;var d=t[o]={exports:{}};return e[o].call(d.exports,d,d.exports,n),d.exports}(115)})(); \ No newline at end of file diff --git a/src/options/options.ts b/src/options/options.ts index cdf9804..b77b089 100644 --- a/src/options/options.ts +++ b/src/options/options.ts @@ -270,6 +270,39 @@ addExcludedDomainButton.addEventListener("click", async () => { } }); +// DOM要素取得 +const includedDomainInput = document.getElementById("includedDomainInput") as HTMLInputElement; +const addIncludedDomainButton = document.getElementById("addIncludedDomainButton") as HTMLButtonElement; +const includedDomainList = document.getElementById("includedDomainList") as HTMLUListElement; + +// included_domainsリストの表示更新関数 +async function renderIncludedDomains() { + const domains = await db.getAllIncludedDomains(); + includedDomainList.innerHTML = ""; + for (const d of domains) { + const li = document.createElement("li"); + li.textContent = d.domain; + const removeBtn = document.createElement("button"); + removeBtn.textContent = "削除"; + removeBtn.addEventListener("click", async () => { + await db.removeIncludedDomain(d.domain); + renderIncludedDomains(); + }); + li.appendChild(removeBtn); + includedDomainList.appendChild(li); + } +} + +// Includeドメイン追加ボタンのイベントリスナー +addIncludedDomainButton.addEventListener("click", async () => { + const domain = includedDomainInput.value.trim(); + if (domain) { + await db.addIncludedDomain(domain); + includedDomainInput.value = ""; // 入力欄をクリア + renderIncludedDomains(); + } +}); + // 1) モード保存先キーを決める const DOMAIN_FILTER_MODE_KEY = "domainFilterMode"; @@ -332,6 +365,7 @@ radioInclude.addEventListener("change", () => toggleSettings("include")); initializeSettings(); renderExcludedDomains(); +renderIncludedDomains(); loadData(); loadDomainFilterMode(); setupDomainFilterModeListeners();