Skip to content

Commit

Permalink
support skipping terms
Browse files Browse the repository at this point in the history
  • Loading branch information
kong0107 committed Aug 28, 2022
1 parent 64cb79d commit 719ae52
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 26 deletions.
3 changes: 3 additions & 0 deletions LER.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ const objArr2nodes = (arr, textNode, defaultLaw = LER.defaultLaw) => {
});
return e("SPAN", null, ...nodes);
}
case "exclude_term": {
return document.createTextNode(item.text);
}
default:
console.error("uncaught type", item);
}
Expand Down
12 changes: 7 additions & 5 deletions README-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@
* `maniffest.json`: 瀏覽器擴充元件設定
* `LER.js`: 本專案主程式
* `LER.popup.js`: 浮動視窗程式碼
* `parseData.js`: 僅開發時使用,將其他資料轉為本專案所需的資料並存為 `data/laws.js`
* `data/laws.json`: 全國法規資料庫的法規名稱與其編號,由 `/parseData.js` 輸出。
* `data/aliases.json`: 法規的簡稱、暱稱對照,手動維護。
* `data/options_default.json`: 預設的使用者設定,手動維護。
* `data/exclude_matches_default.txt`: 預設的例外網站清單,手動維護。
* `parseData.js`: 僅開發時使用,將 [mojLawSplitJSON](https://github.com/kong0107/mojLawSplitJSON) 轉為本專案所需的資料並存為 `data/laws.json`
* `data/`:
* `data/laws.json`: 全國法規資料庫的法規名稱與其編號,由 `/parseData.js` 輸出。
* `data/aliases.json`: 法規的簡稱、暱稱對照,手動維護。
* `data/options_default.json`: 預設的使用者設定,手動維護。
* `data/exclude_matches_default.txt`: 預設的例外網站清單,手動維護。
* `data/exclude_terms.txt`: 不要匹配的詞彙清單。


## Data Sources
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Developers may also see [`changelog-dev.md`](changelog-dev.md) to know more.

## 1.8.0
2022-08-28
* 增加排除匹配(判斷為法規名稱)的機制,例如「國民法官」一詞中的「民法」不被匹配;「XX大學法律系」中的「大學法」不被匹配。

## 1.7.5
2022-08-05
* 修正「有時候」不會顯示「提及條文」區塊的問題。
Expand Down
40 changes: 28 additions & 12 deletions content_scripts/loadLaws.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
"use strict";

if(!LER.loadLaws) LER.loadLaws = getData("laws").then((laws = []) => {
const rules = laws.map(law => ({
pattern: law.name,
replacer: () => {
LER.matchedAnyLaw = true;
return {type: "law", law: law};
},
minLength: law.name.length
}));
LER.rules.unshift(...rules);
return LER.laws = laws;
});
if(!LER.loadLaws) {
const exTermsPromise = fetch(
browser.runtime.getURL("data/exclude_terms.txt")
).then(res => res.text())
.then(text => text.split(/\r?\n\r?/).filter(x => x));

LER.loadLaws = Promise.all([
getData("laws"),
exTermsPromise
]).then(([laws = [], exTerms = []]) => {
const rules = laws.map(law => ({
pattern: law.name,
replacer: () => {
LER.matchedAnyLaw = true;
return {type: "law", law: law};
},
minLength: law.name.length
})).concat(exTerms.map(term => ({
pattern: term,
replacer: () => ({type: "exclude_term", text: term}),
minLength: term.length
})));

rules.sort((a, b) => b.pattern.length - a.pattern.length);
LER.rules.unshift(...rules);
return LER.laws = laws;
});
}
11 changes: 11 additions & 0 deletions data/exclude_terms.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
國民法官法庭
國民法官
大學法律系
德國憲法
德國民法
德國刑法
日本國憲法
日本憲法
日本民法
日本刑法
美國憲法
11 changes: 6 additions & 5 deletions data/laws.json
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,6 @@
{"PCode":"A0010018","name":"國父陵園管理委員會組織條例"},
{"PCode":"A0010073","name":"監察院監察委員行署組織條例"},
{"PCode":"A0010119","name":"監察院國家人權委員會組織法"},
{"PCode":"A0010121","name":"數位發展部資通安全署組織法"},
{"PCode":"A0010122","name":"數位發展部數位產業署組織法"},
{"PCode":"A0010123","name":"國家資通安全研究院設置條例"},
{"PCode":"A0030232","name":"振興經濟消費券發放特別條例"},
{"PCode":"A0030237","name":"莫拉克颱風災後重建特別條例"},
Expand Down Expand Up @@ -310,6 +308,8 @@
{"PCode":"I0000002","name":"法務部司法官訓練所組織條例"},
{"PCode":"J0000040","name":"行政院原子能委員會組織條例"},
{"PCode":"J0090030","name":"因應貿易自由化調整支援條例"},
{"PCode":"K0000200","name":"數位發展部數位產業署組織法"},
{"PCode":"K0000201","name":"數位發展部資通安全署組織法"},
{"PCode":"L0000056","name":"衛生福利部疾病管制署組織法"},
{"PCode":"L0000057","name":"衛生福利部國民健康署組織法"},
{"PCode":"N0000017","name":"勞工保險監理委員會組織條例"},
Expand Down Expand Up @@ -865,6 +865,7 @@
{"PCode":"J0040046","name":"生技醫藥產業發展條例"},
{"PCode":"J0040052","name":"公司國外投資處理辦法"},
{"PCode":"J0040055","name":"產業創新條例施行細則"},
{"PCode":"J0040063","name":"生技醫藥公司審定辦法"},
{"PCode":"J0080002","name":"公司登記規費收費準則"},
{"PCode":"J0080007","name":"營利事業統一發證辦法"},
{"PCode":"J0080024","name":"電子遊戲場業管理條例"},
Expand Down Expand Up @@ -1430,6 +1431,7 @@
{"PCode":"K0000152","name":"交通部航港局編制表"},
{"PCode":"K0000155","name":"交通部鐵道局組織法"},
{"PCode":"K0000191","name":"交通部鐵道局編制表"},
{"PCode":"K0010154","name":"數位發展部處務規程"},
{"PCode":"K0020004","name":"交通部廢品處理辦法"},
{"PCode":"K0020012","name":"交通部會計檢查辦法"},
{"PCode":"K0040003","name":"汽車運輸業管理規則"},
Expand Down Expand Up @@ -1568,7 +1570,6 @@
{"PCode":"A0010016","name":"中央研究院組織法"},
{"PCode":"A0010022","name":"國家安全局組織法"},
{"PCode":"A0010112","name":"中央研究院編制表"},
{"PCode":"A0010120","name":"數位發展部組織法"},
{"PCode":"A0020005","name":"國民大會議事規則"},
{"PCode":"A0020008","name":"國民大會旁聽規則"},
{"PCode":"A0020024","name":"國民大會採訪規則"},
Expand Down Expand Up @@ -1861,6 +1862,8 @@
{"PCode":"J0160036","name":"核子保防作業辦法"},
{"PCode":"J0170008","name":"消費爭議調解辦法"},
{"PCode":"K0000008","name":"戰區軍郵設置辦法"},
{"PCode":"K0000199","name":"數位發展部組織法"},
{"PCode":"K0000202","name":"數位發展部編制表"},
{"PCode":"K0020034","name":"大眾運輸補貼辦法"},
{"PCode":"K0020041","name":"發展大眾運輸條例"},
{"PCode":"K0030002","name":"鐵路修建養護規則"},
Expand Down Expand Up @@ -2129,7 +2132,6 @@
{"PCode":"G0400106","name":"期貨商管理規則"},
{"PCode":"H0010001","name":"教育部處務規程"},
{"PCode":"H0010029","name":"文化部處務規程"},
{"PCode":"H0010059","name":"科技部處務規程"},
{"PCode":"H0020037","name":"原住民族教育法"},
{"PCode":"H0020041","name":"教師法施行細則"},
{"PCode":"H0030028","name":"大學法施行細則"},
Expand Down Expand Up @@ -2388,7 +2390,6 @@
{"PCode":"H0000001","name":"教育部組織法"},
{"PCode":"H0000103","name":"文化部組織法"},
{"PCode":"H0000152","name":"教育部編制表"},
{"PCode":"H0000161","name":"科技部編制表"},
{"PCode":"H0000169","name":"文化部編制表"},
{"PCode":"H0030042","name":"大學評鑑辦法"},
{"PCode":"H0040007","name":"職業學校規程"},
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "法規亦毒氣",
"description": "將網頁中的法規與條號都轉變成連結,讓您快速查閱指定條文。",
"version": "1.7.5",
"version": "1.8.0",
"author": "kong0107",
"homepage_url": "https://g0v.github.io/laweasyread-front/",
"options_ui": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "laweasyread",
"version": "1.7.5",
"version": "1.8.0",
"fullName": "法規亦毒氣",
"author": "kong0107",
"description": "an extension for browsers to view Taiwan's law articles/websites easier",
Expand Down
5 changes: 3 additions & 2 deletions todo.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# To-Do List

* Manifest V3 (以本專案 2.0 版實作)
* Manifest V3 (以本專案 v2.0 版實作)
* 不要用 `git submodule` ,都改用 `npm`
* 立法院法律系統在所得稅法第14條的問題
* 嘗試支援「前條」。
Expand All @@ -9,8 +9,9 @@
* 正確的分項(除了所得稅法§14)
* 支援法規名稱被框住之後的條號連結,例如 `《刑法》第10條`
* 支援更多條號的格式(例如 `民法第3至5條``民法1124條`),但不能在不需要的時候跳出來。
* 排除的關鍵字,例如「XX大學法律系」中的「大學法」即不應被匹配。
* 支援切換成「只處理白名單中的網站」。
* 裁判書連結。
* 於頁面在例外清單中時,顯示適當標記。
* 民國年換成西元年
* LER 應該在 background 就好,只有 defaultLaw 需要在 content
content script 把 textnode 裡的純文字丟過去(要確認message機制可傳的上限), background 把 JSON (或其物件)丟回來,再由 content script 自己把物件建成 Element 。

0 comments on commit 719ae52

Please sign in to comment.