FundNetValueReminder

基金净值提示

目前為 2018-12-19 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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');