From 3503c9643a4b5528caad21b6948d3f7555ca93bf Mon Sep 17 00:00:00 2001 From: gui-ying233 Date: Thu, 14 Sep 2023 14:40:13 -0400 Subject: [PATCH] =?UTF-8?q?=E9=9D=9E=E5=B7=AE=E5=BC=82=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=EF=BC=9A=E4=B8=8A=E4=B8=80=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E3=80=81=E6=9C=80=E5=90=8E=E7=89=88=E6=9C=AC=E3=80=81=E4=B8=8B?= =?UTF-8?q?=E4=B8=80=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.user.js | 159 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 113 insertions(+), 46 deletions(-) diff --git a/main.user.js b/main.user.js index 8548133..2c73182 100644 --- a/main.user.js +++ b/main.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name 灰机wiki查看版本历史 // @namespace https://github.com/gui-ying233/huijiHistory -// @version 2.1.0 +// @version 2.2.0 // @description 以另一种方式查看灰机wiki版本历史(绕过权限错误)。 // @author 鬼影233, Honoka55 // @match *.huijiwiki.com/* @@ -26,6 +26,17 @@ }); if (!document.body.getElementsByClassName("permissions-errors")[0]) return; + const parseDate = timestamp => { + const date = new Date(timestamp); + return `${date.getFullYear()}年${ + date.getMonth() + 1 + }月${date.getDate()}日 (${ + ["日", "一", "二", "三", "四", "五", "六"][date.getDay()] + }) ${date.getHours().toString().padStart(2, 0)}:${date + .getMinutes() + .toString() + .padStart(2, 0)}`; + }; switch (mw.config.get("wgAction")) { case "history": const pageName = mw.config.get("wgPageName"); @@ -74,7 +85,6 @@ }) => { const li = document.createElement("li"); li.dataset.mwRevid = revid; - const date = new Date(timestamp); const newestRev = mw.config.get("wgCurRevisionId") === revid; @@ -101,33 +111,15 @@ { oldid: revid, } - )}" class="mw-changeslist-date" title="${pageName}"> - ${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日 (${ - [ - "日", - "一", - "二", - "三", - "四", - "五", - "六", - ][date.getDay()] - }) ${date - .getHours() - .toString() - .padStart(2, 0)}:${date - .getMinutes() - .toString() - .padStart( - 2, - 0 - )}\u200E ${parseDate( + timestamp + )}\u200E ${user}${user}讨论 | 贡献\u200E . . (${size}字节)\u200E . . (${comment})`; + )}" class="mw-usertoollinks-contribs user-link" title="Special:Contributions/${user}">贡献)\u200E . . (${size}字节)\u200E . . (${comment})`; document .getElementById("pagehistory") .appendChild(li); @@ -170,7 +162,11 @@ .done(d => { document.getElementById( "mw-content-text" - ).innerHTML = `${d.compare.body}
`; + ).innerHTML = `${ + d.compare.body + ? `${d.compare.body}` + : '' + }
(没有差异)
`; }); } else { await api @@ -185,7 +181,11 @@ .done(d => { document.getElementById( "mw-content-text" - ).innerHTML = `${d.compare.body}
`; + ).innerHTML = `${ + d.compare.body + ? `${d.compare.body}` + : '' + }
(没有差异)
`; }); } if (searchParams.get("diffonly") === "1") return; @@ -200,24 +200,11 @@ rvprop: "content|timestamp", }) .done(d => { - const date = new Date( - d.query.pages[0].revisions[0].timestamp - ); document.getElementById( "mw-content-text" - ).innerHTML += `

${date.getFullYear()}年${ - date.getMonth() + 1 - }月${date.getDate()}日 (${ - ["日", "一", "二", "三", "四", "五", "六"][ - date.getDay() - ] - }) ${date - .getHours() - .toString() - .padStart(2, 0)}:${date - .getMinutes() - .toString() - .padStart(2, 0)}的版本

`; + ).innerHTML += `

${parseDate( + d.query.pages[0].revisions[0].timestamp + )}的版本

`; api.post({ action: "parse", format: "json", @@ -240,14 +227,94 @@ revids: searchParams.get("oldid"), utf8: 1, formatversion: 2, - rvprop: "content", + rvprop: "ids|timestamp|user|parsedcomment|content", }) - .done(d => { + .done(async d => { + d = d.query.pages[0].revisions[0]; + let torevid; + await api + .get({ + action: "compare", + format: "json", + fromrev: searchParams.get("oldid"), + torelative: "next", + prop: "ids", + utf8: 1, + formatversion: 2, + }) + .done(d => { + torevid = d.compare.torevid; + }); + document.getElementById( + "bodyContent" + ).parentNode.innerHTML = + `
${ + d.user + }讨论 | 贡献${parseDate( + d.timestamp + )}的版本 (${ + d.parsedcomment + })
${ + d.parentid + ? `(差异) ←上一版本` + : "(差异) ←上一版本" + } | ${ + torevid + ? `最后版本 (差异) | 下一版本→ (差异)
` + : "最后版本 (差异) | 下一版本→ (差异)" + }` + + document.getElementById("bodyContent") + .parentNode.innerHTML; api.post({ action: "parse", format: "json", title: pageName, - text: d.query.pages[0].revisions[0].content, + text: d.content, prop: "text", utf8: 1, formatversion: 2,