summaryrefslogtreecommitdiff
path: root/res
diff options
context:
space:
mode:
authorIru Cai <mytbk920423@gmail.com>2014-04-07 20:32:41 +0800
committerIru Cai <mytbk920423@gmail.com>2014-04-07 20:32:41 +0800
commit88c98119b6e8d6d30731cd0d3e7fb3f9af5557cb (patch)
tree514bf161a790fc77ba5e136b7ac2fd00fd786e18 /res
parent7bf1d87cfb318a227528756eb8f89b8335665528 (diff)
downloadfqterm-88c98119b6e8d6d30731cd0d3e7fb3f9af5557cb.tar.xz
Add a script for downloading an article with ANSI color.
And it supports more BBS systems than the native copyArticle() function, but it's slower.
Diffstat (limited to 'res')
-rw-r--r--res/script/downloadart.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/res/script/downloadart.js b/res/script/downloadart.js
new file mode 100644
index 0000000..f0fd212
--- /dev/null
+++ b/res/script/downloadart.js
@@ -0,0 +1,40 @@
+fqterm.importFile("utils.js");
+
+var saveFile = "/tmp/save.txt";
+var LastLine = 23;
+var timeout = 300;
+var retries = 5;
+// when the article is not completely read
+// there'll be a 'XX%' at the last line
+var r = new RegExp("%");
+var esc = new RegExp('\x1b\x1b','g');
+
+getAnsiLine = function(i){
+ var line = fqterm.getAttrText(i).replace(esc, "\x1b[");
+ return line+"\n";
+}
+
+// first copy the previous lines
+for (var i=0; i<LastLine; ++i){
+ fqterm.appendFile(saveFile, getAnsiLine(i));
+}
+
+// then copy until article ends
+while (1){
+ var line = fqterm.getText(LastLine);
+ if (!r.exec(line)){ // article ends
+ break;
+ }
+ var prev = getAnsiLine(LastLine-1);
+ var cur;
+ fqterm.sendString("j");
+ for (var i=0; i<retries; i++){
+ var cur = getAnsiLine(LastLine-1);
+ if (prev == cur){
+ sleep(timeout);
+ }
+ }
+ fqterm.appendFile(saveFile, cur);
+}
+
+