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

Commit

Permalink
closes #9, related to #7: no fixed DIV
Browse files Browse the repository at this point in the history
Now you can click the button in the popup page!
I don't really know what caused my problem before....

Other modification:
* change name from "法令易讀器" to "法規亦毒氣"; old english name "zhLawEasyRead"
is gone from `manifest.json`, but I haven't decided yet whether to
retain it in cases that only english names are permittable.
* debugged #8 by modifying `ly.lci.js`; I misused
`document.location.pathname` to detect sub-string in search part.
  • Loading branch information
kong0107 committed Jul 1, 2013
1 parent 61f902e commit fc474ae
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 105 deletions.
5 changes: 2 additions & 3 deletions LER.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ LER = function(){
node.setAttribute('target', '_blank');
var href = "http://law.moj.gov.tw/LawClass/Law";
if(/[,-]/.test(SNo)) href += "SearchNo.aspx?PC=" + law.PCode + "&SNo=" + SNo; ///< 多條
else if(!law.lyID) href += "Single.aspx?Pcode=" + law.PCode + "&FLNO=" + SNo; ///< 單條
else if(!law.lyID || law.name == '民法') href += "Single.aspx?Pcode=" + law.PCode + "&FLNO=" + SNo; ///< 單條
else {
//http://lis.ly.gov.tw/lghtml/lawstat/relarti/01183/01183009101.htm
/// 連向立法院法律系統的「相關條文」
href = "http://lis.ly.gov.tw/lghtml/lawstat/relarti/" + law.lyID + "/" + law.lyID;
href += zeroFill(num1, 4) + zeroFill(num2 ? num2 : 0, 2) + ".htm";
}
Expand Down Expand Up @@ -375,7 +375,6 @@ LER = function(){
pattern = pattern.replace(/%number%/g, '[\\d零0一二三四五六七八九十百千]+');
pattern = new RegExp(pattern, 'g');
var replace = function(match, inSpecial) {
console.log(match);
var year = parseInt(match[1]);
var num = parseInt(match[4]);

Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Google瀏覽器外掛,可於瀏覽網站時:
* 將法規名稱加上連往[全國法規資料庫](http://law.moj.gov.tw/)看該法規全文的網頁連結
* 將單一法條連向[立法院法律系統](http://lis.ly.gov.tw/lgcgi/lglaw)該條文與相關條文
* 將多個法條連向[全國法規資料庫](http://law.moj.gov.tw/)看該些條文
* 亦能運作於[零時政府立法院](http://ly.g0v.tw.jit.su/)[評律網](http://www.pingluweb.com/)等以AJAX機制更新的內容(但需手動觸發)。
* 亦能運作於[零時政府立法院](http://ly.g0v.tw.jit.su/)[評律網](http://www.pingluweb.com/)等以AJAX機制更新的內容(需點選網址列的按鈕)。
* 提到大法官解釋時,即連向該號解釋的官方網頁。
* 將下列網站稍做排版,使易於閱讀:
* [大法官解釋](http://www.judicial.gov.tw/constitutionalcourt/p03.asp)
Expand All @@ -17,8 +17,11 @@ Google瀏覽器外掛,可於瀏覽網站時:
警告:部落客於編輯網誌時,請暫時關閉本外掛。

## Examples
* 大法官解釋([範例網頁連結](http://www.judicial.gov.tw/constitutionalcourt/p03_01.asp?expno=617)
![Judicial Interpretation](http://images.plurk.com/kAGZ-22KieXBnFHCtsKe8DBiD8u.jpg)
* 立法院法律系統([範例網頁連結](http://lis.ly.gov.tw/lghtml/lawstat/reason2/01183100110400.htm)
![Legislative Yuan](http://images.plurk.com/kAGZ-5bvO4HGPifAXwkDU9CAs3y.jpg)
![Judicial Interpretation](http://images.plurk.com/kAGZ-5vXMDaSEAUQCW51VJ06k3Z.jpg)
* 全國法規資料庫([範例網頁連結](http://law.moj.gov.tw/LawClass/LawSearchNo.aspx?PC=B0000001&SNo=1079.4,1079.5)
![Laws & Regulations Database](http://images.plurk.com/kAGZ-1V1k4UwBowvUXGaOQ0DF6R.jpg)

# Installation
Expand All @@ -31,6 +34,7 @@ Google瀏覽器外掛,可於瀏覽網站時:
* 網址列右邊出現「§#」圖示的話就是成功了,按該圖示會有一些連結。
* 解壓縮出來的資料夾與檔案不要刪掉。
* 試試在[全國法規資料庫](http://law.moj.gov.tw/)中搜尋一些法規,例如[個人資料保護法](http://law.moj.gov.tw/LawClass/LawAll.aspx?PCode=I0050021)
* 瀏覽動態讀取的網頁(如Facebook、噗浪)時,可能須手動按右上角的「§#」圖示再按「轉換這個網頁」才會作用。

警告:部落客於編輯網誌時,請暫時關閉本外掛。

Expand Down
80 changes: 44 additions & 36 deletions auto.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,45 @@
if(typeof LER == "object") (function(){
if(LER.autoParse instanceof Element) {
LER.parse(LER.autoParse);
LER.debugTime("parsed all");
}

/** 加上懸浮按鈕
* 加在沒有frame,或是最左下角的frame裡頭(不理iFrame)
* 以下程式碼先判斷「『這個』是不是top左下角的那個frame」
*/
var target;
if(top.document && top.document.domain == document.domain) {
var fs;
if(fs = top.document.getElementsByTagName("FRAMESET")[0]) {
var rows = fs.rows ? fs.rows.split(",").length : 1;
var cols = fs.cols ? fs.cols.split(",").length : 1;
target = fs.getElementsByTagName("FRAME")[(rows-1)*cols].contentWindow;
}
}
if(document.location.protocol != "file:"
&& (
(window == top && !document.getElementsByTagName("FRAMESET").length)
|| window == target
)
) {
console.log("fixed label");
var fixed = document.createElement("DIV");
var defaultText = "法令\n亦毒氣";
fixed.appendChild(document.createTextNode(defaultText));
fixed.setAttribute("title", "按下以再次分析/處理網頁內容\n(我知道這按鈕很像廣告,\n有請高手教我如何從 contextMenu 或 browserAction 存取網頁內容…)");
fixed.onclick = function(){LER.parse(document.body); LER.debugTime("parse again");};
fixed.onmouseover = function(){this.innerText = "按下\n以轉換";};
fixed.onmouseout = function(){this.innerText = defaultText;};
fixed.className = "LER-fixed";
document.body.appendChild(fixed);
}
if(typeof LER == "object") (function(){
if(LER.autoParse instanceof Element) {
LER.parse(LER.autoParse);
LER.debugTime("parsed all");
}

chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.greeting == "hello") {
LER.parse(document.body);
}
}
);

/** 加上懸浮按鈕--之前觸發不成功時用的
* 加在沒有frame,或是最左下角的frame裡頭(不理iFrame)
* 以下程式碼先判斷「『這個』是不是top左下角的那個frame」
*/
/*var target;
if(top.document && top.document.domain == document.domain) {
var fs;
if(fs = top.document.getElementsByTagName("FRAMESET")[0]) {
var rows = fs.rows ? fs.rows.split(",").length : 1;
var cols = fs.cols ? fs.cols.split(",").length : 1;
target = fs.getElementsByTagName("FRAME")[(rows-1)*cols].contentWindow;
}
}
if(document.location.protocol != "file:"
&& (
(window == top && !document.getElementsByTagName("FRAMESET").length)
|| window == target
)
) {
//console.log("fixed label");
var fixed = document.createElement("DIV");
var defaultText = "法令\n亦毒氣";
fixed.appendChild(document.createTextNode(defaultText));
fixed.setAttribute("title", "按下以再次分析/處理網頁內容\n(我知道這按鈕很像廣告,\n有請高手教我如何從 contextMenu 或 browserAction 存取網頁內容…)");
fixed.onclick = function(){LER.parse(document.body); LER.debugTime("parse again");};
fixed.onmouseover = function(){this.innerText = "按下\n以轉換";};
fixed.onmouseout = function(){this.innerText = defaultText;};
fixed.className = "LER-fixed";
document.body.appendChild(fixed);
}*/
})();
2 changes: 1 addition & 1 deletion ly.lci.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 原始碼看來是從M$ Word轉過去的
* 目前對會議記錄會跑非常久(可能超過一分鐘)
*/
if(document.location.pathname.indexOf("html") > 0) (function() {
if(document.location.href.indexOf("html") > 0) (function() {
var ps = document.getElementsByTagName("P");
/// 「立法院議案關係文書」那幾個字本身是用<span />調整大小的,就跳過不處理
for(var i = 4; i < ps.length; ++i) ps[i].innerText = ps[i].innerText;
Expand Down
126 changes: 63 additions & 63 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
{
"name": "zhLawEasyRead",
"description": "Replace chinese words of sequence number of law articles into arabic or roman numerals.",
"version": "0.3.9.11",
"manifest_version": 2,
"icons" : {"128": "icon.png"},
"options_page": "options.html",
"browser_action": {
"default_icon": "icon.png",
"default_title": "法令易讀器",
"default_popup": "popup.html"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"exclude_matches": [
"http://law.moj.gov.tw/Eng/*",
"*://drive.google.com/keep*",
"*://docs.google.com/*"
],
"css": ["main.css"],
"js": [
"parseInt.js",
"pcodes.js",
"aliases.js",
"lyIDs.js",
"courts.js",
"LER.js"
],
"all_frames": true
},
{
"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": ["http://lci.ly.gov.tw/*"],
"js": ["ly.lci.js"]
},
{
"matches": ["http://law.moj.gov.tw/*"],
"exclude_matches": ["http://law.moj.gov.tw/Eng/*"],
"js": ["moj.js"]
},
{
"matches": ["<all_urls>"],
"js": ["auto.js"],
"run_at": "document_idle",
"all_frames": true
}
]
}
{
"manifest_version": 2,
"name": "法規亦毒氣",
"description": "將網頁中的法規與條號都轉變成連結,讓您快速查閱指定條文。",
"version": "0.3.10",
"icons" : {"128": "icon.png"},
"options_page": "options.html",
"browser_action": {
"default_icon": "icon.png",
"default_title": "法規亦毒氣",
"default_popup": "popup.html"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"exclude_matches": [
"http://law.moj.gov.tw/Eng/*",
"*://drive.google.com/keep*",
"*://docs.google.com/*"
],
"css": ["main.css"],
"js": [
"parseInt.js",
"pcodes.js",
"aliases.js",
"lyIDs.js",
"courts.js",
"LER.js"
],
"all_frames": true
},
{
"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": ["http://lci.ly.gov.tw/*"],
"js": ["ly.lci.js"]
},
{
"matches": ["http://law.moj.gov.tw/*"],
"exclude_matches": ["http://law.moj.gov.tw/Eng/*"],
"js": ["moj.js"]
},
{
"matches": ["<all_urls>"],
"js": ["auto.js"],
"run_at": "document_idle",
"all_frames": true
}
]
}
1 change: 1 addition & 0 deletions popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</head>
<body>
<ul>
<li><button>轉換這個網頁</button></li>
<li>
<a href='http://law.moj.gov.tw/'>[法務部]全國法規資料庫</a>
<form method="get" action="http://law.moj.gov.tw/Law/LawSearchResult.aspx">
Expand Down
11 changes: 11 additions & 0 deletions popup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
document.addEventListener("DOMContentLoaded", function() {
console.log("DOMContentLoaded");
document.getElementsByTagName("BUTTON")[0].onclick = function() {
chrome.tabs.getSelected(null, function(tab) {
console.log("button clicked on tab " + tab.id);
chrome.tabs.sendMessage(tab.id, {greeting: "hello"}, function(response) {
console.log(response);
});
});
};
});

0 comments on commit fc474ae

Please sign in to comment.