Skip to content

Commit 3ae0f1d

Browse files
committed
适配 国语视界 获取个人数据
1 parent 2690cae commit 3ae0f1d

File tree

2 files changed

+228
-0
lines changed

2 files changed

+228
-0
lines changed

resource/sites/cnlang.org/config.json

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
{
2+
"name": "国语视界",
3+
"timezoneOffset": "+0800",
4+
"schema": "Discuz",
5+
"supportedFeatures": {
6+
"search": false,
7+
"imdbSearch": false,
8+
"sendTorrent": false
9+
},
10+
"url": "https://cnlang.org/",
11+
"description": "国语视界音轨组,特效字幕组官方首发论坛,国语音轨和特效字幕的分享基地,蓝光DIY和4K电影爱好者的乐园。",
12+
"icon": "https://cnlang.org/favicon.ico",
13+
"tags": ["特效字幕", "国语音轨"],
14+
"collaborator": [
15+
"fzlins"
16+
],
17+
"host": "cnlang.org",
18+
"selectors": {
19+
"userBaseInfo": {
20+
"page": "/home.php?mod=spacecp&ac=credit",
21+
"fields": {
22+
"id": {
23+
"selector": [".vwmy a"],
24+
"attribute": "href",
25+
"filters": ["query ? query.replace(/\\D+/g, '') : '' "]
26+
},
27+
"name": {
28+
"selector": [".vwmy a"]
29+
},
30+
"messageCount": {
31+
"selector": ["a.a.showmenu.new"],
32+
"filters": ["query.text().match(/(\\d+)/)", "(query && query.length>=2)?parseInt(query[1]):0"]
33+
},
34+
"isLogged": {
35+
"selector": [
36+
"a[href*='action=logout']"
37+
],
38+
"filters": [
39+
"query.length>0"
40+
]
41+
},
42+
"bonus": {
43+
"selector": "li:contains('大洋')",
44+
"filters": [
45+
"query.text().match(/大洋.*?([\\d.]+)/)[1]",
46+
"parseFloat(query)"
47+
]
48+
}
49+
}
50+
},
51+
"userExtendInfo": {
52+
"page": "/home.php?mod=spacecp&ac=plugin&id=bt_magnet:action",
53+
"fields": {
54+
"uploaded": {
55+
"selector": ".attach_magnet_div p:contains('上传量')",
56+
"filters": [
57+
"query.text().replace('上传量:', '').trim().sizeToNumber()"
58+
]
59+
},
60+
"downloaded": {
61+
"selector": ".attach_magnet_div p:contains('下载量')",
62+
"filters": [
63+
"query.text().replace('下载量:', '').trim().sizeToNumber()"
64+
]
65+
},
66+
"ratio": {
67+
"selector": ".attach_magnet_div p:contains('分享率:')",
68+
"filters": [
69+
"query.text().replace('分享率:', '').replace(/,/g,'').trim()",
70+
"parseFloat(query)"
71+
]
72+
},
73+
"levelName": {
74+
"selector": ["a[href='home.php?mod=spacecp&ac=usergroup']:first"],
75+
"filters": ["query.text().replace('用户组: ', '').trim()"]
76+
},
77+
"joinTime": {
78+
"selector": ".attach_magnet_div p:contains('加入时间:')",
79+
"filters": [
80+
"query.text().replace('加入时间:', '').trim()",
81+
"dateTime(query).isValid()?dateTime(query).valueOf():query"
82+
]
83+
}
84+
}
85+
},
86+
"userSeedingTorrents": {
87+
"prerequisites": "!user.seeding",
88+
"page": "/home.php?mod=spacecp&ac=plugin&id=bt_magnet:action&subop=seeding",
89+
"parser": "getUserSeedingTorrents.js",
90+
"fields": {
91+
"seeding": {
92+
"selector": [".mn tr:not(:eq(0))"],
93+
"filters": ["query.length"]
94+
},
95+
"seedingSize": {
96+
"selector": [".mn tr:not(:eq(0))"],
97+
"filters": ["jQuery.map(query.find('td:eq(1)'), (item)=>{return $(item).text();})", "_self.getTotalSize(query)"]
98+
}
99+
}
100+
}
101+
}
102+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
if ("".getQueryString === undefined) {
2+
String.prototype.getQueryString = function(name, split) {
3+
if (split == undefined) split = "&";
4+
var reg = new RegExp(
5+
"(^|" + split + "|\\?)" + name + "=([^" + split + "]*)(" + split + "|$)"
6+
),
7+
r;
8+
if ((r = this.match(reg))) return decodeURI(r[2]);
9+
return null;
10+
};
11+
}
12+
13+
(function(options, User) {
14+
class Parser {
15+
constructor(options, dataURL) {
16+
this.options = options;
17+
this.dataURL = dataURL;
18+
this.body = null;
19+
this.rawData = "";
20+
this.pageInfo = {
21+
count: 0,
22+
current: 1
23+
};
24+
this.result = {
25+
seeding: 0,
26+
seedingSize: 0
27+
};
28+
this.load();
29+
}
30+
31+
/**
32+
* 完成
33+
*/
34+
done() {
35+
this.options.resolve(this.result);
36+
}
37+
38+
/**
39+
* 解析内容
40+
*/
41+
parse() {
42+
const doc = new DOMParser().parseFromString(this.rawData, "text/html");
43+
// 构造 jQuery 对象
44+
this.body = $(doc).find("body");
45+
46+
this.getPageInfo();
47+
48+
let results = new User.InfoParser(User.service).getResult(
49+
this.body,
50+
this.options.rule
51+
);
52+
53+
if (results) {
54+
this.result.seeding += results.seeding;
55+
this.result.seedingSize += results.seedingSize;
56+
}
57+
58+
// 是否已到最后一页
59+
if (this.pageInfo.current < this.pageInfo.count) {
60+
this.pageInfo.current++;
61+
this.load();
62+
} else {
63+
this.done();
64+
}
65+
}
66+
67+
/**
68+
* 获取页面相关内容
69+
*/
70+
getPageInfo() {
71+
if (this.pageInfo.count > 0) {
72+
return;
73+
}
74+
// 获取最大页码
75+
const infos = this.body
76+
.find("input[name='custompage']")
77+
.attr("size");
78+
if (infos) {
79+
this.pageInfo.count = parseInt(infos);
80+
} else {
81+
this.pageInfo.count = 1;
82+
}
83+
}
84+
85+
/**
86+
* 加载当前页内容
87+
*/
88+
load() {
89+
let url = this.dataURL;
90+
if (this.pageInfo.current > 0) {
91+
url += "&page=" + this.pageInfo.current;
92+
}
93+
$.get(url)
94+
.done(result => {
95+
this.rawData = result;
96+
this.parse();
97+
})
98+
.fail(() => {
99+
this.done();
100+
});
101+
}
102+
}
103+
104+
let dataURL = options.site.activeURL + options.rule.page;
105+
dataURL = dataURL
106+
.replace("$user.id$", options.userInfo.id)
107+
.replace("$user.name$", options.userInfo.name)
108+
.replace("://", "****")
109+
.replace(/\/\//g, "/")
110+
.replace("****", "://");
111+
112+
new Parser(options, dataURL);
113+
})(_options, _self);
114+
/**
115+
*
116+
_options 表示当前参数
117+
{
118+
site,
119+
rule,
120+
userInfo,
121+
resolve,
122+
reject
123+
}
124+
125+
_self 表示 User(/src/background/user.ts) 类实例
126+
*/

0 commit comments

Comments
 (0)