// ==UserScript== // @name 天天基金数据抽取 // @namespace http://tampermonkey.net/ // @version 1.3.5 // @description 用以快捷显示累计净值,任期回报,一年前累计净值,月高点 // @author aotmd // @match http://fund.eastmoney.com/* // @match http://*.eastmoney.com/* // @grant GM_setValue // @grant GM_getValue // @grant GM_deleteValue // @downloadURL none // ==/UserScript== (function () { addLoadEvent(() => { var url = window.location.href; //主页面 var str = /fund\.eastmoney\.com\/.+/i; //净值页面 var str2 = /.+eastmoney\.com.+/i; if (str.test(url)) { window.setTimeout(() => { //做好显示面板 let divElement1 = document.createElement('div'); divElement1.className = "gs1"; document.body.appendChild(divElement1); divElement1.style="top: calc( 15% - 42px );;font-size: 16px;"; let divElement2 = document.createElement('div'); divElement2.className = "gs1"; document.body.appendChild(divElement2); let divElement3 = document.createElement('div'); divElement3.className = "gs1"; document.body.appendChild(divElement3); divElement3.style="top: calc( 15% + 164px );"; //显示基金名称 var 基金名称=document.querySelector("#body > div:nth-child(8) > div > div > a:nth-child(7)").innerText; divElement1.innerHTML = 基金名称; var 任期回报 = (document.querySelector("tr.noBorder > td.td04.bold.ui-color-red").innerText.replace("%","")/100).toFixed(4); var 任职时间 = document.querySelector("tr.noBorder > td.td01").innerText.replace("~至今",""); var 累计净值 = document.querySelector("dl.dataItem03 > dd.dataNums > span").innerText; var 净值时间 = document.querySelector("dl.dataItem02 > dt > p").innerText.split('(')[1].replace(')', ''); //取得指定股票代码 var 股票代码=window.location.pathname.replace("/","").replace(".html",""); var 净值网址=document.querySelector("#Div2 > div.item_title.hd > div.item_more > a").href; //打开新窗口,获取净值 window.open(净值网址+"?ref="+股票代码, '_blank', "height=100,width=100,top="+window.screen.height+",left="+window.screen.width+",location=0,menubar=0,status=0,titlebar=0,toolbar=0"); //持续监听变化 var flag=""; window.setInterval(()=>{ //显示基本信息 var 一年前的时间=GM_getValue(股票代码+"时间"); var 一年前累计净值=GM_getValue(股票代码+"净值"); if (flag===一年前累计净值)return; flag=一年前累计净值; var 近一年=((累计净值/一年前累计净值-1)*100).toFixed(2)+"%"; divElement2.innerHTML = "近一年:       "+近一年+ "
净值时间: " + 净值时间 + "
累计净值:    " + 累计净值 + "
取值时间: " + 一年前的时间 + "
累计净值:    " + 一年前累计净值 + "
任职时间: " + 任职时间 + "
任期回报:    " + 任期回报; },100); var flag2; window.setInterval(()=>{ if (flag2===GM_getValue(股票代码+"近一个月最大累计净值时间"))return; flag2=GM_getValue(股票代码+"近一个月最大累计净值时间"); //显示数据信息 var 近一个月最大累计净值时间=GM_getValue(股票代码+"近一个月最大累计净值时间"); var 近一个月最大累计净值=GM_getValue(股票代码+"近一个月最大累计净值"); var 当前估值=parseFloat((document.querySelector("#gz_gszzl").innerText.replace("%","")/100).toFixed(4)); var 与月高点的差距=1-累计净值*(1+(当前估值))/近一个月最大累计净值; console.log(累计净值); console.log(当前估值); console.log(近一个月最大累计净值); console.log(与月高点的差距); 与月高点的差距=(与月高点的差距*100).toFixed(2)+"%"; divElement3.innerHTML ="近一个月最大累计净值:
取值时间:"+近一个月最大累计净值时间+ "
累计净值:    " + 近一个月最大累计净值+ "
与月高点的差距:"+与月高点的差距; },100); }, 0); }else if (str2.test(url)&&getQueryString("ref")!=null){ var ref=getQueryString("ref"); window.setTimeout(() => { //找到近20个交易日累计净值的最大值 var 近20个交易日时间=document.querySelectorAll("#jztable > table > tbody > tr > td:nth-child(1)"); var 近20个交易日累计净值=document.querySelectorAll("#jztable > table > tbody > tr > td:nth-child(3)"); var maximumIndex=0; for (let key in 近20个交易日累计净值) { if (近20个交易日累计净值[key].innerText>近20个交易日累计净值[maximumIndex].innerText){ maximumIndex=key; } } GM_setValue(ref+"近一个月最大累计净值时间", 近20个交易日时间[maximumIndex].innerText); GM_setValue(ref+"近一个月最大累计净值", 近20个交易日累计净值[maximumIndex].innerText); //找一年前的累计净值 document.querySelector("#pagebar > div.pagebtns > input.pnum").value=13; document.querySelector("#pagebar > div.pagebtns > input.pgo").click(); window.setTimeout(() => { var 时间=document.querySelectorAll("#jztable > table > tbody > tr > td:nth-child(1)"); var 净值=document.querySelectorAll("#jztable > table > tbody > tr > td:nth-child(3)"); GM_setValue(ref+"时间", 时间[2].innerText); GM_setValue(ref+"净值", 净值[2].innerText); window.close(); },500); },0); } }); addStyle(` .gs1 { padding: 5px 5px; font-size: 14px; color: snow; position: fixed; text-align: left; cursor: copy; border-radius: 10px; background-color: rgba(135, 134, 241, 0.84); right: 5px; top: 15%; z-index: 999999; //box-shadow: 0 0 7px 0 rgba(18, 80, 18,0.4), 0 0 0 1px rgba(0,0,0,0.3); min-width: 144px; }`); /** * 添加浏览器执行事件 * @param func 无参匿名函数 */ function addLoadEvent(func) { let oldOnload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function () { try { oldOnload(); } catch (e) { console.log(e); } finally { func(); } } } } /** * 获取网页参数 * @param name 参数名称 * @returns {string|null} */ function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = decodeURI(window.location.search).substr(1).match(reg); if(r != null) return (r[2]); return null; } //添加css样式 function addStyle(rules) { let styleElement = document.createElement('style'); styleElement["type"] = 'text/css'; document.getElementsByTagName('head')[0].appendChild(styleElement); styleElement.appendChild(document.createTextNode(rules)); } /** * 对象排序方法 * @param obj1 * @param obj2 * @returns {number} */ var compare = function (obj1, obj2) { var val1 = obj1.innerText; var val2 = obj2.innerText; if (val1 < val2) { return -1; } else if (val1 > val2) { return 1; } else { return 0; } } })();