想說有時候用之前寫的『自動抓取流量排行榜(ASP.Net)』還是不夠快速
練練Javascript,順便把『click後,自動切換ip所在offsetTop』實作出來
// ==UserScript==
// @name NPUST Net Flow Check
// @description NPUST Net Flow Check
// @include http://140.127.35.245/flowview/func/report/main_netflow_inout_theday_fast.php*
// ==/UserScript==
var osTop = new Array(); //記錄IP所在置位的offsetTop
var osTopSeq = 0; //預設顯示第幾筆位置,同時也用來記錄顯示至第幾筆位置
var trs = document.querySelectorAll('#maintable_netflow_inout > tbody > tr'); //表格內全部列
//切換位置
function movePos() {
osTopSeq++;
if (osTopSeq >= osTop.length) osTopSeq = 0;
window.scrollTo(0, osTop[osTopSeq]);
}
for (var i = 1; i < trs.length; i++) {
if (/140\.127\.22\.(228|234)/.test(trs[i].innerHTML)) {
//記錄ip所在offsetTop
osTop.push(trs[i].offsetTop);
//Highlight
for (var j = 0; j < trs[i].childNodes.length; j++)
if (trs[i].childNodes[j].nodeType == 1) trs[i].childNodes[j].style.backgroundColor = 'red';
}
}
//切換置預設位置
if (osTop.length != 0) window.scrollTo(0, osTop[0]);
//click表格可切換ip
document.getElementById('maintable_netflow_inout').addEventListener('click', movePos, false);