summaryrefslogtreecommitdiff
path: root/res/script/libpost.js
diff options
context:
space:
mode:
authorIru Cai <mytbk920423@gmail.com>2014-04-20 22:09:17 +0800
committerIru Cai <mytbk920423@gmail.com>2014-04-20 22:09:17 +0800
commitb15900a363953591d48366379512795a9422222a (patch)
treeaa5248a9926adbef0cedd7d7dabaf9b157d13f65 /res/script/libpost.js
parent88c98119b6e8d6d30731cd0d3e7fb3f9af5557cb (diff)
downloadfqterm-b15900a363953591d48366379512795a9422222a.tar.xz
Add my qz script -- for fun!
2 functions are added to the script engine.
Diffstat (limited to 'res/script/libpost.js')
-rw-r--r--res/script/libpost.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/res/script/libpost.js b/res/script/libpost.js
new file mode 100644
index 0000000..fee7dea
--- /dev/null
+++ b/res/script/libpost.js
@@ -0,0 +1,69 @@
+fqterm.importFile("utils.js");
+var timeout=100;
+
+postID=function(){
+ var thisLine = fqterm.getText(fqterm.caretY());
+ var reg = new RegExp('[0-9]{1,}');
+ return reg.exec(thisLine);
+}
+
+lastPost=function(){
+ fqterm.sendString("$"); //last post
+ sleep(timeout);
+ return postID();
+}
+
+isBoard=function(){
+ var secondLine = fqterm.getAttrText(1);
+ var charString = "Ctrl-P";
+ var myReg = new RegExp(charString);
+ return myReg.exec(secondLine)==charString;
+}
+
+postAction=function(){
+ if (isBoard()){
+ fqterm.sendParsedString("^p");
+ }else{
+ fqterm.sendString("a");
+ }
+}
+
+postEmpty=function(title){
+ // postAction() is now deprecated
+ if (isBoard()){
+ fqterm.sendParsedString("^p");
+ fqterm.sendString(title+"\n0\n\n"); // no qmd
+ }else{
+ fqterm.sendString("a"+title+"\n");
+ }
+ sleep(timeout);
+ fqterm.sendParsedString("^W\n");
+ sleep(timeout);
+}
+
+pastefile=function(filename){
+ var content = fqterm.readFile(filename);
+ for (var j = 0; j < content.length; ++j)
+ {
+ if (content[j] != '\033')
+ fqterm.sendString(content[j]);
+ else
+ fqterm.sendParsedString("^[^[");
+ }
+ fqterm.sendParsedString("^W\n");
+ sleep(timeout);
+}
+
+copyline=function(){
+ var line=fqterm.caretY();
+ var filename = "/tmp/test.txt";
+ fqterm.writeFile(filename, "");
+ for (var i=line-1;i<=line+1;++i){
+ var origline=fqterm.getAttrText(i);
+ var reg = new RegExp('\x1b\x1b','g');
+ var ANSIStr = origline.replace(reg,'\x1b[');
+ fqterm.appendFile(filename, ANSIStr);
+ fqterm.appendFile(filename, "\n");
+ }
+ return filename;
+}