您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
文章解析为添加到剪切板
当前为
// ==UserScript== // @name mt_文章解析 // @version 1.0.2 // @license MIT // @description 文章解析为添加到剪切板 // @author leeshuailing // @match https://mp.weixin.qq.com/* // @match https://mbd.baidu.com/* // @match https://baijiahao.baidu.com/s?id=* // @grant GM_setClipboard // @grant unsafeWindow // @namespace https://greasyfork.org/users/1194653 // ==/UserScript== function getLatestVersionFromGreasyFork() { const scriptId = '477295-mt-文章解析'; // 替换为你的脚本在 Greasy Fork 上的 ID 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'; 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}`; } var result = { title: "", publistTime: "", link: "", authorName: "", authorId: "", content: "" }; var chinaseKeyMap = { result: "复制全部", title: "标题", publistTime: "发布时间", link: "链接", authorName: "作者", authorId: "作者ID", content: "内容" } 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; } // 获取url let url = unsafeWindow.location.href; if (url.indexOf('mp.weixin.qq.com') > -1) { parseWechatArticle(); } else if (url.indexOf('mbd.baidu.com') > -1) { while (!unsafeWindow.jsonData) { setTimeout(function () { }, 1000); } parseBaiduArticle(); } function getRandomColor() { var color1 = Math.floor(Math.random() * 256); // 0-255 var color2 = Math.floor(Math.random() * 256); // 0-255 var color3 = Math.floor(Math.random() * 256); // 0-255 return 'rgb(' + color1 + ', ' + color2 + ', ' + color3 + ')'; } function createCopyButton(text, content) { var copyButton = document.createElement('button'); copyButton.innerText = text; 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 () { GM_setClipboard(content); }); document.body.appendChild(copyButton); } result.publistTime = timestampToTime(result.publistTime); result.result = JSON.stringify(result); window.addEventListener('load', function () { setTimeout(function () { for (let key in chinaseKeyMap) { createCopyButton(chinaseKeyMap[key], result[key]); } }); }); })();