FundNetValueReminder

基金净值提示

当前为 2018-12-19 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name    FundNetValueReminder
// @description  基金净值提示
// @version  3
// @namespace net.jacky-q.userscript
// @grant    GM_xmlhttpRequest
// @require    https://code.jquery.com/jquery-1.12.4.min.js
// @include http://www.1234567.com.cn/
// ==/UserScript==

var MONITOR_LOCATION = "http://fund.eastmoney.com/f10/jjjz_%fund_code%.html";
var MONITOR_INTERVAL = 30 * 1000;
var slowEList = [{
    fund_code: "100032",
    fund_name: "富国中证红利指数增强",
    net_value: 0.9426,
    monitor_flag: true,
    has_alerted : false
}, {
    fund_code: "000968",
    fund_name: "广发养老指数A(000968)",
    net_value: 0.8507,
    monitor_flag: true,
    has_alerted : false
}, {
    fund_code: "160416",
    fund_name: "华安标普石油指数(160416)",
    net_value: 0.871,
    monitor_flag: true,
    has_alerted : false
}, {
    fund_code: "001051",
    fund_name: "华夏上证50ETF联接A(001051)",
    net_value: 0.731,
    monitor_flag: true,
    has_alerted : false
}, {
    fund_code: "001180",
    fund_name: "广发医药卫生联接A(001180)",
    net_value: 0.8025,
    monitor_flag: true,
    has_alerted : false
}, {
    fund_code: "162411",
    fund_name: "华宝标普石油指数(162411)",
    net_value: 0.502,
    monitor_flag: true,
    has_alerted : false
}, {
    fund_code: "000051",
    fund_name: "华夏沪深300ETF联接A(000051)",
    net_value: 0.965,
    monitor_flag: true,
    has_alerted : false
}, {
    fund_code: "000071",
    fund_name: "华夏恒生ETF联接(000071)",
    net_value: 1.025,
    monitor_flag: true,
    has_alerted : false
}, {
    fund_code: "270048",
    fund_name: "广发纯债债券A(270048)",
    net_value: 1.164,
    monitor_flag: true,
    has_alerted : false
}, {
    fund_code: "000614",
    fund_name: "华安德国30(DAX)联接(000614)",
    net_value: 1.006,
    monitor_flag: true,
    has_alerted : false
}, {
    fund_code: "050027",
    fund_name: "博时信用债纯债债券A(050027)",
    net_value: 1.044,
    monitor_flag: true,
    has_alerted : false
}, {
    fund_code: "003376",
    fund_name: "广发中债7-10年国开债指数A(003376)",
    net_value: 0.558,
    monitor_flag: true,
    has_alerted : false
}];
var zoneList = [{
    fund_code : "110026",
    fund_name : "易方达创业板ETF联接A",
    net_value : 1.3654,
    monitor_flag : true,
    has_alerted : false
},{
    fund_code : "004752",
    fund_name : "广发中证传媒ETF连接A",
    net_value : 0.6845,
    monitor_flag : true,
    has_alerted : false
}];
var MONITOR_STRATEGY = {
    SLOW_E :{
        list : slowEList,
        monitorExpress : function (curNetValue, monitorNetValue,threshold) {
            return (curNetValue - monitorNetValue) / monitorNetValue <= 0.0;
        },
        giveUpExpress : function (curNetValue,monitorNetValue,threshold) {
            return curFundNet - monitorNetValue > 0.05;
        }
    } ,
    ZONE_FLOW : {
        list : zoneList,
        monitorExpress : function (curNetValue, monitorNetValue,threshold) {
            return curNetValue > monitorNetValue;
        },
        giveUpExpress : function (curNetValue,monitorNetValue,threshold) {
            return curFundNet < monitorNetValue * 0.94 ;
        }
    }
};
var curStrategy = MONITOR_STRATEGY.ZONE_FLOW;

// the guts of this userscript
function main() {
    // console.log(typeof $.ajax);
    setInterval(function () {
        var fundList = loadMonitorItem();
        console.log("当前监控基金数:" +  fundList.length);
        for (var i = 0; i < fundList.length; i++) {
            var d = showAlert(fundList[i]);
            loadNetValue(fundList[i], d);
        }
    }, MONITOR_INTERVAL);


}

function showAlert(item) {
    return function (/*curFundNet*/) {
        // console.log("get data:"+item.fund_name);
        var curFundNet = arguments.length > 0 ? arguments[0] : 10000;
        // console.log(item.fund_name + " net value2 :" + curFundNet);
        // console.log("get diff:" + (curFundNet - item['net_value']) / item['net_value'] );
        if ( curStrategy.monitorExpress(curFundNet,item['net_value'])) {
            var tipText = ("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n" + item['fund_name'] + '的净值达到' + curFundNet + ",逼近监视阈值" + item['net_value'] + "\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            console.log(tipText);
            if(!item.has_alerted){
                alert(tipText);
                updateAlertTip(item);
            }
            //  alert(item['fund_name'] + '的净值达到' + curFundNet + ",逼近监视阈值" + item['net_value'] + "!");
        } else if ( curStrategy.giveUpExpress(curFundNet,item['net_value'])) {
            removeMonitor(item);
        }

    }
}

function removeMonitor(item) {
    for (var i = 0; i < curStrategy.list.length; i++) {
        if (item['fund_code'] === curStrategy.list[i].fund_code) {
            curStrategy.list[i].monitor_flag = false;
            console.log("移除监控基金:"+item.fund_name);
        }
    }
}
function updateAlertTip(item) {
    for (var i = 0; i < curStrategy.list.length; i++) {
        if (item['fund_code'] === curStrategy.list[i].fund_code) {
            curStrategy.list[i].has_alerted = true;
        }
    }
}

function loadMonitorItem() {
    var list = [];
    for (var i = 0; i < curStrategy.list.length; i++) {
        if(curStrategy.list[i].monitor_flag){
            list.push(curStrategy.list[i]);
        }
    }
    return list;
}

function loadNetValue(item, callback) {
    //console.log("开始获取估算净值" + item.fund_name);
    if(!item.monitor_flag){
        return;
    }
    var url = MONITOR_LOCATION.replace("%fund_code%", item['fund_code']);
    url +="&tmp=" + new Date().getTime();
    //  console.log("url=" + url);

    $.ajax(url, {
        success: function (data, status, xhr) {
            var net = data.match(/lar bold guzhi">((\d|\.)+)<\/span>/);
            //   console.log(item.fund_name + "当前估值:" + net[1]);
            var fundNet = parseFloat(net[1]);
            //  console.log(item.fund_name + " net value1 :" + fundNet);
            callback(fundNet);
        },
        error: function () {
            console.log("error fetch:"  + item['fund_name']);
        }
    })
    //   var curFundNet = 2.530;
    //   callback.call(curFundNet);

}

// load jQuery and execute the main function
main();
//console.log('script loaded');