Created
March 18, 2015 16:32
-
-
Save Ivlyth/3555ab97e2e6b799babf to your computer and use it in GitHub Desktop.
在查看 温州贷 - 给力标详情页的时候, 将投标纪录列表更换为图表显示, 需要配合 chrome 插件 tampermonkey 配合
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 WZD | |
// @namespace http://myth.ren | |
// @version 0.0.1 | |
// @description just for learning | |
// @author Myth | |
// @match http://invest.wzdai.com/pagers/invest/detail_*.html | |
// @grant none | |
// @require http://code.jquery.com/jquery-latest.js | |
// @require http://w.myth.ren/amcharts.js | |
// @require http://w.myth.ren/serial.js | |
// @require http://w.myth.ren/none.js | |
// ==/UserScript== | |
var userRecords = {}; | |
function pushUserRecords(rs){ | |
for(var i in rs){ | |
var r = rs[i]; | |
var d = new Date(parseFloat(r.addtime)*1000); | |
var money = parseFloat(r.money); | |
var ds = d.format('yyyy-MM-dd hh:m:00'); | |
var mind = new Date(ds); | |
if(ds in userRecords){ | |
userRecords[ds] = userRecords[ds] + money; | |
}else{ | |
userRecords[ds] = money; | |
} | |
} | |
} | |
function getAllUserRecords(){ | |
var atags = $('.list-page a'); | |
var pagesCount = atags.length; | |
for(var i = 1; i <= pagesCount; i++){ | |
$.ajax({ | |
'url':'http://121.40.141.175:8080//invest/ajaxBorrowTenderIdList.html?borrowid='+$('#bid').html().split(':')[1]+'&page='+i, | |
'async':false, | |
'success':function(data){ | |
d = data.data.list; | |
pushUserRecords(d); | |
}, | |
'dataType':'jsonp' | |
}); | |
} | |
} | |
function generateChartData(){ | |
var d = []; | |
for (var i in userRecords){ | |
d.push({ | |
date:new Date(i), | |
visits:userRecords[i] | |
}); | |
} | |
d.sort(function(a, b){ | |
return a.date>b.date?1: | |
(a.date<b.date?-1:0); | |
}) | |
return d; | |
} | |
// for amcharts | |
var chart, chartData; | |
//function zoomChart() { | |
// // different zoom methods can be used - zoomToIndexes, zoomToDates, zoomToCategoryValues | |
// chart.zoomToIndexes(chartData.length - 40, chartData.length - 1); | |
//} | |
function drawCharts(){ | |
chartData = generateChartData(); | |
chart = AmCharts.makeChart("amchartdiv", { | |
"type": "serial", | |
"theme": "none", | |
//"pathToImages": "http://www.amcharts.com/lib/3/images/", | |
"dataProvider": chartData, | |
"valueAxes": [{ | |
"axisAlpha": 0.2, | |
"dashLength": 1, | |
"position": "left" | |
}], | |
//"mouseWheelZoomEnabled":true, | |
"graphs": [{ | |
"id":"g1", | |
"balloonText": "[[category]]<br/><b><span style='font-size:14px;'>value: [[value]]</span></b>", | |
"bullet": "round", | |
"bulletBorderAlpha": 1, | |
"bulletColor":"#FFFFFF", | |
"hideBulletsCount": 50, | |
"title": "red line", | |
"valueField": "visits", | |
"useLineColorForBulletBorder":true | |
}], | |
//"chartScrollbar": { | |
// "autoGridCount": true, | |
// "graph": "g1", | |
// "scrollbarHeight": 40 | |
//}, | |
"chartCursor": { | |
"categoryBalloonDateFormat": "JJ:NN, DD MMMM", | |
"cursorPosition": "mouse" | |
}, | |
"categoryField": "date", | |
"categoryAxis": { | |
"parseDates": true, | |
"axisColor": "#DADADA", | |
"dashLength": 1, | |
"minPeriod": "mm", | |
"minorGridEnabled": true | |
}, | |
//"exportConfig":{ | |
// menuRight: '20px', | |
// menuBottom: '30px', | |
// menuItems: [{ | |
// icon: 'http://www.amcharts.com/lib/3/images/export.png', | |
// format: 'png' | |
// }] | |
//} | |
}); | |
//chart.addListener("rendered", zoomChart); | |
//zoomChart(); | |
} | |
function updateCharts(){ | |
chart.dataProvider = generateChartData(); | |
chart.validateData(); | |
} | |
function addAmchartsDiv(){ | |
// remove all elements in info_tab2 | |
$('#info_tab2 *').remove(); | |
$('#info_tab2').append($('<div id="amchartdiv" style="width:940px;height:480px;"></div>')); | |
} | |
setTimeout(function(){ | |
//滚动条下移 | |
scroll(0,480); | |
triggerClick(document.getElementById('tbnumber').parentNode); | |
getAllUserRecords(); | |
addAmchartsDiv(); | |
drawCharts(); | |
},600); | |
setTimeout(function(){ | |
//更新数据 | |
updateCharts(); | |
},1000); | |
//按;号键,更新数据 | |
document.onkeypress=function(ev){ | |
if(ev.keyCode==59){//[+]61;[;]59 | |
getAllUserRecords(); | |
setTimeout(function(){ | |
updateCharts(); | |
}, 500); | |
} | |
}; | |
function triggerClick(ele){ | |
var mEvent = document.createEvent("MouseEvents"); | |
mEvent.initEvent("click", true, true); | |
ele.dispatchEvent(mEvent); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment