This repository has been archived by the owner on Apr 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2012-04-12
- Loading branch information
0 parents
commit 0c23962
Showing
16 changed files
with
614 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
an extension for Chrome browser to view Taiwan's law articles/websites easier | ||
author: kong0107 | ||
last update: 2012-04-12 | ||
|
||
例示:http://images.plurk.com/c27a95275c55a8ccc4f8e39704df1875.jpg | ||
|
||
功能: | ||
一、自動轉換條號、卷期等。 | ||
如「民法第一千零七十六條之一第一項第二款」將變為「民法§1076-1 I(2)」; | ||
如「立法院公報第八十卷第二十二期第一0七頁」將變為「立法院公報vol. 80, no. 22, p.107」。 | ||
另外如條文中的「前條第一項第三款至第六款」則會變為「前條 I(3)至(6)」 | ||
|
||
二、將滑鼠移置被轉換後的文字,即會顯示原本的文字。 | ||
但如為可編輯之純文字框,如<textarea />,即無此效果。 | ||
|
||
三、將憲法與大法官釋字加上連結 | ||
除非原本即已是連結。 | ||
|
||
|
||
使用限制與臭蟲: | ||
一、限Google瀏覽器,Chrome 18版或更新為佳。 | ||
二、互動式網頁如Gmail、Facebook和Plurk的幾乎無效果。 | ||
三、法規若有分章節款目,其中「款」與「目」亦會被轉換。 | ||
四、數個釋字或憲法條文並列時,僅有第一個會被轉換為連結。 | ||
五、以換行字元強制換行的排版網頁(如「全國法規資料庫」及司法院的裁判書查詢)中,可能會將數行併成過長的一行。 | ||
六、以<br />強制換行的字串尚不會被偵測到。 | ||
|
||
|
||
其他使用說明: | ||
一、為方便複製至純文字編輯器如「記事本」,羅馬數字以英文組合而不以內碼表的符號顯示。「款」的圈圈數字亦同。 | ||
二、大陸地區與聯合國文件中,「項」與「款」的順序與台灣地區相反,但本外掛沒有考量此部分。 | ||
|
||
|
||
|
||
開發說明: | ||
|
||
Google說「需支付一次性的開發人員註冊費 US$5.00」,所以我(還)沒有放在「Chrome 線上應用程式商店」。 | ||
|
||
原本是以字串取代的方式去改變document.body.innerHTML(之前的0.1.8版即是如此),但發現有三個難處: | ||
一、有(類似)onLoad function的網頁(如「全國法規資料庫」的首頁)即會無後續動作。 | ||
二、不知道要怎麼樣避開HTML tag的屬性中的字串。(如各釋字專頁)。 | ||
三、不知道怎麼偵測「是否已在<a />中」。 | ||
所以後來就改成用遞迴方式跑過整個HTML的DOM tree,抓出textNode來處理,但是這樣又會變成勢必得用document.createElement和appendChild等DOM方法,而不能用innerHTML。 | ||
因為可能有多個規則,所以每次遇到一個textNode,處理概念如下: | ||
準備: [text] | ||
經過第一個規則: [text1_1, element1_1, text1_2, element1_2, text1_3] | ||
經過第二個規則: [text1_1, element1_1, text2_1, element2_1, text2_2, element1_2, text1_3] | ||
最後則用新的node array代換掉原本的textNode。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.lawArticle { | ||
font-size: inherit; | ||
} | ||
|
||
.t1 { | ||
line-height: 175%; | ||
text-indent: 2em; | ||
margin-bottom: 0.5em; | ||
} | ||
|
||
object { | ||
display: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dump = document.getElementsByTagName('TR')[0]; | ||
dump.parentNode.removeChild(dump); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
chDigit = '零壹貳參肆伍陸柒捌玖〇一二三四五六七八九0123456789○ㄧ'; | ||
chTenth = '十百千拾佰仟什'; | ||
chNumber = '\\d' + chDigit + chTenth; | ||
|
||
function chNum2int(str) { | ||
var i, result, pos; | ||
str = str.replace(new RegExp('[^' + chNumber + ']', 'g'), ''); | ||
// 有時會是零開頭喔!! | ||
if(!isNaN(parseInt(str))) return str; | ||
if(!new RegExp('[' + chTenth + ']', 'g').test(str)) { | ||
result = ''; | ||
for(i = 0; i < str.length; i++) | ||
result += chDigit.indexOf(str.charAt(i)) % 10; | ||
return result; | ||
} | ||
|
||
result = '0'; | ||
str = str.replace(/^[十什拾]/, '一十'); | ||
str = str.replace(new RegExp('([^' + chDigit + '])[十什拾]', 'g'), '$1一十'); | ||
for(i = 0; i < str.length; i++) { | ||
pos = chDigit.indexOf(str.charAt(i)) % 10; | ||
if(pos > 0) {result += '+' + pos; continue;} // zero could be ignored | ||
pos = chTenth.indexOf(str.charAt(i)) % 3; | ||
if(pos >= 0) | ||
result += '*' + [10, 100, 1000][pos]; | ||
} | ||
return eval(result); | ||
} | ||
|
||
function int2roman(num, lower) { | ||
/* | ||
Note that: | ||
1. There may be more than one way to represent the same integer. | ||
See also Wikipedia, 'Roman numerals.' | ||
2. This function allows only positive integer less than 4000. | ||
3. This function works just as CSS' "list-style-type: upper-roman" | ||
*/ | ||
lower = Boolean(lower); | ||
var result = ''; | ||
var r = [ | ||
//['', 'Ⅰ', 'Ⅱ', 'Ⅲ', 'Ⅳ', 'Ⅴ', 'Ⅵ', 'Ⅶ', 'Ⅷ', 'Ⅸ'], | ||
['', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'], | ||
['', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC'], | ||
['', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM'], | ||
['', 'M', 'MM', 'MMM'] | ||
]; | ||
num = parseInt(num); | ||
if(isNaN(num) || num <= 0 || num >= 4000) return num; | ||
if(num <= 12) return unescape('%u' + (0x215f + (lower*16) + num).toString(16)); | ||
for(var i = 3; i >= 0; i--) | ||
result += r[i][parseInt(num % Math.pow(10, i+1) / Math.pow(10, i))]; | ||
if(typeof lower != 'undefined' && lower) result = result.toLowerCase(); | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pre { | ||
line-height: 150%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function pic2text(node) { | ||
var images = node.getElementsByTagName('IMG'); | ||
for(var i = 0; i < images.length; i++) { | ||
if(images[i].src == 'http://210.69.124.103/ASTAR/100E3722A0C00000040.GIF') { | ||
images[i].parentNode.replaceChild(document.createTextNode('參'), images[i]); | ||
} | ||
} | ||
} | ||
pic2text(document.getElementsByTagName('PRE')[0]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
ol { | ||
margin: 0; | ||
} | ||
|
||
.singlePara { | ||
list-style-type: disc; | ||
padding-left: 1.5em; | ||
} | ||
|
||
.paraList { | ||
list-style-type: upper-roman; | ||
padding-left: 1.5em; | ||
} | ||
|
||
.catList { | ||
padding-left: 4em; | ||
text-indent: -4em; | ||
} | ||
|
||
.subsecList { | ||
list-style-type: none; | ||
padding-left: 2em; | ||
text-indent: -2em; | ||
} | ||
|
||
.itemList { | ||
list-style-type: none; | ||
padding-left: 1.7em; | ||
text-indent: -1.7em; | ||
} | ||
|
||
li { | ||
line-height: 150%; | ||
padding: 0.25em 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
Bugs: | ||
2. 所得稅法§14有「第某類」,§17有「1.」(第某目之一)和不知道該怎麼叫的「(1)」。 | ||
3. 有些「(刪除)」前面沒有空白,因而沒能偵測到。小心章節目款也會有「(刪除)」 | ||
Note: 這裡的「目」是用半行空白,但全國法規資料庫那邊的括號都是全形。 | ||
*/ | ||
|
||
depths = [ | ||
{'name': 'article'}, | ||
{'name': 'paragraph'}, | ||
{'name': 'category', 'regex': /^第[一二三四五六七八九十]+類:/}, | ||
{'name': 'subsection', 'regex': /^[一二三四五六七八九十]+、/}, | ||
{'name': 'item', 'regex': /^\([一二三四五六七八九十]+\)/}, | ||
{'name': 'depth5', 'regex': /^\d+\./}, | ||
{'name': 'depth6', 'regex': /^\(\d+\)/} | ||
]; | ||
function parseNodesWithLawTexts(nodes) { | ||
//var regex = /^\s*( [^<]+<br>\s*)+$/; | ||
var regex = /^\s* /; | ||
var i, j, node, working, paraList, lines, prevDepth, depth, cur; | ||
for(i = 0; i < nodes.length; i++) { | ||
regex.lastIndex = 0; | ||
if(regex.test(nodes[i].innerHTML)) { | ||
node = document.createElement('TD'); | ||
working = paraList = document.createElement('OL'); | ||
node.appendChild(paraList); | ||
lines = nodes[i].innerHTML.replace(/[ \n\r]/g, '').split('<br>'); | ||
for(prevDepth = 1, j = 0; j < lines.length; j++, prevDepth = depth) { | ||
if(lines[j] == '') continue; | ||
if(lines[j].substr(0, 2) == '<a') { | ||
cur = document.createElement('A'); | ||
cur.href = lines[j].match(/href=\"?([^\"\s]*)\"?\s/)[1]; | ||
cur.target = '_blank'; | ||
cur.appendChild(document.createTextNode( | ||
lines[j].substring(lines[j].indexOf('>')+1, lines[j].indexOf('<', 1)) | ||
)); | ||
node.appendChild(cur); | ||
continue; | ||
} | ||
|
||
if(/^\(\d+\)/.test(lines[j])) depth = 5; | ||
else if(/^\d+\./.test(lines[j])) depth = 4; | ||
else if(/^\([一二三四五六七八九十]+\)/.test(lines[j])) depth = 3; // for items | ||
else if(/^[一二三四五六七八九十]+、/.test(lines[j])) depth = 2; // for subsections | ||
else if(/^第[一二三四五六七八九十]+類:/.test(lines[j])) depth = 1.5; // for 所得稅§14 | ||
else depth = 1; // for paragraphs | ||
if(depth > prevDepth) { | ||
//if(!working.lastChild) working.appendChild(document.createElement('LI')); | ||
if(working.lastChild) { | ||
working.lastChild.appendChild(document.createElement('OL')); | ||
working = working.lastChild.lastChild; | ||
} | ||
working.classList.add((depth==2)?'subsecList':'itemList'); | ||
} | ||
else if(depth < prevDepth) | ||
working = (depth == 1) ? paraList : working.parentNode.parentNode; | ||
cur = document.createElement('LI'); | ||
cur.appendChild(document.createTextNode(lines[j].replace(/<[^>]*>/g, ''))); | ||
working.appendChild(cur); | ||
} | ||
paraList.classList.add((paraList.childElementCount > 1) ? 'paraList' : 'singlepara'); | ||
nodes[i].parentNode.replaceChild(node, nodes[i]); | ||
} | ||
} | ||
} | ||
|
||
parseNodesWithLawTexts(document.getElementsByTagName('TD')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.lawArticle { | ||
padding: 0 0.15em; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "zhLawEasyRead", | ||
"manifest_version": 2, | ||
"version": "0.2.6", | ||
"description": "Replace chinese words of sequence number of law articles into arabic or roman numerals.", | ||
"permissions": [ | ||
"chrome-extension://*/*" | ||
], | ||
"browser_action": { | ||
"default_icon": "icon.png", | ||
"default_popup": "popup.html" | ||
}, | ||
"content_scripts": [ | ||
{ | ||
"matches": ["http://www.judicial.gov.tw/constitutionalcourt/p03_01.asp*"], | ||
"css": ["constitutionalcourt.css"], | ||
"js": ["constitutionalcourt.js"] | ||
}, | ||
{ | ||
"matches": ["http://jirs.judicial.gov.tw/*"], | ||
"css": ["jirs.css"], | ||
"js": ["jirs.js"] | ||
}, | ||
{ | ||
"matches": ["http://lis.ly.gov.tw/*"], | ||
"css": ["ly.css"], | ||
"js": ["ly.js"] | ||
}, | ||
{ | ||
"matches": ["<all_urls>"], | ||
"css": ["main.css"], | ||
"js": [ | ||
"functions.js", | ||
"parseAndReplace.js" | ||
] | ||
} | ||
] | ||
} |
Oops, something went wrong.