Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
closes #13; support 法源法律網
Browse files Browse the repository at this point in the history
* 視窗延遲半秒才出現對我來說有點久,現設為350毫秒--之後應允許使用者自設為150毫秒以上的時間。
*   * 發生「移動到子物件會觸發父元件的onMouseOver事件」狀況,在[Stack
Overflow找到解答](http://stackoverflow.com/questions/4697758#4698240)。(詭異的是:之前沒有發生!?),僅套用最簡便但不適用於孫輩以下之後代的。
* [法源法律網](http://www.lawbank.com.tw/)部分,僅對法規查詢的頁面重新排版。
*   *
基本上與全國法規資料庫相同,故另分離出`pre32.js`供這二者共用。印象中其他許多的政府機關自有法規資料庫亦是相同結構,應亦能套用。
  • Loading branch information
kong0107 committed Jul 8, 2013
1 parent 154f633 commit 8e76305
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 131 deletions.
49 changes: 28 additions & 21 deletions LER.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,39 @@ LER = function(){

eles[i].style.position = "relative";
(function() {
//var timerID;
var timerID;
var iframe;
eles[i].onmouseover = function() {
var isFirst = true;
var src = href;
return function() {
var iframe;
if(isFirst) {
iframe = document.createElement("IFRAME");
iframe.style.display = "none";
iframe.className = "LER-iframe";
iframe.src = src;
this.appendChild(iframe);
isFirst = false;
}
else iframe = this.lastChild;
//if(timerID) clearTimeout(timerID);
//timerID = setTimeout(function() {
var self = this; ///< `this` would be different later.
if(timerID) clearTimeout(timerID);
timerID = setTimeout(function() {
if(isFirst) {
iframe = document.createElement("IFRAME");
iframe.style.display = "none";
iframe.className = "LER-iframe";
iframe.src = src;
self.appendChild(iframe);
isFirst = false;
}
//else iframe = self.lastChild;
var target = (iframe.previousSibling.nodeType == 1)
? iframe.previousSibling
: iframe.parentNode
; ///< 法規名稱目前沒有另包container,其previousSibling會是TEXT_NODE
iframe.style.display = "";
iframe.style.top = (this.offsetHeight * 0.9) + "px";
iframe.style[this.offsetLeft > 400 ? "right" : "left"] = "0";
//}, 500);
}
iframe.style.top = target.offsetHeight * 0.9 + "px";
iframe.style[target.offsetLeft > 400 ? "right" : "left"] = "0";
}, 350);
};
}();
eles[i].onmouseout = function(){
//clearTimeout(timerID);
this.lastChild.style.display = "none";
eles[i].onmouseout = function(event){
var e = event.toElement || event.relatedTarget;
if(!e || e.parentNode == this || e == this) return;
clearTimeout(timerID);
if(iframe) this.lastChild.style.display = "none";
};
})();
}
Expand Down Expand Up @@ -513,7 +520,7 @@ LER = function(){
}());

rules.push(function() {
var pattern = /(()?)?\s*([]+|\d+)\s*\s*([]+|\d+)\s*\s*([]+|\d+)\s*/g;
var pattern = /(()?)?\s*([]+|\d+)\s*\s*([]+|\d+)\s*\s*([]+|\d+)\s*/g;
var replace = function(match) {
var node = document.createElement("SPAN");
node.className = "LER-date";
Expand Down
13 changes: 10 additions & 3 deletions constitutionalcourt.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ for(var i = 0; i < fonts.length; ++i) {
fonts[i].parentNode.innerHTML = '<a name="' + anchors[text] + '">' + text + '</a>';
}

/// 內嵌的話,拿掉其他東西
if(window != top) ///< 該頁居然有兩個 table#AutoNumber1
document.body.replaceChild(document.getElementsByTagName("TABLE")[4], document.body.firstElementChild);
/// 內嵌的話...
if(window != top) {
/// 拿掉外框;該頁居然有兩個 table#AutoNumber1
document.body.replaceChild(document.getElementsByTagName("TABLE")[4], document.body.firstElementChild);
/*var ths = document.getElementsByTagName("TH");
for(var i = 0; i < ths; ++i) {
ths[i].setAttribute("width", "");
ths[i].style.width = "4em";
}*/
}
10 changes: 10 additions & 0 deletions lawbank.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
body,
#main,
#tbLaw,
#Law-Content1 {
width: 100% !important;
}

#tbLaw {
margin: auto;
}
15 changes: 13 additions & 2 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": "0.3.13.6",
"version": "0.3.14",
"icons" : {"128": "icon.png"},
"options_page": "options.html",
"browser_action": {
Expand Down Expand Up @@ -56,10 +56,21 @@
"matches": ["http://law.moj.gov.tw/*"],
"exclude_matches": ["http://law.moj.gov.tw/Eng/*"],
"css": ["moj.css"],
"js": ["moj.js"],
"js": [
"moj.js",
"pre32.js"
],
"run_at": "document_end",
"all_frames": true
},
{
"matches": [
"http://db.lawbank.com.tw/FLAW/FLAW*",
"http://db.lawbank.com.tw/FLAW/PrintFLAW*"
],
"css": ["lawbank.css"],
"js": ["pre32.js"]
},
{
"matches": ["<all_urls>"],
"js": ["auto.js"],
Expand Down
106 changes: 1 addition & 105 deletions moj.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
*/
if(window != top) {
var main = document.getElementById("main");
if(main) {
main.parentNode.replaceChild(document.getElementById("mainFrame_body"), main);
//document.getElementsByTagName("FORM")[0].target = "_blank";
}
if(main) main.parentNode.replaceChild(document.getElementById("mainFrame_body"), main);
var base = document.getElementsByTagName("BASE")[0];
if(!base) {
base = document.createElement("BASE");
Expand All @@ -46,107 +43,6 @@
}
}

/** 處理把全國法規資料庫的斷行排版
* 嘗試排版承接層式表單(如`ly.js`)
*/
var stratums = [
{
"name": "paragraphs", ///< 用於CSS
"ordinal": /^(?! )/ ///< 此階層的序數文字,「不能」是global
},
{
"name": "categories",
"ordinal": /^[]+/
},
{
"name": "subparagraphs",
"ordinal": /^\s*[]+(| | )/ ///< 憲法裡的「款」有時是全形空格,有時是兩個半形空格
},
{
"name": "items",
"ordinal": /^\s*[\(][]+[\)]/ ///< 有些括號是全形,有些是半形
},
{
"name": "subitems",
"ordinal": /^\s+\d+\./
},
{
"name": "subsubitems",
"ordinal": /^\s+\d+/ ///< 全形括號(與立法院不同)、半形數字
}
];
var pres = document.getElementsByTagName("PRE");
for(var i = 0; i < pres.length;) {
var row = pres[i].parentNode.parentNode;
if(row.childElementCount != 3) {
/** 只處理條文,不處理分區(編章節)的文字
* 因為 Node#replaceChild 會改變 NodeList,故 ++i 的位置與一般 for 迴圈不同
*/
++i;
continue;
}
/// 增加左方的空間
row.children[0].setAttribute("width", "");
row.children[1].setAttribute("width", "");
row.children[2].setAttribute("width", "90%");

var lines = pres[i].innerText.split("\n"); ///< 記得最後一行是空字串喔
var html = "<li>";
var depthArr = [];
for(var j = 0; j < lines.length; ++j) {
var endDetect = /(||)$/.exec(html);
if(endDetect) {
var stratum = -1;
for(var k = stratums.length - 1; k >= 0; --k) {
if(stratums[k].ordinal.test(lines[j])) {
stratum = k;
break;
}
}

switch(endDetect[1]) {
case "。":
/// 處理所得稅法中,一個款/目中又分段的情形
if(stratum < 0) {
html += "<br />";
break;
}
/// 警告可能的錯誤情形
if(!depthArr.length ///< 「項」
&& lines[j-1].length == 32 ///< 前一行有32字
&& !/\w/.test(lines[j-1]) ///< 且沒有英數
&& lines[j] ///< 而這行不是最後一行
) html += '<div class="LER-warning" title="此網頁是用「換行」的方式排版,因而【法規亦毒氣】沒能判斷這裡究竟是「換行」還是「分項」。">警告:這裡可能其實沒有分項</div>';
// no break!
case "(刪除)":
html += "</li>";
while(depthArr.length && depthArr[depthArr.length - 1] != stratum) {
html += "</ol></li>";
depthArr.pop();
}
break;
case ":":
if(lines[j][0] == "「") { ///< 憲法§48
stratum = -1;
break;
}
html += '<ol class="LER-art-' + stratums[stratum].name + '">';
depthArr.push(stratum);
break;
default:
console.log(endDetect);
throw new SyntaxError("RegExp returns wrong match.");
}
if(lines[j] && stratum >= 0) html += "<li>"; ///< 如果是末行的空白就不用加了
}
html += lines[j].replace(/^\s+/, '');
}
var list = document.createElement("OL");
list.innerHTML = html;
list.className = (list.childElementCount == 1) ? "LER-art-singlePara" : "LER-art-paragraphs";
pres[i].parentNode.replaceChild(list, pres[i]);
}

/** 列印介面
*/
var cf = document.getElementById("ctl00_cphContent_Forword");
Expand Down
100 changes: 100 additions & 0 deletions pre32.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/** 處理<pre />的斷行排版
* 嘗試排版成階層式表單(如`ly.js`)
*/
var stratums = [
{
"name": "paragraphs", ///< 用於CSS
"ordinal": /^(?! )/ ///< 此階層的序數文字,「不能」是global
},
{
"name": "categories",
"ordinal": /^[]+/
},
{
"name": "subparagraphs",
"ordinal": /^\s*[]+(| | )/ ///< 憲法裡的「款」有時是全形空格,有時是兩個半形空格
},
{
"name": "items",
"ordinal": /^\s*[\(][]+[\)]/ ///< 有些括號是全形,有些是半形
},
{
"name": "subitems",
"ordinal": /^\s+\d+\./
},
{
"name": "subsubitems",
"ordinal": /^\s+\d+/ ///< 全形括號(與立法院不同)、半形數字
}
];
var pres = document.getElementsByTagName("PRE");
for(var i = 0; i < pres.length;) {
var row = pres[i].parentNode.parentNode;
if(row.childElementCount != 3) {
/** 只處理條文,不處理分區(編章節)的文字
* 因為 Node#replaceChild 會改變 NodeList,故 ++i 的位置與一般 for 迴圈不同
*/
++i;
continue;
}
/// 增加左方的空間
row.children[0].setAttribute("width", "");
row.children[1].setAttribute("width", "");
row.children[2].setAttribute("width", "95%");

var lines = pres[i].innerText.split("\n"); ///< 記得最後一行是空字串喔
var html = "<li>";
var depthArr = [];
for(var j = 0; j < lines.length; ++j) {
var endDetect = /(||)$/.exec(html);
if(endDetect) {
var stratum = -1;
for(var k = stratums.length - 1; k >= 0; --k) {
if(stratums[k].ordinal.test(lines[j])) {
stratum = k;
break;
}
}

switch(endDetect[1]) {
case "。":
/// 處理所得稅法中,一個款/目中又分段的情形
if(stratum < 0) {
html += "<br />";
break;
}
/// 警告可能的錯誤情形
if(!depthArr.length ///< 「項」
&& lines[j-1].length == 32 ///< 前一行有32字
&& !/\w/.test(lines[j-1]) ///< 且沒有英數
&& lines[j] ///< 而這行不是最後一行
) html += '<div class="LER-warning" title="此網頁是用「換行」的方式排版,因而【法規亦毒氣】沒能判斷這裡究竟是「換行」還是「分項」。">警告:這裡可能其實沒有分項</div>';
// no break!
case "(刪除)":
html += "</li>";
while(depthArr.length && depthArr[depthArr.length - 1] != stratum) {
html += "</ol></li>";
depthArr.pop();
}
break;
case ":":
if(lines[j][0] == "「") { ///< 憲法§48
stratum = -1;
break;
}
html += '<ol class="LER-art-' + stratums[stratum].name + '">';
depthArr.push(stratum);
break;
default:
console.log(endDetect);
throw new SyntaxError("RegExp returns wrong match.");
}
if(lines[j] && stratum >= 0) html += "<li>"; ///< 如果是末行的空白就不用加了
}
html += lines[j].replace(/^\s+/, '');
}
var list = document.createElement("OL");
list.innerHTML = html;
list.className = (list.childElementCount == 1) ? "LER-art-singlePara" : "LER-art-paragraphs";
pres[i].parentNode.replaceChild(list, pres[i]);
}
10 changes: 10 additions & 0 deletions preprocess.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if(location.href.indexOf("http://law.moj.gov.tw/LawClass/Law") == 0) {
/** 如果連結到全國法規資料庫中不存在的法條,會強制執行
* `alert('查無資料');history.go(-1);` // line #43
* 由於該處是寫在<script />裡,因而不能等DOMContenetLoaded才處理
* 但即使是在`document_start`時執行這個檔好像也沒幫助....
* 先放著。
*/
alert = function(str){ console.log(str); };
history.go = function(){};
}

0 comments on commit 8e76305

Please sign in to comment.