summaryrefslogtreecommitdiff
path: root/res
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
parent88c98119b6e8d6d30731cd0d3e7fb3f9af5557cb (diff)
downloadfqterm-b15900a363953591d48366379512795a9422222a.tar.xz
Add my qz script -- for fun!
2 functions are added to the script engine.
Diffstat (limited to 'res')
-rw-r--r--res/script/README7
-rw-r--r--res/script/functions.js6
-rw-r--r--res/script/libpost.js69
-rw-r--r--res/script/qz.js36
-rw-r--r--res/script/testz.js76
5 files changed, 194 insertions, 0 deletions
diff --git a/res/script/README b/res/script/README
index c7dacbc..8e273fc 100644
--- a/res/script/README
+++ b/res/script/README
@@ -6,6 +6,13 @@ Any file to be written to or read from should be in the format of UTF-8.
Usage:
+//UI functions
+msgBox(msg)
+ no return value
+
+yesnoBox(msg)
+ return boolean value
+
sessionID=long(sys.argv[0])
formatError(sessionID)
diff --git a/res/script/functions.js b/res/script/functions.js
new file mode 100644
index 0000000..2461774
--- /dev/null
+++ b/res/script/functions.js
@@ -0,0 +1,6 @@
+
+rand=function(n){ //generate a random number b'w 0-(n-1)
+ var t=Math.random();
+ return Math.floor(t*n);
+}
+
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;
+}
diff --git a/res/script/qz.js b/res/script/qz.js
new file mode 100644
index 0000000..9a98bab
--- /dev/null
+++ b/res/script/qz.js
@@ -0,0 +1,36 @@
+fqterm.importFile("libpost.js");
+fqterm.importFile("testz.js");
+
+qz=function(){
+ articleID = lastPost();
+ ++articleID;
+ var IDStr=isz(articleID);
+ if (IDStr==-1){
+ var cont = true;
+ try
+ {
+ if (fqterm.yesnoBox("似乎不是整哦,继续抢吗?")==false){
+ cont = false;
+ }
+ }
+ catch(err)
+ {
+ }
+ if (cont){
+ IDStr = articleID;
+ }else{
+ return;
+ }
+ }
+ postEmpty(IDStr);
+ if (isBoard()){
+ fqterm.sendString("j=_"); //focus to the new post
+ sleep(500);
+ myFile=copyline();
+ fqterm.sendString("E"); //Edit the post
+ pastefile(myFile);
+ }
+}
+
+qz();
+
diff --git a/res/script/testz.js b/res/script/testz.js
new file mode 100644
index 0000000..ec7610b
--- /dev/null
+++ b/res/script/testz.js
@@ -0,0 +1,76 @@
+fqterm.importFile("functions.js");
+
+isexpt=function(num){
+ if (num==1){
+ return "1";
+ }
+ for (var i=2;i*i<=num;++i){
+ var p=i;
+ for (j=1;p<=num;++j){
+ if (p==num){
+ var strs = new Array();
+ strs[0] = i+"^"+j;
+ strs[1] = "(expt "+i+" "+j+")";
+ strs[2] = i+"**"+j;
+ return strs[rand(3)];
+ }else{
+ p *= i;
+ }
+ }
+ }
+ return -1;
+}
+
+ismod100=function(num){
+ var strs = new Array();
+ strs[0] = num;
+ if (num%1000==0){
+ strs[1] = "000";
+ return strs[rand(2)];
+ }else if (num%100==0){
+ strs[1] = "00";
+ return strs[rand(2)];
+ }else{
+ return -1;
+ }
+}
+
+isseq = function(num){
+ if (num<100){
+ return -1;
+ }
+ var digits = new Array();
+ var tmp = num;
+ var n = 0;
+ for (; tmp>0; n++){
+ digits[n] = tmp%10;
+ tmp = (tmp-digits[n])/10;
+ }
+ for (var i=1; i<n-1; ++i){
+ if (digits[i]*2==digits[i-1]+digits[i+1]){
+ continue;
+ }else{
+ return -1;
+ }
+ }
+ return num;
+}
+
+isz=function(num){
+ var str;
+ str = ismod100(num);
+ if (str!=-1){
+ return str;
+ }
+ str = isexpt(num);
+ if (str!=-1){
+ return str;
+ }
+ str = isseq(num);
+ if (str!=-1){
+ return str;
+ }
+ return -1;
+}
+
+