// ==UserScript== // @name 小米路由器PC端设备实时网速 // @namespace http://tampermonkey.net/ // @version 1.0 // @description 小米路由器PC端后台管理界面设备实时网速 // @author 过去终究是个回忆 // @license MIT // @match http://192.168.31.1/cgi-bin/luci/*/web/home* // @require https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/dayjs/1.10.8/dayjs.min.js // @require https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.14/vue.min.js // @require https://unpkg.com/ajax-hook@2.1.3/dist/ajaxhook.min.js // @require https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/element-ui/2.15.7/index.min.js // @grant GM_getResourceText // @grant GM_addStyle // @grant GM_addStyle // @grant unsafeWindow // @resource element-ui https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/element-ui/2.15.7/theme-chalk/index.min.css // @run-at document-start // @downloadURL none // ==/UserScript== (function () { 'use strict'; GM_addStyle(GM_getResourceText('element-ui')) GM_addStyle(` @font-face{font-family:element-icons;src:url(https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/element-ui/2.15.7/theme-chalk/fonts/element-icons.woff) format("woff"),url(https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/element-ui/2.15.7/theme-chalk/fonts/element-icons.ttf) format("truetype");font-weight:400;font-display:"auto";font-style:normal} #net-speed { float: left; margin-top: 40px; width: 100%; } .demo-table-expand { font-size: 0; } .speed-line { display: flex; justify-content: space-between; align-items: center; } .speed-line div[role="progressbar"] { width: 300px; } `) const maxEachDataStorage = 100 const updateDevDataEvent = new Event('updateDevData') const initData = { history: {}, tableData: [] } window.ah.proxy({ //请求成功后进入 onResponse: (response, handler) => { if (response.config.url.includes('/api/misystem/status')) { const data = JSON.parse(response.response) initData.tableData = data.dev data.dev.forEach(item => { if (!initData.history[item.mac]) { initData.history[item.mac] = [] } const each = { ...item, dateSecond: Date.now(), combinedSpeed: item.upspeed + item.downspeed, } if (initData.history[item.mac].length === maxEachDataStorage) { initData.history[item.mac][maxEachDataStorage] = each } else if (initData.history[item.mac].length < maxEachDataStorage) { initData.history[item.mac].push(each) } else if (initData.history[item.mac].length > maxEachDataStorage) { initData.history[item.mac].splice(maxEachDataStorage - 1, initData.history.length, each) } }) document.dispatchEvent(updateDevDataEvent) } handler.next(response) } }, unsafeWindow) window.onload = function () { const container = document.createElement('div') container.id = 'net-speed' console.log('net-speed starting...') const target = document.querySelector('#bd>.mod-routerstatus.nav-tab-content') target.appendChild(container) new Vue({ el: container, data() { return { dialogTableTitle: 'dialogTableTitle', dialogTableVisible: false, currentRow: {}, history: {}, tableData: [], } }, created() { this.history = initData.history this.tableData = initData.tableData document.addEventListener("updateDevData", () => { this.history = initData.history this.tableData = initData.tableData }) }, methods: { byteFormat: byteFormat, secondToDate: secondToDate, speedFormat(number, precision, isarray) { return this.byteFormat(number, precision, isarray) + '/S' }, speedFormatter(row, column, cellValue) { return this.speedFormat(cellValue, 100) }, dataFormatter(row, column, cellValue) { return this.byteFormat(cellValue, 100) }, secondFormatter(row, column, cellValue) { return this.secondToDate(cellValue) }, dateTimeFormatter(row, column, cellValue) { return dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') }, showHistoryData(row) { this.dialogTableVisible = true this.dialogTableTitle = `${row.devname}(${row.mac}) 历史数据` this.currentRow = row console.log(this.history) } }, template: `
上传速度:
下载速度:
上传速度:
下载速度: