Skip to content

Commit 9927471

Browse files
authored
Create 7lrewards.user.js
1 parent 28c8faf commit 9927471

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

keylol/7lrewards.user.js

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// ==UserScript==
2+
// @name 7L rewards displayer
3+
// @namespace https://github.com/sffxzzp
4+
// @description 显示赠楼价值
5+
// @include /https?:\/\/keylol.com\/.*/
6+
// @grant GM_xmlhttpRequest
7+
// @version 0.01
8+
// @updateURL https://github.com/sffxzzp/userscripts/raw/master/keylol/7lrewards.user.js
9+
// ==/UserScript==
10+
11+
(function () {
12+
var util = (function () {
13+
function util() {}
14+
util.xhr = function (xhrData) {
15+
return new Promise(function(resolve, reject) {
16+
var xhr = new XMLHttpRequest();
17+
xhr.open(xhrData.method || "get", xhrData.url, true);
18+
if (xhrData.method === "post") {xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded; charset=utf-8");}
19+
if (xhrData.cookie) {xhr.withCredentials = true;}
20+
xhr.responseType = xhrData.type || "";
21+
xhr.timeout = 3e5;
22+
if (xhrData.headers) {for (var k in xhrData.headers) {xhr.setRequestHeader(k, xhrData.headers[k]);}}
23+
xhr.onload = function(ev) {
24+
var evt = ev.target;
25+
resolve({ response: evt, body: evt.response });
26+
};
27+
xhr.onerror = reject;
28+
xhr.ontimeout = reject;
29+
xhr.send(xhrData.data);
30+
});
31+
};
32+
return util;
33+
})();
34+
var srd = (function () {
35+
var srd = function () {};
36+
srd.prototype.setValue = function (name, value) {
37+
var data = JSON.parse(localStorage.getItem('srd_data'));
38+
if (data != null) {
39+
data[name] = value;
40+
}
41+
else {
42+
data = {};
43+
data[name] = value;
44+
}
45+
localStorage.setItem('srd_data', JSON.stringify(data));
46+
};
47+
srd.prototype.getValue = function (name) {
48+
var data = JSON.parse(localStorage.getItem('srd_data'));
49+
if (data != null) {
50+
if (data.hasOwnProperty(name)) {
51+
return data[name];
52+
}
53+
else {
54+
return false;
55+
}
56+
}
57+
return false;
58+
};
59+
srd.prototype.run = function () {
60+
var _this = this;
61+
document.querySelectorAll('td[id^=postmessage_] a').forEach(async function (node) {
62+
var match;
63+
if (match = node.href.match(/\/(store\.steampowered|steamcommunity)\.com\/app\/(\d+)/)) {
64+
var res;
65+
if (res = _this.getValue(match[2])) {
66+
console.log(`名称:${res.name}\t\t\t价值:${res.award} 蒸汽`);
67+
}
68+
else {
69+
res = await util.xhr({
70+
url: `https://keylol.com/plugin.php?id=steamcn_gift:select2&type=steam&q=${match[2]}&page=1`,
71+
type: 'json'
72+
});
73+
res = res.body.items[0];
74+
_this.setValue(match[2], res);
75+
console.log(`名称:${res.name}\t\t\t价值:${res.award} 蒸汽`);
76+
}
77+
}
78+
});
79+
};
80+
return srd;
81+
})();
82+
var script = new srd();
83+
script.run();
84+
})();

0 commit comments

Comments
 (0)