try to take over the world!
当前为
// ==UserScript==
// @name 酸酸乳节点延迟排序
// @namespace http://tampermonkey.net/
// @version 0.2.2
// @description try to take over the world!
// @author Rggle
// @match http://acucloud.ml/user/lookingglass
// @grant none
// ==/UserScript==
(function() {
var tableDom = document.querySelector('.table') // 获取table对象
var tbodyDom = tableDom.querySelector('tbody') // 获取tbody对象
addEvent()
// 添加事件
function addEvent () {
var thDomArr = tbodyDom.firstChild.querySelectorAll('th') // 获取th对象数组
thDomArr.forEach((v, i) => {
if (i > 0) {
v.style.cursor = 'pointer'
v.addEventListener('click', function () {
debounce(sortBySpeed.call(v, i))
})
}
})
}
// 点击事件 - 根据速度排序
var sortBySpeed = debounce(function (index) {
var trDomArr = Array.from(tbodyDom.querySelectorAll('tr'))
trDomArr.forEach((v, i) => {
if (i > 0) { // 第一个节点不处理
v.aaa = parseFloat(nthNode.call(v, 'td', index).innerText) // 添加当前速度值
} else { // 第一个节点速度默认为0
v.aaa = 0
}
})
trDomArr.sort(function (a, b) {
return a.aaa - b.aaa
})
tbodyDom.innerHTML = ''
trDomArr.forEach(v => {
tbodyDom.appendChild(v)
})
addEvent()
})
// 获取第n个节点
function nthNode (name, n) {
const nodeArr = this.querySelectorAll(name)
return nodeArr[n]
}
// 延迟点击
function debounce (func, delay) {
let timer
delay = delay || 200
return function (...args) {
return new Promise((resolve, reject) => {
if (timer) {
clearTimeout(timer)
}
timer = setTimeout(() => {
resolve(func.apply(this, args))
}, delay)
})
}
}
})();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址