您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
文章解析为添加到剪切板
当前为
// ==UserScript== // @name mt_文章解析 // @version 1.1.2 // @license MIT // @description 文章解析为添加到剪切板 // @author leeshuailing // @match *://*/* // @grant GM_setClipboard // @grant GM_xmlhttpRequest // @grant unsafeWindow // @namespace https://greasyfork.org/users/1194653 // ==/UserScript== function getLatestVersionFromGreasyFork() { const scriptId = '477295-mt-文章解析'; const apiUrl = `https://greasyfork.org/en/scripts/${scriptId}/versions.json`; fetch(apiUrl) .then(response => response.json()) .then(data => { const latestVersion = data[0].version; checkForUpdate(latestVersion); }) .catch(error => console.error('Error fetching latest version:', error)); } function checkForUpdate(latestVersion) { const currentVersion = GM_info.script.version; if (latestVersion > currentVersion) { const userResponse = confirm(`发现新版本 ${latestVersion},是否立即更新?`); if (userResponse) { window.open('https://greasyfork.org/zh-CN/scripts/477295-mt-%E6%96%87%E7%AB%A0%E8%A7%A3%E6%9E%90'); // 替换为你脚本的 Greasy Fork 页面链接 } } } getLatestVersionFromGreasyFork(); (function () { 'use strict'; const result = { title: "", publistTime: "", link: "", authorName: "", authorId: "", content: "", source: "" }; const chinaseKeyMap = { result: "复制全部", title: "标题", publistTime: "发布时间", link: "链接", authorName: "作者", authorId: "作者ID", content: "内容", source: "来源" }; function timestampToTime(timestamp) { timestamp = timestamp.toString(); timestamp = timestamp.match(/\d{10}/)[0]; if (!timestamp) { return timestamp; } const date = new Date(timestamp * 1000); // 将秒数转换为毫秒数 const year = date.getFullYear(); const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始,需要+1 const day = String(date.getDate()).padStart(2, '0'); const hours = String(date.getHours()).padStart(2, '0'); const minutes = String(date.getMinutes()).padStart(2, '0'); const seconds = String(date.getSeconds()).padStart(2, '0'); return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; } function parseWechatArticle() { result.title = unsafeWindow.globalThis.msg_title; result.publistTime = unsafeWindow.globalThis.create_time; result.link = unsafeWindow.globalThis.msg_link; result.authorName = unsafeWindow.globalThis.nickname; result.authorId = unsafeWindow.globalThis.user_name; result.content = document.querySelector('#js_content').innerHTML; } function parseBaiduArticle() { result.title = unsafeWindow.jsonData.bsData.title; result.publistTime = unsafeWindow.jsonData.bsData.timestamp; result.link = unsafeWindow.jsonData.bsData.profitLog.contentUrl; result.authorName = document.querySelector('span[data-testid="author-name"]').innerText; result.authorId = unsafeWindow.jsonData.bsData.profitLog.contentAccId; result.content = document.querySelector('div[data-testid="article"]').innerHTML; } function igetApi() { let url = unsafeWindow.location.href; let htmlSource = document.documentElement.outerHTML; return GM_xmlhttpRequest({ method: "POST", url: 'http://180.76.101.110:8081/iget-web/v2/parse/html', data: 'url:' + url + "\n" + 'html:' + htmlSource, onload: function (response) { const result_iget = JSON.parse(response.responseText); let data = result_iget.data; result.title = data.title || ""; result.publistTime = data.pubTime || ""; result.authorName = data.author || ""; result.content = data.content || ""; result.source = data.source || ""; result.link = url; setButtonValue(result); } }); } function getRandomColor() { const color1 = Math.floor(Math.random() * 256); // 0-255 const color2 = Math.floor(Math.random() * 256); // 0-255 const color3 = Math.floor(Math.random() * 256); // 0-255 return 'rgb(' + color1 + ', ' + color2 + ', ' + color3 + ')'; } function createCopyButton(butten_name, content) { const copyButton = document.createElement('button'); copyButton.id = butten_name; copyButton.innerText = butten_name; copyButton.style.position = 'fixed'; copyButton.style.top = (50 + 60 * (document.querySelectorAll('button.copy-button').length)) + 'px'; copyButton.style.right = '0'; copyButton.style.transform = 'translateY(-50%)'; copyButton.style.zIndex = '9999'; copyButton.style.fontSize = '16px'; copyButton.style.padding = '10px'; copyButton.style.backgroundColor = getRandomColor(); copyButton.style.color = 'white'; copyButton.style.border = 'none'; copyButton.style.borderRadius = '10px'; // 添加圆角样式 copyButton.style.cursor = 'pointer'; copyButton.style.width = '100px'; copyButton.style.textAlign = 'center'; copyButton.classList.add('copy-button'); copyButton.addEventListener('click', function () { if (butten_name === "开始解析") { let url = unsafeWindow.location.href; if (url.indexOf('mp.weixin.qq.com') > -1) { parseWechatArticle(); setButtonValue(result); } else if (url.indexOf('mbd.baidu.com') > -1) { while (!unsafeWindow.jsonData) { setTimeout(function () { }, 1000); } parseBaiduArticle(); setButtonValue(result); } else { igetApi(); } // 隐藏 innerText=开始解析 的按钮 document.querySelector('#开始解析').style.display = 'none'; } else { GM_setClipboard(content); } }); document.body.appendChild(copyButton); } function setButtonValue(result) { if (result.publistTime) { result.publistTime = timestampToTime(result.publistTime); } result.result = JSON.stringify(result, null, 4); console.log(result) for (let key in chinaseKeyMap) { createCopyButton(chinaseKeyMap[key], result[key]); } } createCopyButton("开始解析"); })();