forked from Ahaochan/Tampermonkey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SteamDB 增强.user.js
73 lines (66 loc) · 2.7 KB
/
SteamDB 增强.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// ==UserScript==
// @name SteamDB Plus
// @name:zh-CN SteamDB 增强
// @name:zh-TW SteamDB 增強
// @namespace https://github.com/Ahaochan/Tampermonkey
// @version 0.0.1
// @icon https://steamdb.info/favicon.ico
// @description 1. 排序功能 2. 自动生成ASF命令
// @author Ahaochan
// @include http*://steamdb.info/upcoming/free/*
// @license GPL-3.0
// @supportURL https://github.com/Ahaochan/Tampermonkey
// @grant GM.setClipboard
// @grant GM_setClipboard
// @require https://cdn.bootcdn.net/ajax/libs/jquery/2.2.4/jquery.min.js
// @require https://greasyfork.org/scripts/375359-gm4-polyfill-1-0-1/code/gm4-polyfill-101.js?version=652238
// @run-at document-end
// @noframes
// ==/UserScript==
jQuery(function ($) {
$('table.table-products').each(function () {
let $table = $(this);
let $thead = $table.find('thead');
let $tbody = $table.find('tbody');
(function ($table, $thead, $tbody) {
// 1. 添加表头
$thead.find('tr:first').append('<th style="width:120px">ASF</th>');
// 2. 添加排序功能
$thead.find('th').each(function (index, ele) {
let $th = $(this);
$th.text($th.text() + ' v');
$th.attr('ahao-asc', 1);
$th.click(function () {
let flag1 = parseInt($th.attr('ahao-asc'));
let flag2 = flag1 === 1 ? -1 : 1;
let $list = $tbody.children();
$list.sort((a, b) => {
let t1 = $(a).find('td').eq(index).text();
let t2 = $(b).find('td').eq(index).text();
if(t1 < t2) { return flag1; }
if(t1 > t2) { return flag2; }
return 0;
});
$tbody.html($list);
$th.attr('ahao-asc', flag2);
});
});
})($table, $thead, $tbody);
// 2. 添加表体
(function ($table, $thead, $tbody) {
$tbody.find('tr').each(function () {
let $tr = $(this);
let id = $tr.children('td').eq(1).find('a').attr('href').match(/\d+/);
let command = `!addlicense ${id}`;
let $td = $(`<td>${command}</td>`);
$td.click(function () {
let $this = $(this);
$this.text('ASF command copied');
GM.setClipboard(command);
setTimeout(function () { $this.text(command); }, 2000);
});
$tr.append($td);
});
})($table, $thead, $tbody);
});
});