// ==UserScript== // @name 查看Luogu中的文章、剪贴板、个人介绍 // @namespace http://tampermonkey.net/ // @version 0.3.0 // @description 查看Luogu中的文章、剪贴板、个人介绍 // @author Andy_hpy // @match *://www.luogu.com.cn/* // @match *://luogu.com.cn/* // @grant GM_xmlhttpRequest // @grant GM_getValue // @grant GM_setValue // @grant GM_addStyle // @grant GM_getResourceText // @resource sweetalert2css https://cdn.jsdelivr.net/npm/sweetalert2@11.26.25/dist/sweetalert2.min.css // @require https://cdn.jsdelivr.net/npm/sweetalert2@11.26.25/dist/sweetalert2.min.js // @require https://cdn.jsdelivr.net/npm/luogu-renderer@latest/dist/luogu-new-renderer.iife.min.js // @run-at document-start // @connect api.luogu.me // @connect .luogu.com.cn // @connect .luogu.com // @license AGPL-3.0 // ==/UserScript== async function init() { window.dataOfVote = JSON.parse(GM_getValue('dataOfVote', '{}')); window.dataOfFavor = JSON.parse(GM_getValue('dataOfFavor', '{}')); setInterval(() => { GM_setValue('dataOfVote', JSON.stringify(window.dataOfVote)); GM_setValue('dataOfFavor', JSON.stringify(window.dataOfFavor)); }, 60000); document.addEventListener('beforeunload', () => { GM_setValue('dataOfVote', JSON.stringify(window.dataOfVote)); GM_setValue('dataOfFavor', JSON.stringify(window.dataOfFavor)); }); } async function articlePage() { const override = setInterval(async function () { if (document.querySelector('body > div')) { clearInterval(override); document.querySelector('body > div').style.visibility = 'hidden'; } }, 10); const id = location.href.split('/').pop(); async function deal404() { const wait = setInterval(async function () { if (document.querySelector('html')) { clearInterval(wait); if (document.querySelector('body > div > div.card > pre#url')) { Swal.fire({ title: '内容未找到', text: '该内容尚未被保存站收录,是否立即保存?', icon: 'warning', showCancelButton: true, confirmButtonText: '保存', cancelButtonText: '返回', confirmButtonColor: "#3085d6", cancelButtonColor: "#d33", allowEscapeKey: false, allowOutsideClick: false }).then(async (result) => { if (result.isConfirmed) { Swal.mixin({ toast: true, position: "top-end", showConfirmButton: false, timer: 3000, timerProgressBar: true, didOpen: (toast) => { toast.onmouseenter = Swal.stopTimer; toast.onmouseleave = Swal.resumeTimer; } }).fire({ icon: "success", title: "保存请求已提交" }); const response = await saveArticle(id); const workId = response.data.workflowId; if (response.code === 200) { const wait = setInterval(async () => { if ((await getWorkflow(workId)).code === 200) { clearInterval(wait); Swal.fire({ title: '保存成功', icon: 'success', confirmButtonText: '确定' }).then(() => { location.reload() }); } }, 500); } else { Swal.fire({ title: '保存失败', text: '保存失败,请稍后再试', icon: 'error', confirmButtonText: '确定' }).then(() => { document.querySelector('body > div').style.visibility = ''; }); } } else if (result.dismiss === Swal.DismissReason.cancel) { history.back(); } }); } else { document.querySelector('body > div').style.display = ''; } } }, 500); return; } let articleInfo, user, theme, metaHtml, replyCount; try { [articleInfo, { user, theme, metaHtml }, replyCount] = await Promise.all([ getDataOnLuoguMe(`https://api.luogu.me/article/query/${id}`), getTheme_MyUserInfo_AndMetaHtml(), getReplyCount(id) ]); } catch (error) { deal404(); return; } if (articleInfo.code === 404) { deal404(); return; } (async () => { document.querySelector('head').insertAdjacentHTML('beforeend', metaHtml); })(); const info = articleInfo.data; const [authorInfo, upvote] = await Promise.all([ getUserInfo(info.authorId), (async () => { const response = await fetch(`https://www.luogu.com.cn/article/${id}/vote?vote=${Number(window.dataOfVote[id] || 0)}`, { method: 'POST' }); const data = await response.json(); if (!response.ok) { return -1; } return data.upvotes; })() ]); const finalData = { instance: "main", template: "article.show", status: 200, locale: "zh-CN", data: { article: { lid: id, title: info.title, category: info.category, time: Math.floor(new Date(info.createdAt).getTime() / 1000), author: { uid: authorInfo.uid, avatar: authorInfo.avatar, name: authorInfo.name, slogan: authorInfo.slogan, badge: authorInfo.badge, isAdmin: authorInfo.isAdmin, isBanned: authorInfo.isBanned, color: authorInfo.color, ccfLevel: authorInfo.ccfLevel, xcpcLevel: authorInfo.xcpcLevel, background: authorInfo.background, verified: true }, upvote: upvote, favorCount: Math.max(window.dataOfFavor[id], info.favorCount), solutionFor: info.solutionForPid == null ? null : { pid: info.solutionForPid }, content: info.content, canReply: true, canEdit: false, status: 1, replyCount: replyCount, voted: Number(window.dataOfVote[id] || 0) }, canReply: true, canEdit: false, favored: window.dataOfFavor[id] || 0 }, user: user, theme: theme } console.debug(finalData); function write() { document.open(); document.write(`
${metaHtml}