-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcaniuse.command.js
110 lines (88 loc) · 2.87 KB
/
caniuse.command.js
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
var caniuseData = require("./data/data.js");
var adapterQueryData = require("./data/adapter.js");
module.exports = function(view, edit){
// view.insert(edit, 0, "HelloWorld");
var detectBrowers = [
'ie'
, 'firefox'
, 'chrome'
, 'safari'
, 'chrome'
, 'opera'
];
function getSelContent() {
var selections = view.sel()[0];
var text = "";
// console.log(selections);
if(!selections.empty()) {
// console.log(view.substr(21));
var begin = selections.a;
while(begin++ < selections.b) text += view.substr(begin - 1)
}
return text;
}
function getResult(data) {
var result = [];
for(var i = 0, li; li = detectBrowers[i++]; ) {
var vers = getVers(data[li]);
vers && result.push(li + " " + vers);
}
return result.join(" | ");
}
function getVers(data) {
var ret = [];
var result = [];
var keys = Object.keys(data).sort(function (a, b) {
return +a > +b;
});
for (var i = 0; i < keys.length; i++) {
(~data[keys[i]].indexOf("a") || ~data[keys[i]].indexOf("y")) && ret.push(keys[i]);
};
var begin = ret.shift();
var end = ret.pop();
begin && result.push(begin);
end && result.push(end);
return result.join("-");
}
var showStatus = function() {
var timer = null;
var shower = null;
var uid = 0;
return function(content) {
// for(var i = 0; i< 30;i++){
// view.erase_status("caniuse" + uid);
// }
// TODO, how to keep info on status bar?
var id = uid++;
// clearTimeout(timer);
// clearInterval(shower);
view.set_status("caniuse" + id, content);
// var ii = 0;
// shower = setInterval(function() {
// view.set_status("caniuse" + id, content);
// }, 400);
timer = setTimeout(function() {
// shower && clearInterval(shower);
view.erase_status("caniuse" + id);
}, 30000);
}
}();
function adapterQuery(query, data) {
query = (query + "").toLowerCase();
if(adapterQueryData[query]) return adapterQueryData[query];
for(var key in adapterQueryData) {
if(~key.indexOf(query)) return adapterQueryData[key];
}
if(data[query]) return query;
for(var k in data) {
if(~k.indexOf(query)) return k;
}
return "";
}
var text = getSelContent();
// console.log(text);
if(!text) return;
var data = caniuseData.data;
var query = adapterQuery(text, data);
if(query && data[query]) showStatus(data[query].title + ": " + getResult(data[query].stats));
}