Repository navigation
Expand file tree
/
Copy pathAlertBox.js
More file actions
151 lines (130 loc) · 3.75 KB
/
Copy pathAlertBox.js
File metadata and controls
151 lines (130 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*********************************************************************************
* pentadactyl plugin for extension AlertBox
* https://addons.mozilla.org/en-US/firefox/addon/alertbox/
* :openunread,command to list unread list
* Intercept dactyl.open,auto mark unread to read
* add completer to open/tabopen,if no input,will open first unread link:o<Enter>
* ******************************************************************************/
var Service = Components.classes['@ajitk.com/alertbox/alertbox;1'].getService().wrappedJSObject;
//global UnRead list
let UnReadList=[];
//get unread list,will be called in
// init
// when unread items changes
function FindUnReadList(){
Service.store.SieveStore.find({
state: 40, /* C.STATE_READY, */
'ts_view.lt': { name: 'ts_data', type: 'field' }
}, {
only: ['id','uri','name', 'text', 'ts_data'],
}, function(err, result) {
UnReadList=result.data;
});
}
// Run At init
FindUnReadList();
// Number of unread items changes. Update global list.
Service.service.state.on('change:unread', function() {
FindUnReadList();
});
let AlertBoxUtil={
//get and return unread list
getUnread : function(){
var il=[];
for each(item in UnReadList)
il.push([item.uri,item.text.substr(0,60) + " - " + item.name]);
return il;
},
//mark url's item to readed
markRead : function(url){
Service.notify.Popup.hide();
var id="";
for each(item in UnReadList){
if(item.uri==url){
id=item.id;
break;
}
}
if(id && id.length>0){
Service.store.SieveStore.update(
id,
{ ts_view: Date.now() }
//function(){FindUnReadList();}
);
}
},
//get next unread url
getNextUrl : function(){
return UnReadList && UnReadList.length > 0
? UnReadList[0].uri
: "";
},
//open given url,mark it as readed
openUrl : function(url){
if(url=="") {
Cc["@mozilla.org/alerts-service;1"].getService(Ci.nsIAlertsService).showAlertNotification(
"chrome://alertbox/skin/icons/bell_32.png",
"AlertBox: no update found", "Away from the computer, cherish life...", true
);
return;
}
AlertBoxUtil.markRead(url);
if(dactyl.open_org!=null) dactyl.open_org(url);
else dactyl.open(url);
},
//completer for open/tabopen
completer: function (context) {
context.title=["AlertBox Unread List","New Content"];
context.completions=AlertBoxUtil.getUnread();
context.filterFunc=function(items){
var words = context.filter.toLowerCase().split(/\s+/g);
return [item for each(item in items) if((item.text + " " + item.description).toLowerCase().indexOf(words)>=0)];
}
}
}
//add command:open unread item,use first item if no input
group.commands.add(
['openunread', 'ou[nread]'],
'open unread site in alertbox',
function(args){
var url=(args && args.length>0) ? args[0] : url=AlertBoxUtil.getNextUrl();
AlertBoxUtil.openUrl(url);
},
{
bang: true,
completer: AlertBoxUtil.completer,
literal: 0
},
true
);
group.commands.add(
['findunread'],
'Find unread site in alertbox',
function(){
FindUnReadList();
}
);
//add unread list to open/tabopen's completer
if(true){
completion.addUrlCompleter("AlertBox","Unread List",AlertBoxUtil.completer);
var array=[];
array.push("AlertBox");
options["complete"].forEach(function(item){
if(item!="AlertBox") array.push(item);
})
options["complete"]=array;
}
//Intecept dactyl.open to mark unread to read
//check null to avoid repeat intecept
if(true && dactyl.open_org==null){
dactyl.open_org = dactyl.open;
dactyl.open = function open(urls, params = {}, force = false) {
if(urls=="about:blank"){
var next=AlertBoxUtil.getNextUrl();
if(next && next.length>0) urls=next;
}
AlertBoxUtil.markRead(dactyl.parseURLs(urls)[0]);
dactyl.open_org(urls,params,force);
setTimeout(FindUnReadList,2000);
}
}