Last active
December 25, 2017 10:13
-
-
Save SiZapPaaiGwat/bdefb34411fc3184a5d64fe889d5e7f8 to your computer and use it in GitHub Desktop.
雪球助手,方便跳转到理性仁网站查看个股数据。(user.js)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name 雪球助手 | |
// @namespace http://tampermonkey.net/ | |
// @version 1.1 | |
// @description 愉快地在雪球、理性仁等网站之间玩耍(跳转) | |
// @author 小紫baby | |
// @include /^https:\/\/(xueqiu|www\.lixinger)+\.com.*/ | |
// @grant none | |
// ==/UserScript== | |
/*eslint-disable*/ | |
(function () { | |
'use strict' | |
var hkStockTemplateUrl = 'https://www.lixinger.com/analytics/company/hk/{0}/detail/fundamental/value' | |
var szStockTemplateUrl = 'https://www.lixinger.com/analytics/company/sz/{0}/detail/fundamental/value' | |
var szFundTemplateUrl = 'https://www.lixinger.com/analytics/fund/sz/{0}/detail' | |
var szIndiceTemplateUrl = 'https://www.lixinger.com/analytics/indice/sz/{0}/detail/value' | |
var shStockTemplateUrl = 'https://www.lixinger.com/analytics/company/sh/{0}/detail/fundamental/value' | |
var shFundTemplateUrl = 'https://www.lixinger.com/analytics/fund/sh/{0}/detail' | |
var shIndiceTemplateUrl = 'https://www.lixinger.com/analytics/indice/sh/{0}/detail/value' | |
var regList = [ | |
// 港股证券 | |
/^\d{5}$/, | |
// 深市证券 | |
/^SZ(00|01|02|20|30)\d{4}$/, | |
// 深市基金 | |
/^SZ(15|16)\d{4}$/, | |
// 深市指数 | |
// 深证综指,理性仁深圳A股 | |
/^SZ399106$/, | |
/^SZ39\d{4}$/, | |
// 沪市证券 | |
/^SH(600|601|900)\d{3}$/, | |
// 沪市基金 | |
/^SH(510|512)\d{3}$/, | |
// 沪市指数 | |
// 上证指数,理性仁上海A股 | |
/^SH000001$/, | |
/^SH000\d{3}$/ | |
] | |
var urlList = [ | |
hkStockTemplateUrl, | |
szStockTemplateUrl, | |
szFundTemplateUrl, | |
'https://www.lixinger.com/analytics/indice/lxr/1000003/detail/value', | |
szIndiceTemplateUrl, | |
shStockTemplateUrl, | |
shFundTemplateUrl, | |
'https://www.lixinger.com/analytics/indice/lxr/1000004/detail/value', | |
shIndiceTemplateUrl | |
] | |
function normalizeCode(code) { | |
return code && code.replace(/[a-z]+/gi, '') | |
} | |
function getLixingrenStockPageUrl(code) { | |
var stockCode = normalizeCode(code) | |
// 美股不支持 | |
if (!stockCode) return '' | |
for (var i = 0; i < regList.length; i += 1) { | |
if (regList[i].test(code)) { | |
return urlList[i].replace('{0}', stockCode) | |
} | |
} | |
return '' | |
} | |
function setHrefAttribute (el, code) { | |
var url = getLixingrenStockPageUrl(code) | |
if (!url) { | |
console.log('不支持的证券代码:' + code) | |
return | |
} | |
el.attr('href', url) | |
} | |
if (location.host === 'xueqiu.com') { | |
/** | |
* 主页自选股跳转到理性仁 | |
*/ | |
var linkSelector = '#optional tr.sortable a.code' | |
$(document.body).on('click', linkSelector, function(e) { | |
var href = $(this).attr('href') | |
if (href.indexOf('www.lixinger.com') > -1) { | |
return | |
} | |
var code = href.replace('/S/', '') | |
setHrefAttribute($(this), code) | |
}) | |
/** | |
* 兼容旧版主页 | |
*/ | |
var oldTitleSelector = 'tr[data-symbol] span.title' | |
var oldSymbolSelector = 'tr[data-symbol] span.subtitle' | |
$(document.body).on('mouseenter', oldTitleSelector, function(e) { | |
var code = $(this).parents('tr[data-symbol]').attr('data-symbol') | |
$(this).parent().attr('href', '/S/' + code) | |
}) | |
$(document.body).on('mouseenter', oldSymbolSelector, function(e) { | |
var code = $(this).parents('tr[data-symbol]').attr('data-symbol') | |
setHrefAttribute($(this).parent(), code) | |
}) | |
/** | |
* 股票页跳转到理性仁 | |
*/ | |
var titleSelector = '#app .stock-name' | |
$(titleSelector).eq(0).after('<div style="float: left;margin: 0 20px">' + | |
'<a class="lxr-icon" target="_blank"><img style="width: 20px;height: 20px;vertical-align: middle" ' + | |
' src="https://www.lixinger.com/static/img/logo50x50.png" style="vertical-align: middle;" /></a></div>') | |
$('.lxr-icon').one('mouseenter', function() { | |
var code = location.pathname.replace('/S/', '') | |
setHrefAttribute($(this), code) | |
}) | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment