Chrome Quote Crawl Plugin
Want to sneak up on the market at work? Write a plug-in yourself, try to write one, create a new folder, name it StockMonitor, and put the files as follows:
- 3 .png icon files, 19X19, 48X48, 128X128, named 19, 48, 128 as plugin icons
- manifest.json: configuration file
{
"update_url": "https://clients2.google.com/service/update2/crx",
"name": "StockMonitor",
"version": "1.0.0",
"description": "StockMonitor",
"manifest_version": 1,
"browser_action": {
"default_icon": "19.png",
"default_title": "StockMonitor",
"default_popup": "popup.html"
},
"icons": {
"16": "19.png",
"48": "48.png",
"128": "128.png"
},
"permissions": [
"http://hq.sinajs.cn/",
"storage"
]
}
- popup.html: the main interface of the plugin
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
table {
width: 150px;
font-size: 10px;
text-align: center;
}
table tr th {
font-family: 'Courier New', Courier, monospace;
font-size: 12px;
}
.tr-red {
color: red;
}
.tr-green {
color: green;
}
</style>
</head>
<div id="maincontent">
<table>
<tr>
<th>名称</th>
<th>现价</th>
<th>涨幅</th>
</tr>
<tr id="510300">
<td>300ETF</td>
<td>0.000</td>
<td>-0.00%</td>
</tr>
<tr id="601288">
<td>农业银行</td>
<td>0.000</td>
<td>+0.00%</td>
</tr>
<tr id="000157">
<td>中联重科</td>
<td>0.000</td>
<td>+0.00%</td>
</tr>
</table>
</div>
<div>
<script type="text/javascript" charset="utf-8" src='jquery.min.js'></script>
<script type="text/javascript" charset="utf-8" src='refresh.js'></script>
</div>
</html>
- refresh.js: data acquisition script
var stock = {
format_number: function(s, n) {
n = n > 0 && n <= 20 ? n : 2;
s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
var l = s.split(".")[0].split("").reverse(),
r = s.split(".")[1];
t = "";
for (i = 0; i < l.length; i++) {
t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
}
return t.split("").reverse().join("") + "." + r;
},
init: function() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
var quoteStr = xmlhttp.responseText;
quoteStr = quoteStr
.replace(/var hq_str_s_sz/g, '')
.replace(/var hq_str_s_sh/g, '')
.replace(/=/g, ',')
.replace(/"/g, '')
.replace(/\n/g, '')
.replace(/\r\n/g, '');
quoteStr = quoteStr.substr(0, quoteStr.length - 1);
console.log(quoteStr);
var quotes = quoteStr.split(';');
for (var i = 0; i < quotes.length; i++) {
var quote = quotes[i].split(',');
var code = quote[0]; //代码
var price = parseFloat(quote[2]); //价格
var pct = parseFloat(quote[4]); //百分比
var tr = document.getElementById(quote[0]);
tr.children[1].innerText = stock.format_number(price, 3);
if (pct > 0) {
tr.setAttribute('class', 'tr-red');
tr.children[2].innerText = '+' + pct + '%';
} else if (pct = 0) {
tr.children[2].innerText = '*' + pct + '%';
} else {
tr.setAttribute('class', 'tr-green');
tr.children[2].innerText = '-' + pct + '%';
}
}
}
}
xmlhttp.open("GET", "http://hq.sinajs.cn/rn=1522216317579&list=s_sh510300,s_sh601288,s_sz000157", true);
xmlhttp.send();
}
};
$(function() {
stock.init();
});
Load the decompressed extension in the extension and you can use it. If you want to package it, Baidu~