Skip to content

Commit

Permalink
修正编辑器中文路径的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ywzhaiqi committed Nov 25, 2013
1 parent fca48c6 commit a301dcc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 123 deletions.
19 changes: 16 additions & 3 deletions uAutoPagerize2/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
uAutoPagerize2.uc.js
====================

uAutoPagerize 中文规则简化改进版。跟 [uAutoPagerize](../uAutoPagerize)
uAutoPagerize 中文规则简化改进版,原作者链接:[Griever/userChromeJS](https://github.com/Griever/userChromeJS/tree/master/uAutoPagerize)。跟 [uAutoPagerize](../uAutoPagerize)

- 基于日文原版重新改写。
- **中文规则数据库**为:[Super_preloaderPlus_one for Greasemonkey](http://userscripts.org/scripts/show/178900),这是我用于其它浏览器的翻页脚本 + 数据库。
- **按钮默认位置**为状态栏(可改为地址栏),不可移动,也不会有按钮找不到的问题。
- 新增 `添加下一页到历史记录`
- 新增 `鼠标双击或按键暂停翻页`,在配置文件中。
- 配置文件的 EXCLUDE(黑名单)已经不可用,改在右键菜单里设置,存储在 about:config 中。
- 无多功能的分隔条,无强制翻页(功能的实现不完美),SITEINFO_Writer.uc.js 可能有问题(我已经不再使用)
- 无多功能的分隔条,无强制翻页。

### 右键菜单

Expand All @@ -33,10 +33,23 @@ uAutoPagerize 中文规则简化改进版。跟 [uAutoPagerize](../uAutoPagerize
- 百度如果无法翻页,请清除 cookie
- [uAutoPagerizeUI](uAutoPagerizeUI):图形管理规则,待完善。

### Google 搜索的问题

下面的是 [Super_preloaderPlus_one](http://userscripts.org/scripts/show/178900) 脚本的问题,uc 脚本无问题。

不支持从主页搜索的翻页,只能用这样的搜索

https://www.google.com/search?q=firefox

这几类都不支持

https://www.google.com/#newwindow=1&q=firefox
https://www.google.com/webhp?hl=en&tab=ww&ei=dhFeUuHaBo2aiAeNm4CgCw&ved=0CBgQ1S4#hl=en&newwindow=1&q=firefox

SITEINFO_Writer.uc.js
--------------------

规则辅助工具。
规则辅助工具,原作者链接:[SITEINFOを書く.uc.js](https://gist.github.com/Griever/1044551)

- 略加改进的选取 xpath 生成
- xpath 正确与否的颜色提示
Expand Down
5 changes: 3 additions & 2 deletions uAutoPagerize2/SITEINFO_Writer.uc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
// @namespace http://d.hatena.ne.jp/Griever/
// @author Griever
// @modified ywzhaiqi
// @update 2013-11-22
// @include main
// @compatibility Firefox 5 - firefox 23a1
// @charset UTF-8
// @version 下書き1
// @version 2013.11.23
// @downloadURL https://github.com/ywzhaiqi/userChromeJS/raw/master/uAutoPagerize2/SITEINFO_Writer.uc.js
// @homepageURL https://github.com/ywzhaiqi/userChromeJS/tree/master/uAutoPagerize2
// @note 增加下一页中文选择xpath
// @note fix compatibility for firefox 23a1 by lastdream2013
// @note まだこれからつくり込む段階
Expand Down
136 changes: 18 additions & 118 deletions uAutoPagerize2/uAutoPagerize2.uc.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,12 +589,20 @@ var ns = window.uAutoPagerize = {
}
});

if (info.autopager.uAutoPagerize2) {
for (var name in info.autopager.uAutoPagerize2) {
newInfo[name] = info.autopager.uAutoPagerize2[name];
}
}

newList.push(newInfo);
}
return newList;
},
launch: function(win, timer, DOMLoad){
if (!win) return;
var doc = win.document;
if (!doc) return;

// 监测文件是否更新
if(ns.isModified){
Expand All @@ -613,7 +621,6 @@ var ns = window.uAutoPagerize = {
}
}

var doc = win.document;
if (!/html|xml/i.test(doc.contentType) ||
doc.body instanceof HTMLFrameSetElement ||
win.frameElement && !(win.frameElement instanceof HTMLFrameElement) ||
Expand Down Expand Up @@ -1069,19 +1076,23 @@ var ns = window.uAutoPagerize = {
},
edit: function(aFile) {
if (!aFile || !aFile.exists() || !aFile.isFile()) return;
var editor = Services.prefs.getCharPref("view_source.editor.path");
if (!editor) {
var editor = Services.prefs.getComplexValue("view_source.editor.path", Ci.nsILocalFile);
if (!editor.exists()) {
alert("编辑器的路径未设定。\n请设置 view_source.editor.path");
var url = "about:config?filter=view_source.editor";
var url = "about:config?filter=view_source.editor.path";
openLinkIn(url, "tab", { inBackground: false});
return;
}

try {
var UI = Cc["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Ci.nsIScriptableUnicodeConverter);
var UI = Cc["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Ci.nsIScriptableUnicodeConverter);
UI.charset = window.navigator.platform.toLowerCase().indexOf("win") >= 0? "gbk": "UTF-8";
var process = Cc['@mozilla.org/process/util;1'].createInstance(Ci.nsIProcess);

try {
var path = UI.ConvertFromUnicode(aFile.path);
exec(editor, path);
var args = [path];
process.init(editor);
process.run(false, args, args.length);
} catch (e) {}
},
getElementsByXPath: getElementsByXPath,
Expand Down Expand Up @@ -2544,117 +2555,6 @@ function saveFile(name, data) {
foStream.close();
}

function exec(path, arg){
var file = Cc['@mozilla.org/file/local;1'].createInstance(Ci.nsILocalFile);
var process = Cc['@mozilla.org/process/util;1'].createInstance(Ci.nsIProcess);
try {
var a = (typeof arg == 'string' || arg instanceof String) ? arg.split(/\s+/) : [arg];
file.initWithPath(path);

if (!file.exists()) {
Cu.reportError('File Not Found: ' + path);
return;
}

if (file.isExecutable()) {
process.init(file);
process.run(false, a, a.length);
} else {
file.launch();
}

} catch(e) {
debug(e);
}
}

function xToString(x) {
function toStr(x) {
switch (typeof x) {
case 'undefined':
return Str(x);
case 'boolean':
return Str(x);
case 'number':
return Str(x);
case 'string':
return ('"' +
(x.replace(/(?:\r\n|\n|\r|\t|\\|")/g, function(a) {
var ret;
switch (a) { //转成字面量
case '\r\n':
ret = '\\r\\n'
break;
case '\n':
ret = '\\n';
break;
case '\r':
ret = '\\r'
break;
case '\t':
ret = '\\t'
break;
case '\\':
ret = '\\\\'
break;
case '"':
ret = '\\"'
break;
default:
break;
}
return ret;
})) + '"');
case 'function':
var fnStr = Str(x);
return fnStr.indexOf('native code') == -1 ? fnStr : 'function(){}';
case 'object':
//注,object的除了单纯{},其他的对象的属性会造成丢失..
if (x === null) {
return Str(x);
}
switch (x.constructor.name) {
case "Object":
var i;
var rStr = '';
for (i in x) {
if (!x.hasOwnProperty(i)) { //去掉原型链上的属性.
continue;
}
// rStr += toStr(i) + ':' + toStr(x[i]) + ',';
rStr += i + ':' + toStr(x[i]) + ',';
}
return ('{' + rStr.replace(/,$/i, '') + '}');
case "Array":
var i;
var rStr = '';
for (i in x) {
if (!x.hasOwnProperty(i)) { //去掉原型链上的属性.
continue;
}
rStr += toStr(x[i]) + ',';
}
return '[' + rStr.replace(/,$/i, '') + ']';
case "String":
return toStr(Str(x));
case "RegExp":
return Str(x);
case "Number":
return Str(x);
case "Boolean":
return Str(x);
default:
//alert(x.constructor);//漏了什么类型么?
break;
}
default:
break;
}
}
var Str = String;
return toStr(x);
}

})('\
#uAutoPagerize-icon {\
list-style-image: url(\
Expand Down

0 comments on commit a301dcc

Please sign in to comment.