// ==UserScript==
// @name U2种子历史记录
// @namespace https://u2.dmhy.org/
// @version 0.0.6
// @description 查看种子历史记录
// @author kysdm
// @grant none
// @match *://u2.dmhy.org/details.php?id=*
// @match *://u2.dmhy.org/offers.php?id=*
// @icon https://u2.dmhy.org/favicon.ico
// @require https://cdn.jsdelivr.net/npm/localforage@1.9.0/dist/localforage.min.js
// @license Apache-2.0
// @downloadURL none
// ==/UserScript==
/*
本脚本基于 Bamboo Green 界面风格进行修改
/*
/*
更新日志
https://github.com/kysdm/u2_share/commits/main/u2share_torrents_history.user.js
*/
// 声明全局变量
var lang, torrent_id, db, user_id, key, token;
(async () => {
'use strict';
// 初始化
lang = new lang_init($('#locale_selection').val()); // 获取当前网页语言
torrent_id = location.href.match(/\.php\?id=(\d{3,5})/i) || ['', '']; if (torrent_id[1] !== '') torrent_id = torrent_id[1]; // 当前种子ID
user_id = $('#info_block').find('a:first').attr('href').match(/\.php\?id=(\d{3,5})/i) || ['', '']; if (user_id[1] !== '') user_id = user_id[1]; // 当前用户ID
db = localforage.createInstance({ name: "history" });
key = await db.getItem('key');
token = await db.getItem('token');
if (key === null || key.length !== 32) { new auth_key(); return; } else if (token === null || token.length !== 96) { new auth_token(key); return; };
// 为已经删除的种子显示历史
if ($('#outer').find('h2').text().match(/错误|錯誤|Ошибка|error/i)) { history2(); } else { history1(); };
})();
function auth_key() {
'use strict';
$('#outer').html('
U2种子历史记录 KEY初始化
'
+ ''
+ '点击按钮,请求key,key需写在个人说明中,'
+ '填写完成请刷新界面。
|
'
+ ''
+ '32位长度的key会显示在这里 (不是32位就是失败) |
'
+ ''
+ ''
+ ' |
'
);
$("#auth_key_d").click(function () {
let __key = window.prompt("请输入key"); // 弹窗提示输入key
if (__key === null || __key.length === 0) return; // 没有任何输入时 无视本次操作
$('#auth_value').text(__key);
db.setItem('key', __key);
});
$("#auth_key").click(function () {
$.ajax({
type: 'post',
url: 'https://u2.kysdm.com/api/v1/token',
contentType: "application/json",
dataType: 'json',
data: JSON.stringify({ "uid": user_id }),
success: function (d) {
if (d.msg === 'success') {
let __key = d.data.key
$('#auth_value').text(__key);
db.setItem('key', __key);
} else {
$('#auth_value').text(d);
};
},
error: function (d) {
$('#auth_value').text(d);
},
});
});
};
function auth_token(__key) {
'use strict';
$('#outer').html('U2种子历史记录 TOKEN初始化
'
+ ''
+ '点击按钮,请求token,token会自动记录在本地数据库中,完成后请刷新界面。
|
'
+ ''
+ '96位长度的token会显示在这里 (不是96位就是失败) |
'
+ ''
+ ''
+ ' |
'
);
$("#auth_token_d").click(function () {
let __token = window.prompt("请输入token"); // 弹窗提示输入token
if (__token === null || __token.length === 0) return; // 没有任何输入时 无视本次操作
$('#auth_value').text(__token);
db.setItem('token', __token);
});
$("#auth_token").click(async function () {
$.ajax({
type: 'post',
url: 'https://u2.kysdm.com/api/v1/token',
contentType: "application/json",
dataType: 'json',
data: JSON.stringify({ "uid": user_id, "key": __key }),
success: function (d) {
if (d.msg === 'success') {
let __token = d.data.token
$('#auth_value').text(__token);
db.setItem('token', __token);
} else {
$('#auth_value').html('可能没有把key写入个人说明
key: ' + __key + '
错误信息: ' + JSON.stringify(d));
};
},
error: function (d) {
$('#auth_value').text(d);
},
});
});
};
async function history1() {
'use strict';
if ($('h3').length === 1) { // 插入 select 基本框架
const right = ($('#outer').width() - $('h3').next().width()) / 2 + 5; // 计算偏移量
$('#top').after('');
$(window).resize(function () { $('#history').css("right", ($('#outer').width() - $('h3').next().width()) / 2 + 5); });
} else {
const right = ($('#outer').width() - $('#top').next().width()) / 2 + 5; // 计算偏移量
$('#top').after('');
$(window).resize(function () { $('#history').css("margin-right", ($('#outer').width() - $('#history').next().width()) / 2 + 5 + 'px'); });
};
$("#history_select").append("");
const __json = await getapi(); // 从 API 获取数据
if (__json.msg !== 'success') { // 加载失败时
console.log('获取历史记录失败.');
$("#history_select").empty(); // 插入前先清空 option
$("#history_select").append(''); // 希望你不要看到这个 (ノДT)
return;
};
console.log('获取历史记录成功.');
let history_data = __json.data.history;
var now_data = {
self: 0, // 唯一标识符
title: $('#top').text(), // 主标题
subtitle: $("td[class='rowhead nowrap']:contains(" + lang['subtitle'] + ")").next().html(), // 副标题
uploaded: $("td[class='rowhead nowrap']:contains(" + lang['uploaded'] + ")").next().html(), // 发布人
basic_info: $("td[class='rowhead nowrap']:contains(" + lang['basic_info'] + ")").next().html(), // 基本信息
description_info: $('#kdescr').html(), // 描述
get_time: getDateString(), // 数据获取时间 这里是当前时间
};
history_data = [now_data].concat(history_data); // 将现在的页面保存,并插入到数列第一位
$("#history_select").empty(); // 插入前先清空 option
for (let i = 0, len = history_data.length; i < len; i++) { // 循环插入到选择列表中
$("#history_select").append("");
};
// 草 为什么会这样呢 明明原来很整齐的
$("#history_select").change(function () { // 监听菜单选择
let self = Number($(this).val());
for (let i = 0, len = history_data.length; i < len; i++) {
if (self !== history_data[i].self) continue;
if (self === 0) { // 还原现在的页面
$('#top').text(history_data[i].title); // 主标题
$("td[class='rowhead nowrap']:contains(" + lang['subtitle'] + ")").next().html(history_data[i].subtitle); // 副标题
$("td[class='rowhead nowrap']:contains(" + lang['uploaded'] + ")").next().html(history_data[i].uploaded); // 发布人一栏
$("td[class='rowhead nowrap']:contains(" + lang['basic_info'] + ")").next().html(history_data[i].basic_info); // 基本信息一栏
$('#kdescr').html(history_data[i].description_info); // 描述
return;
}
$('#top').text(history_data[i].title); // 主标题
$("td[class='rowhead nowrap']:contains(" + lang['subtitle'] + ")").next().text(history_data[i].subtitle); // 副标题
$("td[class='rowhead nowrap']:contains(" + lang['description'] + ")").last().next().html('' + bbcode2html(history_data[i].description_info) + ''); // 描述
if ($('h3').length === 1) { // 已经通过候选的种子
$("td[class='rowhead nowrap']:contains(" + lang['uploaded'] + ")").next().html(((p) => {
if (p.uploader_id === null && p.uploader_name === '匿名') return '' + lang['anonymous'] + ''; // 匿名发布
if (p.uploader_id === null && p.uploader_name !== '匿名') return p.uploader_name; // 自定义署名 不带UID
if (p.uploader_id !== null && p.uploader_name !== '匿名') return '' + p.uploader_name + ''; // 正常显示 || 自定义署名 带UID
})(history_data[i])); // 发布人
$("td[class='rowhead nowrap']:contains(" + lang['basic_info'] + ")").next().html('' + lang['uploaded_at'] + ': ' + history_data[i].uploaded_at.replace('T', ' ')
+ (() => { if (history_data[i].torrent_size) { return ' ' + lang['size'] + ': ' + convert(history_data[i].torrent_size) } else { return ''; } })()
+ ' ' + lang['category'] + ': ' + history_data[i].category)
} else { // 还在候选的种子
$("td[class='rowhead nowrap']:contains(" + lang['basic_info'] + ")").next().html('' + lang['submitted_by'] + ': '
+ ((p) => {
if (p.uploader_id === null && p.uploader_name === '匿名') return '' + lang['anonymous'] + ''; // 匿名发布
if (p.uploader_id !== null && p.uploader_name !== '匿名') return '' + p.uploader_name + ''; // 正常显示
})(history_data[i])
+ ' ' + lang['submitted_at'] + ': ' + lang['category'] + ': '
+ history_data[i].category
);
};
};
});
};
async function history2() {
'use strict';
const errorstr = $('#outer').find('td.text').text();
// 正在努力加载中...
$('#outer').find('td.text').html(errorstr + ' ' + lang['history_text_loading'] + '');
const __json = await getapi(); // 从 API 获取数据
if (__json.msg !== 'success') { // 加载失败时
console.log('获取历史记录失败.');
$('#outer').find('td.text').html(errorstr + ' ' + lang['history_text_error'] + '');
return;
} else if (__json.data.history.length === 0) { // 获取成功 但没有历史记录时
console.log('没有历史记录.');
$('#outer').find('td.text').html(errorstr + ' ' + lang['history_text_empty'] + '');
return;
};
console.log('获取历史记录成功.');
let history_data = __json.data.history;
// 还原网页
$('#outer').html('' + history_data[0].title + '
'
+ ''
+ '(#' + torrent_id + ')
'
+ '' + lang['torrent_title'] + ' | '
+ ''
+ '[U2].' + history_data[0].torrent_name + '.torrent |
'
+ '' + lang['subtitle'] + ' | '
+ ''
+ (() => { if (history_data[0].subtitle) { return history_data[0].subtitle } else { return ''; } })()
+ ' |
'
+ '' + lang['basic_info'] + ' | '
+ '' + lang['submitted_by'] + ': '
+ ((p) => {
if (p.uploader_id === null && p.uploader_name === '匿名') return '' + lang['anonymous'] + ''; // 匿名发布
if (p.uploader_id !== null && p.uploader_name !== '匿名') return '' + p.uploader_name + ''; // 正常显示
})(history_data[0])
+ ' ' + lang['submitted_at'] + ': '
+ (() => { if (history_data[0].torrent_size) { return ' 大小: ' + convert(history_data[0].torrent_size) } else { return ''; } })()
+ ' ' + lang['category'] + ': ' + history_data[0].category
+ ' |
'
+ ''
+ ''
+ ' ' + lang['description'] + ' | '
+ ''
+ ' '
+ bbcode2html(history_data[0].description_info) + ' |
'
+ '' + lang['torrent_info'] + ' | '
+ ''
+ '' + lang['files'] + ': ' + history_data[0].torrent_files_qty
+ '
| ' + lang['info_hash'] + ': ' + history_data[0].torrent_hash
+ ' |
|
'
);
for (let i = 0, len = history_data.length; i < len; i++) { // 循环插入到选择列表中
$("#history_select").append("");
};
$("#history_select").change(function () { // 监听菜单选择
let self = Number($(this).val());
for (let i = 0, len = history_data.length; i < len; i++) {
if (self !== history_data[i].self) continue;
$('#top').text(history_data[i].title); // 主标题
$("td[class='rowhead nowrap']:contains(" + lang['subtitle'] + ")").next().text(history_data[i].subtitle); // 副标题
$("td[class='rowhead nowrap']:contains(" + lang['description'] + ")").last().next().html('' + bbcode2html(history_data[i].description_info) + ''); // 描述
$("td[class='rowhead nowrap']:contains(" + lang['basic_info'] + ")").next().html('' + lang['submitted_by'] + ': '
+ ((p) => {
if (p.uploader_id === null && p.uploader_name === '匿名') return '' + lang['anonymous'] + ''; // 匿名发布
if (p.uploader_id !== null && p.uploader_name !== '匿名') return '' + p.uploader_name + ''; // 正常显示
})(history_data[i])
+ ' ' + lang['submitted_at'] + ': '
+ (() => { if (history_data[i].torrent_size) { return ' ' + lang['size'] + ': ' + convert(history_data[i].torrent_size) } else { return ''; } })()
+ ' ' + lang['category'] + ': ' + history_data[i].category
);
};
});
};
function bbcode2html(bbcodestr) {
'use strict';
const f_reg = new RegExp("^\"?\"?$");
var tempCode = new Array();
var tempCodeCount = 0;
function addTempCode(value) {
tempCode[tempCodeCount] = value;
let returnstr = "";
tempCodeCount++;
return returnstr;
}
const escape_reg = new RegExp("[&\"\'<>]", "g");
bbcodestr = bbcodestr.replace(escape_reg, function (s, x) {
switch (s) {
case '&':
return '&';
case '"':
return '"';
case "'":
return ''';
case '<':
return '<';
case '>':
return '>';
default:
return s;
}
});
bbcodestr = bbcodestr.replace(/\r\n/g, () => { return '
' });
bbcodestr = bbcodestr.replace(/\n/g, () => { return '
' });
bbcodestr = bbcodestr.replace(/\r/g, () => { return '
' });
// code 标签
const code_reg = new RegExp("\\[code\\](.+?)\\[\\/code\\]", "gis");
bbcodestr = bbcodestr.replace(code_reg, function (s, x) {
return addTempCode('
' + lang['code'] + '
' + x + '
');
});
// info 标签
const info_reg = new RegExp("\\[(mediainfo|info)\\](.+?)\\[\\/(\\1)\\]", "gis");
bbcodestr = bbcodestr.replace(info_reg, function (s, x, y) {
switch (x) {
case 'info':
return addTempCode('');
case 'mediainfo':
return addTempCode('');
default:
return s;
}
});
// 超链接
bbcodestr = bbcodestr.replace(/\[url=((?:https?|ftp|gopher|news|telnet|mms|rtsp):\/\/((?!<|>|\s|"|>|'|<|\(|\)|\[|\]).)+)\](.+?)\[\/url\]/gis, function (s, x, y, z) {
return addTempCode('' + z + '');
});
bbcodestr = bbcodestr.replace(/\[url\]((?:https?|ftp|gopher|news|telnet|mms|rtsp):\/\/((?!<|>|\s|"|>|'|<|\(|\)|\[|\]).)+)\[\/url\]/gis, function (s, x) {
return addTempCode('' + x + '')
});
// 单个标签 不带参
const o_reg = new RegExp("\\[(\\*|siteurl|site)\\]", "gi");
bbcodestr = bbcodestr.replace(o_reg, function (s, x, y) {
switch (x) {
case '*':
return '
';
case 'site':
return 'U2分享園@動漫花園';
case 'siteurl':
return 'https://u2.dmhy.org';
default:
return s;
}
});
// 成对标签 带参
const d_reg = new RegExp("\\[(rt|font)=([^\\]]+)\\](.*?)\\[(/\\1)\\]", "gis");
while (d_reg.test(bbcodestr)) {
bbcodestr = bbcodestr.replace(d_reg, function (s, w, x, y, z) {
switch (w) {
case 'rt':
if (f_reg.test(x)) {
return '[' + addTempCode('p3F#oW2@cEn_JHstp-&37DgD' + w) + '=' + x + ']'
+ y + '[' + addTempCode('p3F#oW2@cEn_JHstp-&37DgD' + z) + ']'
}
else {
return addTempCode('' + y + '');
}
case 'font':
if (f_reg.test(x)) {
return '[' + addTempCode('p3F#oW2@cEn_JHstp-&37DgD' + w) + '=' + x + ']'
+ y + '[' + addTempCode('p3F#oW2@cEn_JHstp-&37DgD' + z) + ']';
}
else {
return '' + y + '';
}
default:
return s;
}
})
};
// 成对标签 不带参
const a_reg = new RegExp("\\[(pre|b|i|u|s)\\](.*?)\\[/(\\1)\\]", "gs");
while (a_reg.test(bbcodestr)) {
bbcodestr = bbcodestr.replace(a_reg, function (s, x, y, z) {
switch (x) {
case 'b':
return '' + y + '';
case 'i':
return '' + y + '';
case 'u':
return '' + y + '';
case 's':
return '' + y + '';
case 'pre':
return '' + y + '
';
default:
return s;
}
})
};
// 颜色
const color_reg = new RegExp("\\[color=(?:")?([#0-9a-z]{1,15}|[a-z]+?)(?:")?\\](.*?)\\[/color\\]", "gis");
while (color_reg.test(bbcodestr)) {
bbcodestr = bbcodestr.replace(color_reg, function (s, x, y) {
return '' + y + '';
})
};
// 文字大小
const size_reg = new RegExp("\\[size=(?:")?([1-7])(?:")?\\](.*?)\\[/size\\]", "gis");
while (size_reg.test(bbcodestr)) {
bbcodestr = bbcodestr.replace(size_reg, function (s, x, y) {
return '' + y + '';
})
};
// 图片
bbcodestr = bbcodestr.replace(/\[(img|imglnk)\]([^\]]+)\[\/(?:\1)\]/gi, function (s, x, y) {
if (/^https?:\/\/((?!<|>|"|>|'|<|;|\(|\)|\[|\]).)+$/i.test(y)) {
switch (x) {
case 'img':
return addTempCode('
');
case 'imglnk':
return addTempCode('
');
}
} else {
return addTempCode(s);
}
});
bbcodestr = bbcodestr.replace(/\[img=([^\]]+)\]/gi, function (s, x) {
if (/^https?:\/\/((?!<|>|"|>|'|<|;|\(|\)|\[|\]).)+$/i.test(x)) {
return addTempCode('
');
} else {
return addTempCode(s);
}
});
// 没有bbcode包裹的超链接
bbcodestr = bbcodestr.replace(/((?:https?|ftp|gopher|news|telnet|mms|rtsp):\/\/((?!<|>|\s|"|>|'|<|\(|\)|\[|\]).)+)/gi, function (s, x) {
return '' + s + '';
});
// 引用
const quote_reg1 = new RegExp("\\[quote\\](.*?)\\[/quote\\]", "gsi");
while (quote_reg1.test(bbcodestr)) {
bbcodestr = bbcodestr.replace(quote_reg1, function (s, x) {
return '';
});
};
const quote_reg2 = new RegExp("\\[quote=([^\\[\\]]*)\\](.*?)\\[/quote\\]", "gsi");
while (quote_reg2.test(bbcodestr)) {
bbcodestr = bbcodestr.replace(quote_reg2, function (s, x, y) {
if (f_reg.test(x)) {
return '';
}
else {
return '';
}
});
};
// spoiler
const spoiler_reg1 = new RegExp("\\[spoiler\\](.*?)\\[/spoiler\\]", "gsi");
const spoiler_reg2 = new RegExp("\\[spoiler=([^\\]]+)\\\](.*?)\\[/spoiler\\]", "gsi");
while (spoiler_reg1.test(bbcodestr)) {
bbcodestr = bbcodestr.replace(spoiler_reg1, function (s, x) {
return ''
+ lang['spoiler'] + ' '
+ ''
+ ''
+ ' |
'
+ x + ' |
';
});
};
while (spoiler_reg2.test(bbcodestr)) {
bbcodestr = bbcodestr.replace(spoiler_reg2, function (s, x, y) {
if (f_reg.test(x)) {
return ''
+ lang['spoiler'] + ' '
+ ''
+ ''
+ ' |
'
+ y + ' |
';
}
else {
return ''
+ x.replace(/^(?:")?(.*?)(?:")?$/, "$1") + ' '
+ ''
+ ''
+ ' |
'
+ y + ' |
';
}
});
};
// 表情
const em_reg = new RegExp("\\[(em[1-9][0-9]*)\\]", "gi");
bbcodestr = bbcodestr.replace(em_reg, function (s, x) {
switch (x) {
case (x.match(/^em[1-9][0-9]*/i) || {}).input:
return '
';
default:
return s;
}
})
for (let i = 0, len = tempCode.length; i < len; i++) {
// console.log(i + " : " + tempCode[i]);
bbcodestr = bbcodestr.replace("", tempCode[i]);
}
bbcodestr = bbcodestr.replace(/p3F#oW2@cEn_JHstp-&37DgD/g, "");
if (/(
)$/.test(bbcodestr)) { bbcodestr = bbcodestr + '
' };
var htmlobj = $.parseHTML('' + bbcodestr + '
');
$(htmlobj).children('fieldset').children('fieldset').children('fieldset').children('fieldset').each(function () {
$(this).html($(this).html().replace(/(^