// ==UserScript== // @name Archive.md Quick Jump // @namespace https://archive.md/ // @version 1.0 // @description 在主流新闻站点页面添加 archive.md 存档/查看按钮 // @author ayaka // @match *://*.nytimes.com/* // @match *://*.washingtonpost.com/* // @match *://*.wsj.com/* // @match *://*.bbc.com/* // @match *://*.bbc.co.uk/* // @match *://*.cnn.com/* // @match *://*.reuters.com/* // @match *://*.apnews.com/* // @match *://*.theguardian.com/* // @match *://*.ft.com/* // @match *://*.economist.com/* // @match *://*.bloomberg.com/* // @match *://*.forbes.com/* // @match *://*.cnbc.com/* // @match *://*.foxnews.com/* // @match *://*.nbcnews.com/* // @match *://*.abcnews.go.com/* // @match *://*.politico.com/* // @match *://*.theatlantic.com/* // @match *://*.newyorker.com/* // @match *://*.latimes.com/* // @match *://*.usatoday.com/* // @match *://*.time.com/* // @match *://*.independent.co.uk/* // @match *://*.telegraph.co.uk/* // @match *://*.dailymail.co.uk/* // @match *://*.spiegel.de/* // @match *://*.lemonde.fr/* // @match *://*.nhk.or.jp/* // @match *://*.asahi.com/* // @match *://*.mainichi.jp/* // @match *://*.yomiuri.co.jp/* // @match *://*.nikkei.com/* // @match *://*.scmp.com/* // @match *://*.straitstimes.com/* // @match *://*.aljazeera.com/* // @match *://*.nature.com/* // @match *://*.science.org/* // @match *://*.wired.com/* // @match *://*.arstechnica.com/* // @match *://*.theverge.com/* // @match *://*.techcrunch.com/* // @match *://*.medium.com/* // @match *://*.substack.com/* // @match *://*.caixin.com/* // @match *://*.infzm.com/* // @match *://*.chinadaily.com.cn/* // @license MIT // @grant GM_addStyle // @run-at document-idle // @downloadURL none // ==/UserScript== (function () { 'use strict'; const currentURL = location.href; const archiveSearch = `https://archive.md/newest/${currentURL}`; const archiveSubmit = `https://archive.md/?run=1&url=${encodeURIComponent(currentURL)}`; // ---------- 样式 ---------- GM_addStyle(` #archive-float-btn { position: fixed; bottom: 24px; right: 24px; z-index: 2147483647; display: flex; flex-direction: column; gap: 6px; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; transition: opacity .2s; } #archive-float-btn.collapsed .archive-sub { display: none; } #archive-float-btn .archive-main-toggle { width: 48px; height: 48px; border-radius: 50%; border: none; background: #1a1a2e; color: #fff; font-size: 20px; cursor: pointer; box-shadow: 0 2px 12px rgba(0,0,0,.3); display: flex; align-items: center; justify-content: center; align-self: flex-end; transition: transform .2s, background .2s; } #archive-float-btn .archive-main-toggle:hover { background: #16213e; transform: scale(1.1); } #archive-float-btn .archive-sub { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; } #archive-float-btn .archive-sub a { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 8px; text-decoration: none; font-size: 13px; font-weight: 500; color: #fff; white-space: nowrap; box-shadow: 0 2px 8px rgba(0,0,0,.25); transition: transform .15s, box-shadow .15s; } #archive-float-btn .archive-sub a:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(0,0,0,.35); } #archive-float-btn .archive-sub .archive-view { background: #0f3460; } #archive-float-btn .archive-sub .archive-save { background: #533483; } #archive-float-btn .archive-sub .archive-copy { background: #1a1a2e; cursor: pointer; border: none; font: inherit; padding: 8px 14px; border-radius: 8px; color: #fff; font-size: 13px; font-weight: 500; box-shadow: 0 2px 8px rgba(0,0,0,.25); } `); // ---------- DOM ---------- const container = document.createElement('div'); container.id = 'archive-float-btn'; container.classList.add('collapsed'); // 子按钮区 const sub = document.createElement('div'); sub.className = 'archive-sub'; // 查看存档 const viewLink = document.createElement('a'); viewLink.className = 'archive-view'; viewLink.href = archiveSearch; viewLink.target = '_blank'; viewLink.rel = 'noopener'; viewLink.innerHTML = `📖查看存档`; // 创建存档 const saveLink = document.createElement('a'); saveLink.className = 'archive-save'; saveLink.href = archiveSubmit; saveLink.target = '_blank'; saveLink.rel = 'noopener'; saveLink.innerHTML = `💾创建存档`; // 复制存档链接 const copyBtn = document.createElement('button'); copyBtn.className = 'archive-copy'; copyBtn.innerHTML = `📋复制存档链接`; copyBtn.addEventListener('click', () => { navigator.clipboard.writeText(archiveSearch).then(() => { copyBtn.querySelector('span:last-child').textContent = '已复制 ✓'; setTimeout(() => { copyBtn.querySelector('span:last-child').textContent = '复制存档链接'; }, 1500); }); }); sub.append(viewLink, saveLink, copyBtn); // 主按钮 const toggle = document.createElement('button'); toggle.className = 'archive-main-toggle'; toggle.textContent = '🗄️'; toggle.title = 'Archive.md'; toggle.addEventListener('click', () => { container.classList.toggle('collapsed'); }); container.append(sub, toggle); document.body.appendChild(container); // 点击外部收起 document.addEventListener('click', (e) => { if (!container.contains(e.target)) { container.classList.add('collapsed'); } }); })();