// ==UserScript== // @name U2历史记录 // @namespace https://u2.dmhy.org/ // @version 0.3.3 // @description 查看种子历史记录 // @author kysdm // @grant none // @match *://u2.dmhy.org/details.php?id=* // @match *://u2.dmhy.org/offers.php?id=* // @match *://u2.dmhy.org/forums.php?action=viewtopic* // @icon https://u2.dmhy.org/favicon.ico // @require https://cdnjs.cloudflare.com/ajax/libs/localforage/1.10.0/localforage.min.js // @require https://unpkg.com/thenby@1.3.4/thenBy.min.js // @license Apache-2.0 // @downloadURL none // ==/UserScript== /* 本脚本基于 Bamboo Green 界面风格进行修改 /* /* GreasyFork 地址 https://greasyfork.org/zh-CN/scripts/428545 */ /* 使用说明 https://u2.dmhy.org/forums.php?action=viewtopic&topicid=13495&page=p150133#pid150133 */ /* 更新日志 https://github.com/kysdm/u2_share/commits/main/u2share_history.user.js */ // 声明全局变量 var lang, torrent_id, db, user_id, topicid, 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 topicid = location.href.match(/topicid=(\d+)/i) || ['', '']; if (topicid[1] !== '') topicid = topicid[1]; 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 (token === null || token.length !== 96) { new auth(key); return; }; if (/\/(offers|details)\.php\?id=\d{3,5}/i.test(location.href) && $('#outer').find('h2').text().match(/错误|錯誤|Ошибка|error/i)) { torrentInfoHistoryReset(); torrentCommentHistoryReset(); }// 为已经删除的种子显示历史 else if (/\/(offers|details)\.php\?id=\d{3,5}/i.test(location.href) && !/(cmtpage|offer_vote|vote)=(1|p)/i.test(location.href)) { torrentInfoHistory(); torrentCommentHistory(); } // 为正常种子显示历史 else if (/\/(offers|details)\.php\?id=\d{3,5}/i.test(location.href) && /cmtpage=1/i.test(location.href)) { torrentCommentHistory(); } // 为正常种子显示历史 <仅评论> else if (/\/forums\.php\?action=viewtopic/i.test(location.href) && $('#outer').find('h2').text().match(/错误|錯誤|Ошибка|error/i)) { forumCommentHistoryReset(); } // 为被删除的论坛帖子显示历史 else if (/\/forums\.php\?action=viewtopic/i.test(location.href)) { forumCommentHistory(); }; // 为论坛帖子显示历史 })(); function auth() { 'use strict'; $('#outer').html(`

U2种子历史记录 自动鉴权工具

点击开始按钮,将自动进行鉴权,提示完成请刷新界面。
(建议手动备份下个人说明)
`); $("#auth_token_d").click(async function () { let __token = window.prompt("请输入Token"); // 弹窗提示输入Token if (__token === null || __token.length === 0) return; // 没有任何输入时 无视本次操作 else if (__token.length !== 96) { await outPutLog(`Token: ${__token}`); await outPutLog(`Token长度不正确`); return; } // TOKEN长度不正确时 无视本次操作 else { await db.setItem('token', __token); await outPutLog(`Token: ${__token}`); await outPutLog('鉴权结束'); }; }); function getProfile() { return new Promise(async (resolve, reject) => { $.ajax({ type: 'get', url: 'https://u2.dmhy.org/usercp.php?action=personal', cache: false, success: async r => { const usercp = $.parseHTML(r) // const profile = $(usercp).find('[name="info"]').text(); // 获取用户信息 const profile = { "action": "personal", "type": "save", "acceptpms": $(usercp).find('[name="acceptpms"]:checked').val(), // 接受以下短讯 // 如果不需要开启对应功能,则不发送该参数 "deletepms": $(usercp).find('[name="deletepms"]').is(':checked') ? 'on' : '', // 回复后删除短讯 "savepms": $(usercp).find('[name="savepms"]').is(':checked') ? 'on' : '', // 保存短讯至发件箱 "commentpm": $(usercp).find('[name="commentpm"]').is(':checked') ? 'yes' : '', // 我发布的种子有新评论时通知我 "atpm": $(usercp).find('[name="atpm"]').is(':checked') ? '1' : '',// 有人在群聊区@我时通知 "quotepm": $(usercp).find('[name="quotepm"]').is(':checked') ? '1' : '',// 有人在论坛、种子评论或候选评论引用我时通知。 // 如果不需要开启对应功能,则不发送该参数 "country": $(usercp).find('[name="country"]').val(), // 国家/地区 "download": $(usercp).find('[name="download"]').val(),// 下行带宽 "upload": $(usercp).find('[name="upload"]').val(),// 上行带宽 "isp": $(usercp).find('[name="isp"]').val(),// 互联网服务提供商 "savatar": $(usercp).find('[name="savatar"]').val(), // 选择头像 "avatar": $(usercp).find('[name="avatar"]').val(), // 自定义头像 "info": $(usercp).find('[name="info"]').text() // 个人说明 }; let profileAuth = { ...profile }; // 复制 profileAuth.info = `-----BEGIN API KEY-----\n${key}\n-----END API KEY-----\n\n${profile.info}`; // 在个人说明加入鉴权信息 const p = profileAuth.info.replace(/\r\n/g, () => { return '
' }).replace(/\n/g, () => { return '
' }).replace(/\r/g, () => { return '
' }); await outPutLog(`请检查准备写入个人说明的BBCODE是否正确

个人说明  
`); await db.setItem('profile', profile); // 存储用户信息 $("#auth_profile_check").click(async function (ev) { $(this).hide(); $(this).siblings(".spoiler-button-show").show(); $(this).parentsUntil(".spoiler").find("span.spoiler-content:first").hide(); ev.preventDefault(); return resolve(profileAuth); }); }, error: async d => { await outPutLog('获取个人说明BBCODE失败'); await outPutLog(`错误信息: ${d.responseText}`); return reject(Error(d.responseText)); }, }); }); }; function postProfile(data) { return new Promise(async (resolve, reject) => { $.ajax({ type: 'post', url: 'https://u2.dmhy.org/usercp.php', cache: false, contentType: "application/x-www-form-urlencoded", data: data, success: async r => { await outPutLog('修改个人说明BBCODE成功'); return resolve(key); }, error: async d => { await outPutLog('修改个人说明BBCODE失败'); await outPutLog(`错误信息: ${d.responseText}`); return reject(Error(d.responseText)); }, }); }); }; function getAuthKey() { return new Promise(async (resolve, reject) => { $.ajax({ type: 'post', url: 'https://u2.kysdm.com/api/v1/token', contentType: "application/json", dataType: 'json', // async: false, data: JSON.stringify({ "uid": user_id }), success: async function (d) { if (d.msg === 'success') { key = d.data.key db.setItem('key', key); await outPutLog('获取Key成功'); await outPutLog(`Key: ${key}`); return resolve(key); } else { await outPutLog('获取Key失败'); await outPutLog(`错误信息: ${JSON.stringify(d)}`); return reject(Error('获取Key失败')); }; }, error: async function (d) { await outPutLog('获取Key失败'); await outPutLog(`错误信息: ${d.responseText}`); return reject(Error('获取Key失败')); }, }); }); }; function getToken() { return new Promise(async (resolve, reject) => { $.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: async function (d) { if (d.msg === 'success') { let __token = d.data.token await outPutLog('获取Token成功'); await outPutLog(`Token: ${__token}`); await db.setItem('token', __token); return resolve(__token); } else { await outPutLog('获取Token失败'); await outPutLog(`错误信息: ${JSON.stringify(d)}`); return reject(Error('获取Token失败')); }; }, error: async function (d) { await outPutLog('获取Token失败'); await outPutLog(`错误信息: ${d.responseText}`); return reject(Error('获取Token失败')); }, }); }); }; function outPutLog(text) { return new Promise(async (resolve, reject) => { const log = $('#auth_log').html(); $('#auth_log').html(`${log}${getDateString()} - ${text}
`); resolve(await sleep(0)); }); }; async function sleep(interval) { return new Promise(resolve => { setTimeout(resolve, interval); }) }; $("#auth_token").click(async function () { await outPutLog('鉴权开始'); await outPutLog('获取鉴权所需的Key'); getAuthKey() .then(async () => { await outPutLog('获取个人说明BBCODE'); return getProfile(); }) .then(async data => { await outPutLog('修改个人说明BBCODE'); await postProfile(data); }) .then(async () => { await outPutLog('获取鉴权所需的Token'); await getToken(); }) .then(async () => { await outPutLog('还原个人说明BBCODE'); await postProfile(await db.getItem('profile')); }) .catch(async err => { await outPutLog(err); }) .finally(async () => { await outPutLog('鉴权结束'); }); }); }; async function forumCommentHistoryReset() { 'use strict'; const errorstr = $('#outer').find('td.text').text(); // 正在努力加载中... $('#outer').find('td.text').html(errorstr + '        ' + lang['history_text_loading'] + ''); $.ajax({ type: 'post', url: 'https://u2.kysdm.com/api/v1/comment', contentType: "application/json", dataType: 'json', data: JSON.stringify({ "uid": user_id, "token": token, "topicid": topicid, "type": "forum" }), success: function (d) { if (d.msg === 'success') { console.log('获取论坛评论成功'); let __comment = d.data.comment[topicid].sort(firstBy((a, b) => a.pid - b.pid).thenBy((a, b) => b.self - a.self)); // 如果用self排序,消息顺序不正确,则改用编辑日期排序 if (__comment.length === 0) { // 没有评论 可以说不会出现这种情况 console.log('没有历史记录.'); $('#outer').find('td.text').html(errorstr + '        ' + lang['history_text_empty'] + ''); return; }; // 计算pid出现次数 let pidList = __comment.map(x => x.pid); let counts = new Object(); pidList.forEach(x => counts[x] = counts[x] ? counts[x] + 1 : 1); const pidListSet = [...new Set(pidList)]; // 去重 // 还原网页 $('#outer').html(`



` ); // 还原标题 $('span[id="top"]').html(__comment[0]['topics']); __comment.forEach(x => { const bbcode_html = `
#${x.pid} ${x.username}  #${pidListSet.findIndex((a) => a == x.pid) + 1} 楼   Top
avatar
${(() => { if (x.action === 'edit') { return `${bbcode2html(x.bbcode)} ${(() => { if ($('#locale_selection').val() === 'en_US') return `

${lang['last_edited']} ${x.username} at .



`; else if ($('#locale_selection').val() === 'ru_RU') return `

${lang['last_edited']} ${x.username} в .



`; else return `

[] ${x.username} ${lang['last_edited']}



`; })()}`; } else { return `${bbcode2html(x.bbcode)}

`; }; })()}
` if (counts[x.pid] > 1) { console.log('有编辑记录 直接添加下拉菜单'); // 插入下拉菜单基本框架 if ($(`#history_comment${x.pid}_select`).length === 0) { $('#comments').append(bbcode_html); // 先插入整体框架 console.log('添加下拉菜单基本框架'); $(`[id="pid${x.pid}"]`).find('[class="embedded nowrap"]').before(`
`); $(`#history_comment${pid}_select`).append(``); }; }); }); $("[id^=history_comment]").change(function () { // 监听菜单选择 let self = $(this).val(); for (let i = 0, len = __comment.length; i < len; i++) { if (self != __comment[i].self) continue; let html; let x = __comment[i]; if (x.action === 'edit') { html = `${bbcode2html(x.bbcode)} ${(() => { if ($('#locale_selection').val() === 'en_US') return `

${lang['last_edited']} ${x.username} at .

`; else if ($('#locale_selection').val() === 'ru_RU') return `

${lang['last_edited']} ${x.username} в .

`; else return `

[] ${x.username} ${lang['last_edited']}

`; })()}`; } else { html = `${bbcode2html(x.bbcode)}`; }; $(this).parents('[id^=pid]').parent().next().find('.post-body').html(html); return; }; }); } else { console.log('获取论坛评论错误'); }; }, error: function (d) { }, }); }; async function torrentCommentHistory() { 'use strict'; $.ajax({ type: 'post', url: 'https://u2.kysdm.com/api/v1/comment', contentType: "application/json", dataType: 'json', data: JSON.stringify({ "uid": user_id, "token": token, "torrent_id": torrent_id, "type": "torrent" }), success: function (d) { if (d.msg === 'success') { console.log('获取种子评论成功'); let __comment = d.data.comment[torrent_id].sort((a, b) => b.self - a.self); let cidList = __comment.map(x => x.cid); let counts = new Object(); cidList.forEach(x => counts[x] = counts[x] ? counts[x] + 1 : 1) $('[id^="cid"]').each(function () { let cid = $(this).find('[class="embedded"]').children('a').attr('name'); __comment.forEach(x => { if (x.cid == cid && counts[cid] > 1) { if ($(`#history_comment${cid}_select`).length === 0) $(this).find('[class="embedded nowrap"]').before(`
'); $(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('
`); }; // 向下拉菜单写入信息 $(`#history_comment${x.cid}_select`).append(``) } else { $('#comments').append(bbcode_html); }; }); $("[id^=history_comment]").change(function () { // 监听菜单选择 let self = $(this).val(); for (let i = 0, len = __comment.length; i < len; i++) { if (self != __comment[i].self) continue; let html; let x = __comment[i]; if (x.action === 'edit') { html = `
${bbcode2html(x.bbcode)} ${(() => { if ($('#locale_selection').val() === 'en_US') return `

${lang['last_edited']} ${x.username} at .



`; else if ($('#locale_selection').val() === 'ru_RU') return `

${lang['last_edited']} ${x.username} в .



`; else return `

[] ${x.username} ${lang['last_edited']}



`; })()}`; } else { html = `
${bbcode2html(x.bbcode)}

`; }; $(this).parents('[id^=cid]').parent().next().find('[class="rowfollow"]:last').html(html); return; }; }); }; }, error: function (d) { }, }); }) }; const MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; const element = document.getElementById("outer"); var observer = new MutationObserver(callback); observer.observe(element, { childList: true }); }; async function torrentInfoHistoryReset() { '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']}        ${lang['reset_token']}`); $("#apifailure").click(function () { let confirm = prompt("输入 YES 确认本次操作 (大写)"); if (confirm === 'YES') { db.removeItem('key'); db.removeItem('token'); alert("成功"); }; }); 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; // let gdListObj = JSON.parse(localStorage.getItem("u2_gd_list")); // 读取谷歌备份列表 // 还原网页 $('#outer').html('

' + (() => { return history_data[0].banned === 1 ? history_data[0].title + '    [' + lang['banned'] + ']' : history_data[0].title; })() + '

' + '
' + '
' + '

(#' + torrent_id + ')

' + '' + '' + (() => { return history_data[0].subtitle ? '' : '' })() + '' + '' + '' + '' + '' + '
' + lang['torrent_title'] + '' + '[U2].' + history_data[0].torrent_name + '.torrent
' + lang['subtitle'] + '' + history_data[0].subtitle + '
' + 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 // + (() => { // const r = '   ' + lang['google_backup'] + ': ' // if (gdListObj === null) return ``; // 列表不存在时,直接返回 // const gdList = gdListObj.list; // 载入种子列表 // let d = gdList.findIndex((value) => value == Number(torrent_id)); // 查找数据库中是否有备份,没有返回-1 // if (d === -1) return r + `×`; // 没有备份时 // return `${r}` // })() + '
' + '' + 'Show/Hide ' + 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; history_data[i].banned === 1 ? $('#top').html(history_data[i].title + '    [' + lang['banned'] + ']') : $('#top').text(history_data[i].title); // 检查副标题一栏是否存在 if ($("td[class='rowhead nowrap']:contains(" + lang['subtitle'] + ")").length === 0 && history_data[i].subtitle !== null) { $("td[class='rowhead nowrap']:contains(" + lang['uploaded'] + ")").parent().before('' + lang['subtitle'] + ''); } else if ($("td[class='rowhead nowrap']:contains(" + lang['subtitle'] + ")").length === 1 && history_data[i].subtitle === null) { $("td[class='rowhead nowrap']:contains(" + lang['subtitle'] + ")").parent().remove(); }; $("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(/ /g, () => { return '  ' }); bbcodestr = bbcodestr.replace(/\r\n/g, () => { return '
' }); bbcodestr = bbcodestr.replace(/\n/g, () => { return '
' }); bbcodestr = bbcodestr.replace(/\r/g, () => { return '
' }); // info/code 标签 const info_reg = new RegExp("\\[(mediainfo|info|code)\\](.+?)\\[\\/(\\1)\\]", "gis"); bbcodestr = bbcodestr.replace(info_reg, function (s, x, y) { switch (x) { case 'info': return addTempCode('
' + lang['info'] + '' + y + '
'); case 'mediainfo': return addTempCode('
' + lang['mediainfo'] + '' + y + '
'); case 'code': return addTempCode(`
${lang['code']}
${y}

`); 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 + '') }); // 超链接 (相对) bbcodestr = bbcodestr.replace(/\[url=(((?!<|>|\s|"|>|'|<|\(|\)|\[|\]).)+)\](.+?)\[\/url\]/gis, function (s, x, y, z) { return addTempCode('' + z + ''); }); bbcodestr = bbcodestr.replace(/\[url\](((?!<|>|\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 'list'; 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 + '(' + x.replace(/^(?:")?(.*?)(?:")?$/, "$1") + ')'); } 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 (/^((?!<|>|"|>|'|<|;|\(|\)|\[|\]|#).)+\.(?:png|jpg|jpeg|gif|svg|bmp)$/i.test(y)) { // url 以 .png 之类结尾 switch (x) { case 'img': return addTempCode('image'); case 'imglnk': return addTempCode('image'); }; }; return addTempCode(s); }); bbcodestr = bbcodestr.replace(/\[img=([^\]]+)\]/gi, function (s, x) { if (/^((?!<|>|"|>|'|<|;|\(|\)|\[|\]|#).)+\.(?:png|jpg|jpeg|gif|svg|bmp)$/i.test(x)) { // url 以 .png 之类结尾 return addTempCode('image'); }; return 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 '
' + lang['quote'] + '' + x + '
'; }); }; 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 '
' + lang['quote'] + '' + y + '
'; } else { return '
' + lang['quote'] + ': ' + x.replace(/^(?:")?(.*?)(?:")?$/, "$1") + '' + y + '
'; } }); }; // 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 '[' + x + ']'; 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(/(^[^<]*?<\/legend>)(.*)/i, function (s, x, y) { return x + '' + '
' + lang['auto_fold'] + '  ' + '' + '' + '
' + y + '
'; })) }); return $(htmlobj).html(); }; function getapi() { 'use strict'; return new Promise((resolve, reject) => { // https://www.w3school.com.cn/jquery/ajax_ajax.asp $.ajax({ type: 'get', url: 'https://u2.kysdm.com/api/v1/history?token=' + token + '&maximum=50&uid=' + user_id + '&torrent=' + torrent_id, contentType: 'application/json', dataType: 'json', cache: true, success: r => resolve(r), error: r => { console.log('发生错误,HTTP状态码[' + r.status + ']。'); reject(r.status) }, }); }).catch(() => { return { "state": "404", "msg": "failure", "data": { "history": [] } }; }); }; function lang_init(lang) { 'use strict'; var lang_json = { "zh_CN": { "quote": "引用", "info": "发布信息", "mediainfo": "媒体信息", "code": "代码", "spoiler": "警告!下列文字很可能泄露剧情,请谨慎选择是否观看。", "spoiler_button_1": "我就是手贱", "spoiler_button_2": "我真是手贱", "main_title": "主标题", "rt_text": "请输入上标", "main_body": "请输入正文", "main_body_prefix": "请输入标题", "url_name": "请输入网址名称", "url_link": "请输入网址链接", "select_type": "请选择分类...", "preview": "预览", "auto_fold": "过深引用自动折叠", "subtitle": "副标题", "uploaded": "发布人", "basic_info": "基本信息", "description": "描述", "history_select_loading": "正在努力加载中...", "history_select_error": "加载失败啦 (ノДT)", "anonymous": "匿名", "uploaded_at": "发布时间", "size": "大小", "category": "类型", "submitted_by": "提供者", "submitted_at": "提交时间", "history_text_loading": "~~正在检查历史数据中~~", "history_text_error": "加载失败啦 (ノДT) %%", "history_text_empty": "半条历史记录都没有 (ノДT) @@", "torrent_title": "种子标题", "torrent_info": "种子信息", "files": "文件数", "info_hash": "种子散列值", "show_or_hide": "显示 / 隐藏", "KiB": " KiB", "MiB": " MiB", "GiB": " GiB", "TiB": " TiB", "current_time": " 当前时间", "anonymous_user": " 匿名用户", "banned": "已屏蔽", "google_backup": "谷歌备份", "google_send": "发送请求", "last_edited": "最后编辑", "back_to_top": "返回顶部", "reset_token": "重置Token (・_・)ヾ", }, "zh_TW": { "quote": "引用", "info": "發佈訊息", "mediainfo": "媒體訊息", "code": "代碼", "spoiler": "警告!下列文字很可能洩露劇情,請謹慎選擇是否觀看。", "spoiler_button_1": "我就是手賤", "spoiler_button_2": "我真是手賤", "main_title": "主標題", "rt_text": "請輸入上標", "main_body": "請輸入正文", "main_body_prefix": "請輸入標題", "url_name": "請輸入網址名稱", "url_link": "請輸入網址連結", "select_type": "請選擇分類...", "preview": "預覽", "auto_fold": "過深引用自動摺疊", "subtitle": "副標題", "uploaded": "發布人", "basic_info": "基本訊息", "description": "描述", "history_select_loading": "正在努力載入中...", "history_select_error": "載入失敗啦 (ノДT)", "anonymous": "匿名", "uploaded_at": "發布時間", "size": "大小", "category": "類型", "submitted_by": "提供者", "submitted_at": "提交時間", "history_text_loading": "~~正在檢查歷史數據中~~", "history_text_error": "載入失敗啦 (ノДT) %%", "history_text_empty": "半條歷史記錄都沒有 (ノДT) @@", "torrent_title": "種子標題", "torrent_info": "種子訊息", "files": "文件數", "info_hash": "種子散列值", "show_or_hide": "顯示 / 隱藏", "KiB": " KiB", "MiB": " MiB", "GiB": " GiB", "TiB": " TiB", "current_time": " 當前時間", "anonymous_user": " 匿名用戶", "banned": "已屏蔽", "google_backup": "Google備份", "google_send": "發送請求", "last_edited": "最後編輯", "back_to_top": "返回頂部", "reset_token": "重設Token (・_・)ヾ", }, "zh_HK": { "quote": "引用", "info": "發佈訊息", "mediainfo": "媒體訊息", "code": "代碼", "spoiler": "警告!下列文字很可能洩露劇情,請謹慎選擇是否觀看。", "spoiler_button_1": "我就是手賤", "spoiler_button_2": "我真是手賤", "main_title": "主標題", "rt_text": "請輸入上標", "main_body": "請輸入正文", "main_body_prefix": "請輸入標題", "url_name": "請輸入網址名稱", "url_link": "請輸入網址鏈接", "select_type": "請選擇分類...", "preview": "預覽", "auto_fold": "過深引用自動摺疊", "subtitle": "副標題", "uploaded": "發布人", "basic_info": "基本訊息", "description": "描述", "history_select_loading": "正在努力加載中...", "history_select_error": "加載失敗啦 (ノДT)", "anonymous": "匿名", "uploaded_at": "發佈時間", "size": "大小", "category": "類型", "submitted_by": "提供者", "submitted_at": "提交時間", "history_text_loading": "~~正在檢查歷史數據中~~", "history_text_error": "加載失敗啦 (ノДT) %%", "history_text_empty": "半條歷史記錄都沒有 (ノДT) @@", "torrent_title": "種子標題", "torrent_info": "種子訊息", "files": "文件數", "info_hash": "種子散列值", "show_or_hide": "顯示 / 隱藏", "KiB": " KiB", "MiB": " MiB", "GiB": " GiB", "TiB": " TiB", "current_time": " 當前時間", "anonymous_user": " 匿名用戶", "banned": "已屏蔽", "google_backup": "Google備份", "google_send": "發送請求", "last_edited": "最後編輯", "back_to_top": "返回頂部", "reset_token": "重置Token (・_・)ヾ", }, "en_US": { "quote": "Quote", "info": "Infobox", "mediainfo": "Media Info", "code": "CODE", "spoiler": "Warning! This section contains spoiler!", "spoiler_button_1": "I agree to view this.", "spoiler_button_2": "Hide this.", "main_title": "Main Title", "rt_text": "Please enter superscript", "main_body": "Please enter the text", "main_body_prefix": "Please enter a title", "url_name": "Please enter the URL name", "url_link": "Please enter the URL link", "select_type": "Please select a type.", "preview": "Preview", "auto_fold": "Over quote auto fold", "subtitle": "Small Description", "uploaded": "Uploader", "basic_info": "Basic Info", "description": "Description", "history_select_loading": "Trying to load now ...", "history_select_error": "Load failure (ノДT)", "anonymous": "Anonymous", "uploaded_at": "Uploaded at", "size": "Size", "category": "Category", "submitted_by": "Submitted by", "submitted_at": "Submitted at", "history_text_loading": "~~Checking historical data now~~", "history_text_error": "Load failure (ノДT) %%", "history_text_empty": "Half of the history is missing (ノДT) @@", "torrent_title": "Torrent Title", "torrent_info": "Torrent Info", "files": "Files", "info_hash": "Info hash", "show_or_hide": "Show or Hide", "KiB": " KiB", "MiB": " MiB", "GiB": " GiB", "TiB": " TiB", "current_time": " CurrentTime", "anonymous_user": " AnonymousUser", "banned": "Banned", "google_backup": "Google Backup", "google_send": "Send request", "last_edited": "Last edited by", "back_to_top": "Back to top", "reset_token": "Reset Token (・_・)ヾ", }, "ru_RU": { "quote": "Цитата", "info": "Отправленные", "mediainfo": "Данные о Медиа", "code": "CODE", "spoiler": "Предупреждение! Данный раздел содержит СПОЙЛЕРЫ!", "spoiler_button_1": "I agree to view this.", "spoiler_button_2": "Hide this.", "main_title": "Основное название", "rt_text": "Пожалуйста, введите надстрочный индекс", "main_body": "Пожалуйста, введите текст", "main_body_prefix": "Пожалуйста, введите название", "url_name": "Пожалуйста, введите имя URL", "url_link": "Пожалуйста, введите URL-ссылку", "select_type": "выберите тип ...", "preview": "Предварительный просмотр", "auto_fold": "Автоматическое складывание для более глубоких ссылок", "subtitle": "Краткое Описание", "uploaded": "Загрузил", "basic_info": "Базовая инф.", "description": "Описание", "history_select_loading": "Пытаюсь загрузить сейчас ...", "history_select_error": "Отказ нагрузки (ノДT)", "anonymous": "Анонимно", "uploaded_at": "Загружен", "size": "Размер", "category": "Категория", "submitted_by": "Разместивший Запрос", "submitted_at": "Дата размещения", "history_text_loading": "~~Проверка исторических данных сейчас~~", "history_text_error": "Отказ нагрузки (ノДT) %%", "history_text_empty": "Половина истории отсутствует (ノДT) @@", "torrent_title": "Имя торрента", "torrent_info": "Информация о торренте ", "files": "Файлов в торренте", "info_hash": "Информация о ХЕШЕ", "show_or_hide": "Показать / Скрыть", "KiB": " KiБ", "MiB": " MiБ", "GiB": " GiБ", "TiB": " TiБ", "current_time": " Текущее время", "anonymous_user": " Анонимный пользователь", "banned": "Забанен", "google_backup": "Резервное копирование Google", "google_send": "послать запрос", "last_edited": "Последний раз редактировалось", "back_to_top": "На главную", "reset_token": "Токен сброса (・_・)ヾ", } }; return lang_json[lang]; }; // 当前时间 字符串格式 function getDateString() { function zero(obj) { return obj < 10 ? '0' + obj : obj }; const time = new Date(); return time.getFullYear().toString() + '-' + zero(time.getMonth() + 1).toString() + '-' + zero(time.getDate()).toString() + ' ' + zero(time.getHours()) + ':' + zero(time.getMinutes()) + ':' + zero(time.getSeconds()) }; function convert(s) { if (s / 1024 < 1024) return (s / 1024).toFixed(3) + lang['KiB'] if (s / 1024 / 1024 < 1024) return (s / 1024 / 1024).toFixed(3) + lang['MiB'] if (s / 1024 / 1024 / 1024 < 1024) return (s / 1024 / 1024 / 1024).toFixed(3) + lang['GiB'] if (s / 1024 / 1024 / 1024 / 1024 < 1024) return (s / 1024 / 1024 / 1024 / 1024).toFixed(3) + lang['TiB'] };