Skip to content

Commit

Permalink
Merge pull request #5 from ronggang/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Bright-W committed Apr 16, 2022
2 parents 311d06e + 2fa9854 commit 9e68e0d
Show file tree
Hide file tree
Showing 4 changed files with 364 additions and 247 deletions.
34 changes: 18 additions & 16 deletions resource/sites/www.skyey2.com/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"tags": ["动漫"],
"collaborator": [
"栽培者",
"MewX"
"MewX",
"fzlins"
],
"host": "www.skyey2.com",
"selectors": {
Expand Down Expand Up @@ -53,20 +54,6 @@
"(query && query.length>=2) ? query[1].trim() : 0"
]
},
"seeding": {
"selector": "#psts li:contains('做种数估计')",
"filters": [
"query.text().replace('做种数估计', '').replace(/,/g,'').trim()",
"parseFloat(query)"
]
},
"seedingSize": {
"selector": "#psts li:contains('实际保种')",
"filters": [
"query.text().match(/实际保种.+?\\/\\s*([\\d\\.]+\\s*[ZEPTGMK])/)",
"(query && query.length>=2) ? (query[1].trim()).sizeToNumber() : 0"
]
},
"levelName": {
"selector": "a[href='home.php?mod=spacecp&ac=usergroup']",
"filters": ["query.text().replace('用户组: ', '').trim()"]
Expand All @@ -86,7 +73,22 @@
]
}
}
}
},
"userSeedingTorrents": {
"prerequisites": "!user.seeding",
"page": "/forum.php?&mod=torrents&cat_5up=on",
"parser": "getUserSeedingTorrents.js",
"fields": {
"seeding": {
"selector": ["table.torrents > tbody > tr:not(:eq(0))"],
"filters": ["query.length"]
},
"seedingSize": {
"selector": ["table.torrents > tbody > tr:not(:eq(0))"],
"filters": ["jQuery.map(query.find('td.rowfollow:eq(3)'), (item)=>{return $(item).text();})", "_self.getTotalSize(query)"]
}
}
}
},
"supportedFeatures": {
"imdbSearch": false
Expand Down
126 changes: 126 additions & 0 deletions resource/sites/www.skyey2.com/getUserSeedingTorrents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
if ("".getQueryString === undefined) {
String.prototype.getQueryString = function(name, split) {
if (split == undefined) split = "&";
var reg = new RegExp(
"(^|" + split + "|\\?)" + name + "=([^" + split + "]*)(" + split + "|$)"
),
r;
if ((r = this.match(reg))) return decodeURI(r[2]);
return null;
};
}

(function(options, User) {
class Parser {
constructor(options, dataURL) {
this.options = options;
this.dataURL = dataURL;
this.body = null;
this.rawData = "";
this.pageInfo = {
count: 0,
current: 0
};
this.result = {
seeding: 0,
seedingSize: 0
};
this.load();
}

/**
* 完成
*/
done() {
this.options.resolve(this.result);
}

/**
* 解析内容
*/
parse() {
const doc = new DOMParser().parseFromString(this.rawData, "text/html");
// 构造 jQuery 对象
this.body = $(doc).find("body");

this.getPageInfo();

let results = new User.InfoParser(User.service).getResult(
this.body,
this.options.rule
);

if (results) {
this.result.seeding += results.seeding;
this.result.seedingSize += results.seedingSize;
}

// 是否已到最后一页
if (this.pageInfo.current < this.pageInfo.count) {
this.pageInfo.current++;
this.load();
} else {
this.done();
}
}

/**
* 获取页面相关内容
*/
getPageInfo() {
if (this.pageInfo.count > 0) {
return;
}
// 获取最大页码
const infos = this.body
.find("table.torrents > tbody > tr:eq(0) td:eq(1)")
.text();
if (infos) {
this.pageInfo.count = parseInt(infos.split('/')[1] / 50);
} else {
this.pageInfo.count = 0;
}
}

/**
* 加载当前页内容
*/
load() {
let url = this.dataURL;
if (this.pageInfo.current > 0) {
url += "&page=" + this.pageInfo.current;
}
$.get(url)
.done(result => {
this.rawData = result;
this.parse();
})
.fail(() => {
this.done();
});
}
}

let dataURL = options.site.activeURL + options.rule.page;
dataURL = dataURL
.replace("$user.id$", options.userInfo.id)
.replace("$user.name$", options.userInfo.name)
.replace("://", "****")
.replace(/\/\//g, "/")
.replace("****", "://");

new Parser(options, dataURL);
})(_options, _self);
/**
*
_options 表示当前参数
{
site,
rule,
userInfo,
resolve,
reject
}
_self 表示 User(/src/background/user.ts) 类实例
*/
3 changes: 2 additions & 1 deletion src/options/components/SearchBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<v-text-field
flat
solo-inverted
:prepend-icon="$vuetify.breakpoint.smAndUp ? 'search' : ''"
prepend-icon="search"
@click:prepend="searchTorrent()"
:label="$t('searchBox.searchTip')"
class="mt-2 mb-0"
v-model="searchKey"
Expand Down
Loading

0 comments on commit 9e68e0d

Please sign in to comment.