forked from boypt/stock-viewer
-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
122 lines (109 loc) · 3.47 KB
/
app.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
111
112
113
114
115
116
117
118
119
120
121
122
;(function($,undefined){
// 初始化指数数据
(function(){
var stock_list_data = localStorage.getItem('stock_list');
$("#importexport_code").val(stock_list_data || '');
if(!!stock_list_data){
return;
}
var data = [
{key: "sh000001", name: "上证指数", pinyin: "szzs", type: "ZS"},
{key: "sz399006", name: "创业板指", pinyin: "cybz", type: "ZS"},
{key: "sh601211", name: "国泰君安", pinyin: "gtja", type: "ZS"}
];
while(data.length){
Stock.addStock(data.pop());
}
})();
(function(){
var renderIconHtml = function(){
var confIcons = ['rabbit', 'panda', 'mouse', 'lips', 'bear', 'dog', 'angrybird', 'hellokitty', 'octopus', 'tiger', 'flower', 'crab'];
// window.confIcons = confIcons;
var html = [];
while(confIcons.length){
var icon = confIcons.shift();
html.push('<a href="#" class="icon" data-id="' + icon + '"><img src="images/icons/' + icon + '.png"/></a>');
}
$('#setting .iconlist').html(html.join(""));
}
var bindEvent = function(){
$('.setting').on('click', function(e){
$("#setting").toggle();
$('.mask').toggle();
});
$('#setting').delegate('.icon', 'click', function(e){
var name = $(this).attr('data-id');
localStorage.setItem('stock_icon', name);
$('.iconlist .icon').removeClass('cur');
$(this).addClass('cur');
chrome.browserAction.setIcon({path: 'images/icons/' + name + '.png'});
}).delegate('.close', 'click', function(e){
$('#setting').hide();
$('.mask').hide();
}).delegate('.default', 'click', function(e){
localStorage.removeItem('stock_icon');
chrome.browserAction.setIcon({path: 'images/logo48.png'});
});
$(".importexport").on('click', function(e){
var stock_list_data = localStorage.getItem('stock_list');
$("#importexport_code").val(stock_list_data || '');
$("#importexport").show();
$('.mask').toggle();
});
$("#importexport").delegate('.close', 'click', function(e){
$('#importexport').hide();
$('.mask').toggle();
});
$("#importexport_confirm").click(function (e) {
var textdata = $("#importexport_code").val();
try {
var tmp = JSON.parse(textdata);
console.log(tmp);
if (typeof(tmp['value']) !== 'object') {
alert('array error');
return;
};
} catch (e) {
alert(e);
return;
}
localStorage.setItem('stock_list', textdata);
window.close();
});
}
renderIconHtml();
bindEvent();
})();
var baseSugUrl = 'http://smartbox.gtimg.cn/s3/?t=all';
var localBaseSugUrl = localStorage.getItem('stock_sugUrl');
if(localBaseSugUrl && localBaseSugUrl != 'undefined'){
baseSugUrl = localBaseSugUrl;
}
/* 搜索suggest */
var sug = new Suggest({
template : {
item : '<div class="sug-item" data-pre="{0}" data-item="{0}{1}" data-type={4}>'+
'<span class="key">{1}</span><span class="name">{2}</span><span class="pinyin">{3}</span>'+
// '<span class="sug-plus"></span>'+
'</div>'
},
requestUrl : baseSugUrl,
requestQueryKey : 'q',
requestCallbackKey : 'cb',
localStorageKey : Stock.name,
suggestMaxNum: 15,
submitCallback : function(query){
var arr = query.split(" ");
var queryObj = {
key : arr[0]+arr[1],
name : arr[2],
pinyin : arr[3],
type : arr[4]
}
console.log(queryObj);
Stock.addStock(queryObj);
},
isCache : false
});
window.TYPE = "financeQQ";
})(jQuery);