Debian Codegraph @

src/scripts/article.js

raw symbols SCIP
1 QTerm.loadScript("utils.js");
2 var Article = Article ? Article : new Object;
3 Article.downloading = false;
4 Article.textList= [];
5 Article.articleText = "";
6
7 Article.q = new QEventLoop;
8
9 Article.getArticle = function()
10 {
11 this.textList = [];
12 this.downloading = true;
13 QTerm.scriptEvent.connect(this, this.downloadArticle);
14 this.downloadArticle("Article: start");
15 QTerm.eventFinished.connect(this,this.q.quit);
16 if (this.downloading)
17 this.q.exec();
18 QTerm.eventFinished.disconnect(this,this.q.quit);
19 return Article.articleText;
20 }
21
22 // check it there is duplicated string
23 // it starts from the end in the range of one screen height
24 // so this is a non-greedy match
25 Article.checkDuplicate = function()
26 {
27 if (this.textList.length == 0) {
28 return 0;
29 }
30 var i=0;
31 var emptyLines = 0
32 var start=0;
33 var strTemp = QTerm.getText(0).rtrim();
34 var size = strTemp.length
35 while ( emptyLines < QTerm.rows() -1 && strTemp.length == 0) {
36 emptyLines++;
37 strTemp = QTerm.getText(emptyLines).rtrim();
38 }
39
40 if (strTemp.length == 0) {
41 return 0;
42 }
43
44 for(var index = this.textList.length -1; index > 0, i < QTerm.rows()-1; // not exceeeding the last screen
45 --index, i++)
46 {
47 if(this.textList[index] != strTemp)
48 continue;
49 var index2 = index;
50 var dup=true;
51 // match more to see if its duplicated
52 for(var j=emptyLines; j<=i; j++, index2++)
53 {
54 var str1 = QTerm.getText(j).rtrim();
55 if(this.textList[index2]!=str1)
56 {
57 dup = false;
58 break;
59 }
60 }
61 if(dup)
62 {
63 // set the start point
64 start = i+1;
65 break;
66 }
67 }
68 return start;
69 }
70
71 Article.pageComplete = function()
72 {
73 var bottom = QTerm.getText(QTerm.rows() - 1).rtrim();
74 if (QTerm.caretY() == QTerm.rows() - 1 && QTerm.caretX() >= bottom.length - 1) {
75 return true;
76 }
77 }
78
79 Article.downloadArticle = function(message)
80 {
81 if ((message == "QTerm: new data")||(message == "Article: start"))
82 {
83 if (!this.pageComplete())
84 return;
85 var start = this.checkDuplicate();
86 // add new lines
87 for(i=start;i<QTerm.rows()-1;i++)
88 this.textList[this.textList.length]=QTerm.getText(i).rtrim();
89
90 // the end of article
91 if( QTerm.endOfArticle() ) {
92 this.downloading = false;
93 this.articleText = this.textList.join("\n");
94 QTerm.scriptEvent.disconnect(this, this.downloadArticle);
95 QTerm.eventFinished();
96 return;
97 }
98
99 // continue
100 QTerm.sendString(" ");
101 }
102 }
103
104 QTerm.Article = Article;
105