Skip to content

Commit

Permalink
修正「有時候」不會顯示「提及條文」區塊的問題。
Browse files Browse the repository at this point in the history
  • Loading branch information
kong0107 committed Aug 5, 2022
1 parent 3e766e5 commit 64cb79d
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 3,667 deletions.
7 changes: 6 additions & 1 deletion changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

這是給程式設計師看的版本。一般使用者請參閱 [`changelog.md`](changelog.md)

## 1.7.5
2022-08-05
* 修改 `parseData.js` ,使精簡的部分不要差太多,且不會略過法律層級的。
* 修改 `manifest.json` ,使不用擔心 `content_scripts` 之間的執行順序(跟 v1.7.1 處理的困境類似)。把 v1.7.3 時另列的 `exec.js` 併回之前的位置,改用 `setTimeout` 延後 100 毫秒來賭監聽器會先註冊好才發生 `textNodeParsed` 事件。

## 1.7.3
2021-11-30
* `Node.closest()` 拼錯成 "closet" 了,蠢。
* 為使 `textNodeParsed` 的監聽器註冊於該事件發生之前,於 `manifest.json` 中將 `exec.js` 挪到最後面。
* 為使 `textNodeParsed` 的監聽器註冊於該事件發生之前,於 `manifest.json` 中將 `exec.js` 挪到最後面。 ( v1.7.5 改為另一做法)

## 1.7.2
2021-11-22
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.7.5
2022-08-05
* 修正「有時候」不會顯示「提及條文」區塊的問題。

## 1.7.4
2022-07-31
* 因應大法官會議改制為憲法法庭的網站改版及連結更動。
Expand Down
2 changes: 1 addition & 1 deletion content_scripts/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if(typeof LER == "object" && document.body && window.innerWidth && window.innerH
LER.artNumberParserMethod = storage.artNumberParserMethod;
LER.enablePopup = storage.enablePopup;
if(matched_pattern) console.debug(`LER skipped auto-parse because location ${location.href} is matched by the pattern ${matched_pattern}`);
else if(storage.autoParse) LER.parse(document.body);
else if(storage.autoParse) setTimeout(() => LER.parse(document.body), 100);
});

browser.runtime.onMessage.addListener(message => {
Expand Down
7 changes: 1 addition & 6 deletions content_scripts/loadLaws.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
"use strict";

LER.loadLaws = getData("laws").then((laws = []) => {
// 放棄一些過長的法規名稱,可以加快速度。
laws = laws.filter(law =>
!law.name.endsWith(")")
//&& law.name.length < 20
);
if(!LER.loadLaws) LER.loadLaws = getData("laws").then((laws = []) => {
const rules = laws.map(law => ({
pattern: law.name,
replacer: () => {
Expand Down
3,775 changes: 137 additions & 3,638 deletions data/laws.json

Large diffs are not rendered by default.

29 changes: 16 additions & 13 deletions 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.4",
"version": "1.7.5",
"author": "kong0107",
"homepage_url": "https://g0v.github.io/laweasyread-front/",
"options_ui": {
Expand Down Expand Up @@ -38,6 +38,7 @@
},
"content_scripts": [
{
"run_at": "document_end",
"matches": ["<all_urls>"],
"js": [
"node_modules/webextension-polyfill/dist/browser-polyfill.min.js",
Expand All @@ -47,38 +48,40 @@
"browser/browser.js",
"content_scripts/functions.js",
"LER.js"
],
"run_at": "document_end"
]
},
{
"matches": ["<all_urls>"],
"js": [
"LER.popup.js",
"content_scripts/loadLaws.js"
"content_scripts/loadLaws.js",
"content_scripts/exec.js"
],
"css": ["content_scripts/main.css"]
},
{
"matches": ["*://law.moj.gov.tw/*"],
"matches": ["https://law.moj.gov.tw/*"],
"css": ["content_scripts/moj.css"]
},
{
"matches": ["*://law.moj.gov.tw/LawClass/*"],
"exclude_matches": ["*://law.moj.gov.tw/LawClass/LawHistory.aspx*"],
"js": ["content_scripts/moj.js"]
"matches": ["https://law.moj.gov.tw/LawClass/*"],
"exclude_matches": ["https://law.moj.gov.tw/LawClass/LawHistory.aspx*"],
"js": [
"content_scripts/loadLaws.js",
"content_scripts/moj.js"
]
},
{
"matches": ["https://lis.ly.gov.tw/lglawc/lglawkm"],
"js": ["content_scripts/ly_lglawkm.js"]
},
{
"matches": ["https://lis.ly.gov.tw/lglawc/lawsingle?*"],
"js": ["content_scripts/ly_lawsingle.js"],
"js": [
"content_scripts/loadLaws.js",
"content_scripts/ly_lawsingle.js"
],
"css": ["content_scripts/ly_lawsingle.css"]
},
{
"matches": ["<all_urls>"],
"js": ["content_scripts/exec.js"]
}
]
}
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"name": "laweasyread",
"version": "1.7.4",
"version": "1.7.5",
"fullName": "法規亦毒氣",
"author": "kong0107",
"description": "an extension for browsers to view Taiwan's law articles/websites easier",
"id": "jid0-TbNAc8Mn0J5idqU6wtcFNmtNcqo",
"keywords": [
"law",
"Taiwan",
"WebExtension"
"Taiwan"
],
"homepage": "http://g0v.github.io/laweasyread-front",
"repository": {
Expand Down
9 changes: 5 additions & 4 deletions parseData.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 可用於瀏覽器外掛的更新資料,亦可用於開發階段生成 data/laws.json
* @return 後依法規名稱長度,由長至短排序
*/
function parseData(mojData, aliases) {
function parseData(mojData, aliases, nameLengthLimit = Infinity) {
const map = new Map();

const result = mojData
Expand All @@ -15,7 +15,8 @@ function parseData(mojData, aliases) {
map.get(name).push(law);
return false;
}
if(law.name.length > 16) return false;
if(/([^]|||)$/.test(law.name)) return true;
if(law.name.length > nameLengthLimit) return false;

return true;
})
Expand All @@ -25,7 +26,7 @@ function parseData(mojData, aliases) {
* 把名字後面有括號的同名法規只留下最新的
*/
map.forEach((versions, name) => {
if(name.length > 16) return false;
if(name.length > nameLengthLimit) return false;
versions.forEach(law => {
const match = /(\d+\.\d+\.\d+)\s*[]$/.exec(law.name);
const date = match[1].padStart(9, "0");
Expand Down Expand Up @@ -59,6 +60,6 @@ if(typeof module !== 'undefined' && module.exports) {
const mojData = JSON.parse(fs.readFileSync("../mojLawSplit/json/index.json").toString());
const aliases = JSON.parse(fs.readFileSync("./data/aliases.json").toString());

const json = JSON.stringify(parseData(mojData, aliases)).replace(/{/g, "\n{");
const json = JSON.stringify(parseData(mojData, aliases, 10)).replace(/{/g, "\n{");
fs.writeFileSync("./data/laws.json", json);
}
4 changes: 3 additions & 1 deletion todo.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# To-Do List

* Manifest V3 (以本專案 2.0 版實作)
* 不要用 `git submodule` ,都改用 `npm`
* 立法院法律系統在所得稅法第14條的問題
* 嘗試支援「前條」。(除了偵測目前在哪個法,還必須判斷目前是第幾條)
* 嘗試支援「前條」。
* 整合 ronnywang 抓下來的立法院資料。
* 「相關法條」資料
* 正確的分項(除了所得稅法§14)
* 支援法規名稱被框住之後的條號連結,例如 `《刑法》第10條`
* 支援更多條號的格式(例如 `民法第3至5條``民法1124條`),但不能在不需要的時候跳出來。
* 排除的關鍵字,例如「XX大學法律系」中的「大學法」即不應被匹配。
* 支援切換成「只處理白名單中的網站」。
* 裁判書連結。
* 於頁面在例外清單中時,顯示適當標記。
Expand Down

0 comments on commit 64cb79d

Please sign in to comment.