Skip to content

Instantly share code, notes, and snippets.

@xingoxu
Last active August 16, 2018 03:59
Show Gist options
  • Save xingoxu/2cd507bb1b3f6101e2e230afe47c27ea to your computer and use it in GitHub Desktop.
Save xingoxu/2cd507bb1b3f6101e2e230afe47c27ea to your computer and use it in GitHub Desktop.
u2 完成种子显示做种人数
// ==UserScript==
// @name 完成种子显示做种人数
// @namespace com.xingoxu
// @version 0.1
// @author xingo
// @include /^https:\/\/u2.dmhy.org\/userdetails.php/
// @grant none
// ==/UserScript==
ajax.update = function (url, elm) {
var e = _id(elm);
var f = function (r) {
e.style.display = '';
e.innerHTML = r;
};
return new Promise(resolve => {
ajax.get(url, r => {
f(r);
resolve();
});
});
};
function getusertorrentlistajax(userid, type, blockid) {
if (document.getElementById(blockid).innerHTML == "")
return ajax.update('getusertorrentlistajax.php?userid=' + userid + '&type=' + type, blockid);
return Promise.resolve();
}
let infoGotted = false;
async function getCompletedTorrent() {
await getusertorrentlistajax('43582', 'completed', 'ka3');
if (infoGotted) return;
$('#ka3>table>tbody>tr:first-child td:nth-child(2)').after(
`<td class="colhead" align="center">
<img class="seeders" src="pic/trans.gif" alt="seeders" title="做种者">
<img class="leechers" src="pic/trans.gif" alt="leechers" title="下载者">
</td>`);
$('#ka3>table>tbody>tr:first-child>td:nth-child(n+5)').remove();
$('#ka3>table>tbody>tr:nth-child(n+2)>td:nth-child(n+5)').remove();
$('#ka3>table>tbody>tr:nth-child(n+2)').each((i, el) => {
let url = $(el).find('.torrentname a').prop('href');
// let id = new URL(url).searchParams.get('id');
ajax.get(url, body => {
body = $.parseHTML(body, null);
let text = $(body).find('#peercount').text();
let [upload, download] = text.match(/\d+/g).map(s => parseInt(s));
$(el).children('td:nth-child(3)')
.css('background-color', 'transparent')
.css('white-space', 'nowrap')
.text(`${upload} | ${download}`);
if (upload < 3) {
$(el).css('background-color', '#c1da9a');
}
})
})
}
window.getusertorrentlistajax = getusertorrentlistajax;
window.getCompletedTorrent = getCompletedTorrent;
$('#ka3').siblings('a').prop('href', `javascript: getCompletedTorrent(); klappe_news('a3');`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment