// ==UserScript== // @name 网页复制解锁 // @namespace https://cxbank.icu/copyfree // @version 1.2.0 // @description 解除复制/右键/选中限制;正文一键提取、表格转 CSV、图片原图下载(可打包 ZIP)。 // @author ZZ // @match *://*/* // @grant none // @run-at document-start // @noframes false // ==/UserScript== (function () { 'use strict'; var KEY = 'copyfree_on'; var S = { on: true, removedAttrs: 0, removedClasses: 0, }; try { S.on = localStorage.getItem(KEY) !== '0'; } catch (e) {} /* 需要"放行"的事件类型 */ var BLOCKED = { copy: 1, cut: 1, contextmenu: 1, selectstart: 1, dragstart: 1 }; /* ---------- 1) 拦截 preventDefault ---------- */ var origPD = Event.prototype.preventDefault; Event.prototype.preventDefault = function () { try { if (S.on && this && BLOCKED[this.type]) { /* 记录一下,面板上能看到"本站拦了几个" */ S.blockedCalls = (S.blockedCalls || 0) + 1; return; } } catch (e) {} return origPD.apply(this, arguments); }; /* ---------- 2) 清掉内联事件 ---------- */ function stripInline(root) { try { var attrs = ['oncopy', 'oncut', 'oncontextmenu', 'onselectstart', 'ondragstart', 'onmousedown', 'onmouseup']; var all = (root || document).querySelectorAll('*'); for (var i = 0; i < all.length; i++) { var el = all[i]; for (var k = 0; k < attrs.length; k++) { if (el.getAttribute && el.getAttribute(attrs[k])) { el.removeAttribute(attrs[k]); S.removedAttrs++; } } } /* 文档级 */ ['oncopy', 'oncut', 'oncontextmenu', 'onselectstart', 'ondragstart'].forEach(function (a) { try { document[a] = null; } catch (e) {} try { document.body && (document.body[a] = null); } catch (e) {} }); } catch (e) {} } /* ---------- 3) 去掉 user-select: none ---------- */ var style = null; function applyStyle() { if (!style) { style = document.createElement('style'); style.id = 'copyfree-style'; style.textContent = 'html,body,*{-webkit-user-select:text !important;user-select:text !important;' + '-webkit-touch-callout:default !important}'; (document.head || document.documentElement).appendChild(style); } style.disabled = !S.on; } /* ---------- 4) 清理常见"禁止选中"的 class ---------- */ var BAD_CLASS = /(noselect|no-select|noselection|unselectable|disable-select|user-select-none)/i; function stripClasses(root) { try { var all = (root || document).querySelectorAll('[class]'); for (var i = 0; i < all.length; i++) { var el = all[i]; var c = String(el.className || ''); if (!BAD_CLASS.test(c)) continue; el.className = c.split(/\s+/).filter(function (x) { return !BAD_CLASS.test(x); }).join(' '); S.removedClasses++; } } catch (e) {} } /* ---------- 5) 兜底:Alt+C 强制复制选中内容 ---------- */ function forceCopy() { try { var sel = String(window.getSelection ? window.getSelection() : ''); if (!sel) return false; if (navigator.clipboard && navigator.clipboard.writeText) { navigator.clipboard.writeText(sel); return true; } var ta = document.createElement('textarea'); ta.value = sel; ta.style.cssText = 'position:fixed;left:-9999px;top:0'; document.body.appendChild(ta); ta.select(); document.execCommand('copy'); ta.remove(); return true; } catch (e) { return false; } } document.addEventListener('keydown', function (e) { if (e.altKey && (e.key === 'c' || e.key === 'C')) { if (forceCopy()) { e.preventDefault(); toast('已复制选中内容'); } } }, true); /* ---------- 6) 图片原图下载 ---------- */ /* 常见 CDN 缩略图规则 → 还原成原图 */ function origUrl(u) { if (!u) return ''; var s = String(u).trim(); if (!s || /^data:/i.test(s)) return ''; /* 微信公众平台:末尾 /640 或 /300 之类 */ s = s.replace(/\/(?:640|300|200|132|0|w)\/?$/i, '/0'); s = s.replace(/([?&])(?:wxfrom|wx_lazy|wx_co|tp|wx_fmt)=[^&]*/gi, '$1').replace(/[?&]$/, ''); /* 通用 ?x-oss-process / ?imageView2 / ?imageMogr2 / resize 参数 */ s = s.replace(/[?&](?:x-oss-process|imageView2|imageMogr2|resize|thumbnail|thumb|w|h|quality|q|width|height)=[^&]*/gi, ''); s = s.replace(/[?&]$/, ''); /* 知乎 _b / _hd → 原图 */ s = s.replace(/_(?:b|hd|720w|540w)\.(jpg|jpeg|png|webp|gif)/i, '.$1'); /* 后缀式缩略:@320w_200h、@!q70、!w400 */ s = s.replace(/@[^/?#]*$/, ''); s = s.replace(/![a-z]\d+[^/?#]*$/i, ''); /* 淘宝/1688:_sum.jpg / _400x400.jpg / _q75.jpg */ s = s.replace(/_(?:sum|q\d{2}|\d+x\d+)(\.(?:jpg|jpeg|png|webp|gif))/i, '$1'); /* WordPress:-300x200.jpg */ s = s.replace(/-\d{2,4}x\d{2,4}(\.(?:jpg|jpeg|png|webp|gif))/i, '$1'); /* 简书/CSDN 等:/thumb/、/small/、_small */ s = s.replace(/\/(?:thumb|thumbs|small|medium|preview)\//i, '/'); s = s.replace(/_(?:small|medium|thumb)(\.(?:jpg|jpeg|png|webp|gif))/i, '$1'); /* bilibili:@320w_200h.webp */ s = s.replace(/@\d+w_\d+h\.(?:webp|jpg|png)/i, ''); return s; } function absUrl(u) { try { return new URL(u, location.href).href; } catch (e) { return ''; } } function collectImages() { var out = [], seen = {}; function push(u, w, h, note) { var a = absUrl(u); if (!a || /^data:/i.test(a)) return; if (seen[a]) return; seen[a] = 1; out.push({ url: a, orig: origUrl(a), w: w || 0, h: h || 0, note: note || '' }); } /* :原图优先取 data-original / data-src / data-actualsrc */ var imgs = document.querySelectorAll('img'); for (var i = 0; i < imgs.length && out.length < 200; i++) { var im = imgs[i]; var real = im.getAttribute('data-original') || im.getAttribute('data-src') || im.getAttribute('data-actualsrc') || im.getAttribute('data-lazy-src') || ''; var cand = real || im.currentSrc || im.src || ''; if (!cand) continue; if (im.naturalWidth && im.naturalWidth < 60 && im.naturalHeight < 60) continue; /* 跳过图标 */ push(cand, im.naturalWidth || im.width, im.naturalHeight || im.height, real ? 'lazy' : ''); /* srcset 里挑最大的 */ var ss = im.getAttribute('srcset'); if (ss) { var best = '', bw = 0; ss.split(',').forEach(function (part) { var p = part.trim().split(/\s+/); var w = parseInt(p[1], 10) || 0; if (w > bw) { bw = w; best = p[0]; } }); if (best) push(best, bw, 0, 'srcset'); } } /* */ document.querySelectorAll('picture source[srcset]').forEach(function (sc) { var first = (sc.getAttribute('srcset') || '').split(',')[0]; if (first) push(first.trim().split(/\s+/)[0], 0, 0, 'picture'); }); /* CSS 背景图(限前 120 个元素,避免卡) */ var all = document.querySelectorAll('*'); for (var k = 0; k < all.length && k < 1200 && out.length < 200; k++) { var bg = ''; try { bg = getComputedStyle(all[k]).backgroundImage || ''; } catch (e) { bg = ''; } var m = /url\(["']?([^"')]+)["']?\)/.exec(bg); if (m && m[1]) push(m[1], 0, 0, 'bg'); } return out; } /* --- 极简 ZIP(仅存储不压缩)--- */ var CRC_TABLE = (function () { var t = new Uint32Array(256); for (var n = 0; n < 256; n++) { var c = n; for (var k = 0; k < 8; k++) c = (c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1); t[n] = c >>> 0; } return t; })(); function crc32(buf) { var c = 0xFFFFFFFF; for (var i = 0; i < buf.length; i++) c = CRC_TABLE[(c ^ buf[i]) & 0xFF] ^ (c >>> 8); return (c ^ 0xFFFFFFFF) >>> 0; } function makeZip(files) { var enc = new TextEncoder(); var parts = [], central = [], offset = 0; files.forEach(function (f) { var name = enc.encode(f.name); var data = f.data; var crc = crc32(data); var local = new Uint8Array(30 + name.length); var dv = new DataView(local.buffer); dv.setUint32(0, 0x04034b50, true); dv.setUint16(4, 20, true); dv.setUint16(6, 0x0800, true); dv.setUint16(8, 0, true); dv.setUint16(10, 0, true); dv.setUint16(12, 0, true); dv.setUint32(14, crc, true); dv.setUint32(18, data.length, true); dv.setUint32(22, data.length, true); dv.setUint16(26, name.length, true); dv.setUint16(28, 0, true); local.set(name, 30); parts.push(local, data); var cd = new Uint8Array(46 + name.length); var cv = new DataView(cd.buffer); cv.setUint32(0, 0x02014b50, true); cv.setUint16(4, 20, true); cv.setUint16(6, 20, true); cv.setUint16(8, 0x0800, true); cv.setUint16(10, 0, true); cv.setUint16(12, 0, true); cv.setUint16(14, 0, true); cv.setUint32(16, crc, true); cv.setUint32(20, data.length, true); cv.setUint32(24, data.length, true); cv.setUint16(28, name.length, true); cv.setUint16(30, 0, true); cv.setUint16(32, 0, true); cv.setUint16(34, 0, true); cv.setUint16(36, 0, true); cv.setUint32(38, 0, true); cv.setUint32(42, offset, true); cd.set(name, 46); central.push(cd); offset += local.length + data.length; }); var cdSize = central.reduce(function (a, b) { return a + b.length; }, 0); var end = new Uint8Array(22); var ev = new DataView(end.buffer); ev.setUint32(0, 0x06054b50, true); ev.setUint16(8, files.length, true); ev.setUint16(10, files.length, true); ev.setUint32(12, cdSize, true); ev.setUint32(16, offset, true); return new Blob(parts.concat(central, [end]), { type: 'application/zip' }); } function saveBlob(blob, name) { var a = document.createElement('a'); var u = URL.createObjectURL(blob); a.href = u; a.download = name; document.body.appendChild(a); a.click(); setTimeout(function () { URL.revokeObjectURL(u); a.remove(); }, 4000); } function fileName(u, i) { var n = 'image_' + (i + 1); try { var p = new URL(u).pathname.split('/').pop(); if (p && p.length < 80) n = decodeURIComponent(p).replace(/[\\/:*?"<>|]/g, '_'); } catch (e) {} if (!/\.(jpg|jpeg|png|webp|gif|bmp|avif)$/i.test(n)) n += '.jpg'; return n; } /* 逐个抓取;跨域失败就退回新窗口打开 */ async function grab(url) { try { var r = await fetch(url, { credentials: 'omit', mode: 'cors' }); if (!r.ok) throw new Error('HTTP ' + r.status); return new Uint8Array(await r.arrayBuffer()); } catch (e) { return null; } } var IMG = { list: [], sel: {}, panel: null, busy: false }; function imgPanel() { if (IMG.panel) { IMG.panel.remove(); IMG.panel = null; return; } IMG.list = collectImages(); IMG.sel = {}; if (!IMG.list.length) { toast('本页没找到图片'); return; } var box = document.createElement('div'); box.style.cssText = 'position:fixed;inset:4% 6%;z-index:2147483003;background:#fff;border-radius:16px;' + 'box-shadow:0 20px 60px rgba(0,0,0,.35);display:flex;flex-direction:column;overflow:hidden;' + 'font:13px/1.6 -apple-system,"Segoe UI",sans-serif;color:#1c1c1e'; box.innerHTML = '
' + '图片原图下载' + '' + '' + '' + '' + '' + '' + '
'; var list = box.querySelector('#cf-list'); IMG.list.forEach(function (it, i) { var card = document.createElement('div'); card.style.cssText = 'border:2px solid ' + (it.orig !== it.url ? '#34c759' : '#e5e5ea') + ';border-radius:10px;overflow:hidden;cursor:pointer;background:#fafafa'; var thumb = document.createElement('img'); thumb.src = it.url; thumb.style.cssText = 'width:100%;height:96px;object-fit:cover;display:block;background:#eee'; var meta = document.createElement('div'); meta.style.cssText = 'padding:6px 8px;font-size:11px;color:#666;white-space:nowrap;overflow:hidden;text-overflow:ellipsis'; meta.textContent = (it.w ? it.w + '×' + it.h : '尺寸未知') + (it.orig !== it.url ? ' · 可还原原图' : '') + (it.note ? ' · ' + it.note : ''); card.appendChild(thumb); card.appendChild(meta); card.onclick = function () { if (IMG.sel[i]) { delete IMG.sel[i]; card.style.outline = ''; } else { IMG.sel[i] = 1; card.style.outline = '3px solid #0a84ff'; } updateCnt(); }; list.appendChild(card); }); function updateCnt() { var n = Object.keys(IMG.sel).length; box.querySelector('#cf-cnt').textContent = '共 ' + IMG.list.length + ' 张 · 已选 ' + n; } updateCnt(); box.querySelector('#cf-x').onclick = function () { box.remove(); IMG.panel = null; }; box.querySelector('#cf-all').onclick = function () { var all = Object.keys(IMG.sel).length !== IMG.list.length; IMG.sel = {}; if (all) IMG.list.forEach(function (_, i) { IMG.sel[i] = 1; }); Array.prototype.forEach.call(list.children, function (c, i) { c.style.outline = IMG.sel[i] ? '3px solid #0a84ff' : ''; }); updateCnt(); }; box.querySelector('#cf-copy').onclick = function () { var urls = Object.keys(IMG.sel).map(function (i) { return IMG.list[i].orig; }); if (!urls.length) return toast('先选几张'); var txt = urls.join('\n'); if (navigator.clipboard) navigator.clipboard.writeText(txt).then(function () { toast('已复制 ' + urls.length + ' 条'); }); else toast('复制失败'); }; box.querySelector('#cf-zip').onclick = async function () { var idx = Object.keys(IMG.sel).map(Number); if (!idx.length) return toast('先选择图片'); if (IMG.busy) return; IMG.busy = true; toast('正在抓取 0/' + idx.length + '…'); var files = [], fail = 0; for (var n = 0; n < idx.length; n++) { var it = IMG.list[idx[n]]; var data = await grab(it.orig); if (!data) { fail++; continue; } files.push({ name: fileName(it.orig, n), data: data }); toast('正在抓取 ' + (n + 1) + '/' + idx.length + '…'); } IMG.busy = false; if (!files.length) return toast('全部抓取失败(跨域限制),可改用「复制链接」'); saveBlob(makeZip(files), 'images_' + Date.now() + '.zip'); toast('已打包 ' + files.length + ' 张' + (fail ? '(' + fail + ' 张跨域失败)' : '')); }; document.body.appendChild(box); IMG.panel = box; } /* ---------- 7) 正文提取复制 ---------- */ /* 思路:候选容器打分(文字长度 / 段落数 / 链接密度 / 类名特征),取最高分当正文 */ var NEG_CLASS = /(nav|menu|header|footer|sidebar|aside|comment|advert|banner|promo|share|related|recommend|breadcrumb|copyright|toolbar|popup|modal|login)/i; var POS_CLASS = /(article|content|post|entry|main|body|text|detail|rich|markdown|read)/i; function cleanText(t) { return String(t || '') .replace(/[ \t\u00a0]+/g, ' ') .replace(/\n{3,}/g, '\n\n') .trim(); } function textOf(el) { var t = ''; try { t = el.innerText || el.textContent || ''; } catch (e) { t = ''; } return cleanText(t); } function scoreNode(el) { var txt = textOf(el); if (txt.length < 140) return -1; var links = el.querySelectorAll('a'); var linkLen = 0; for (var i = 0; i < links.length; i++) linkLen += (links[i].innerText || '').length; var density = links.length ? linkLen / Math.max(1, txt.length) : 0; if (density > 0.55) return -1; /* 链接太多 = 导航区 */ var cls = String(el.className || '') + ' ' + String(el.id || ''); var score = txt.length; if (POS_CLASS.test(cls)) score *= 1.6; if (NEG_CLASS.test(cls)) score *= 0.35; var paras = el.querySelectorAll('p,div>br,li').length; score *= 1 + Math.min(1.2, paras / 40); score *= 1 - density; /* 链接密度越高越不像正文 */ /* 太靠近 body/html 的容器扣分(避免整页) */ if (el === document.body) score *= 0.25; if (el.tagName === 'HTML') score *= 0.1; return score; } function pickContentNode() { var best = null, bestScore = 0; var cands = document.querySelectorAll( 'article, main, [class*="article"], [class*="content"], [class*="post"], [class*="entry"],' + '[class*="detail"], [class*="rich"], [id*="content"], [id*="article"], .markdown-body, section, div' ); var limit = Math.min(cands.length, 2500); for (var i = 0; i < limit; i++) { var el = cands[i]; try { var cs = getComputedStyle(el); if (cs.display === 'none' || cs.visibility === 'hidden') continue; } catch (e) {} var s = scoreNode(el); if (s > bestScore) { bestScore = s; best = el; } } return best; } /* 从正文节点里提取结构化纯文本:段落换行、标题保留 */ function extractText(root) { if (!root) return ''; var clone = root.cloneNode(true); /* 去掉明显噪音 */ clone.querySelectorAll('script,style,noscript,svg,canvas,iframe,video,audio,form,nav,aside,footer,header,[aria-hidden="true"]') .forEach(function (n) { try { n.remove(); } catch (e) {} }); clone.querySelectorAll('[class],[id]').forEach(function (n) { try { var c = String(n.className || '') + ' ' + String(n.id || ''); if (NEG_CLASS.test(c) && textOf(n).length < 400) n.remove(); } catch (e) {} }); /* 块级元素前后补换行 */ var out = []; (function walk(node) { if (!node) return; if (node.nodeType === 3) { var t = node.nodeValue; if (t && t.trim()) out.push(t.replace(/[ \t\u00a0]+/g, ' ')); return; } if (node.nodeType !== 1) return; var tag = node.tagName; if (tag === 'BR') { out.push('\n'); return; } var block = /^(P|DIV|SECTION|ARTICLE|LI|TR|H1|H2|H3|H4|H5|H6|BLOCKQUOTE|PRE|TD|DD|DT)$/.test(tag); if (block) out.push('\n'); if (/^H[1-6]$/.test(tag)) out.push('\n'); for (var i = 0; i < node.childNodes.length; i++) walk(node.childNodes[i]); if (block) out.push('\n'); })(clone); var text = out.join('').replace(/[ \t\u00a0]+/g, ' ').replace(/\n\s*\n\s*\n+/g, '\n\n').trim(); return text; } function copyText(txt) { if (!txt) return false; try { if (navigator.clipboard && navigator.clipboard.writeText) { navigator.clipboard.writeText(txt); return true; } } catch (e) {} try { var ta = document.createElement('textarea'); ta.value = txt; ta.style.cssText = 'position:fixed;left:-9999px'; document.body.appendChild(ta); ta.select(); var ok = document.execCommand('copy'); ta.remove(); return ok; } catch (e) { return false; } } /* 一键复制全文 */ function copyArticle(silent) { var root = pickContentNode(); var txt = extractText(root); if (!txt || txt.length < 80) { toast('没找到正文(可能这页不是文章)'); return false; } var ok = copyText(txt); if (ok && !silent) toast('已复制正文 ' + txt.length + ' 字'); else if (!ok) toast('复制失败,请手动选中'); return ok ? txt : false; } /* 正文预览面板:可编辑后再复制 */ function articlePanel() { var root = pickContentNode(); var txt = extractText(root); if (!txt || txt.length < 80) { toast('没找到正文'); return; } var old = document.getElementById('cf-article'); if (old) { old.remove(); return; } var box = document.createElement('div'); box.id = 'cf-article'; box.style.cssText = 'position:fixed;inset:6% 8%;z-index:2147483003;background:#fff;border-radius:16px;' + 'box-shadow:0 20px 60px rgba(0,0,0,.35);display:flex;flex-direction:column;overflow:hidden;' + 'font:13px/1.7 -apple-system,"Segoe UI",sans-serif;color:#1c1c1e'; box.innerHTML = '
' + '正文提取' + '' + '' + '' + '' + '' + '
' + ''; var ta = box.querySelector('#cf-text'); ta.value = txt; box.querySelector('#cf-len').textContent = txt.length + ' 字 · ' + txt.split('\n').filter(function (x) { return x.trim(); }).length + ' 段'; box.querySelector('#cf-copy2').onclick = function () { if (copyText(ta.value)) toast('已复制 ' + ta.value.length + ' 字'); else toast('复制失败'); }; box.querySelector('#cf-txt').onclick = function () { var name = (document.title || 'article').replace(/[\\/:*?"<>|]/g, '_').slice(0, 60) + '.txt'; saveBlob(new Blob([ta.value], { type: 'text/plain;charset=utf-8' }), name); toast('已保存 ' + name); }; box.querySelector('#cf-x2').onclick = function () { box.remove(); }; document.body.appendChild(box); } /* ---------- 8) 表格导出 CSV ---------- */ function cellText(td) { var t = String(td.innerText || td.textContent || '').replace(/\s+/g, ' ').trim(); return t; } function csvEscape(v) { var s = String(v == null ? '' : v); if (/[",\n\r]/.test(s)) return '"' + s.replace(/"/g, '""') + '"'; return s; } function tableToCsv(table) { var rows = []; var trs = table.querySelectorAll('tr'); var maxCols = 0; var grid = []; for (var i = 0; i < trs.length; i++) { var tr = trs[i]; var cells = tr.children, line = []; for (var j = 0; j < cells.length; j++) { var c = cells[j]; if (!/^(TD|TH)$/.test(c.tagName)) continue; var span = parseInt(c.getAttribute('colspan') || '1', 10) || 1; line.push(cellText(c)); for (var k = 1; k < span; k++) line.push(''); } if (line.length) { grid.push(line); if (line.length > maxCols) maxCols = line.length; } } if (!grid.length) return ''; grid.forEach(function (line) { while (line.length < maxCols) line.push(''); rows.push(line.map(csvEscape).join(',')); }); /* BOM 让 Excel 正确识别 UTF-8 */ return '\ufeff' + rows.join('\r\n'); } function exportTable(table, idx) { var csv = tableToCsv(table); if (!csv) { toast('这个表格没内容'); return; } var name = 'table_' + (idx + 1) + '_' + new Date().toISOString().slice(0, 10) + '.csv'; saveBlob(new Blob([csv], { type: 'text/csv;charset=utf-8' }), name); var n = (csv.match(/\r\n/g) || []).length + 1; toast('已导出 ' + n + ' 行 → ' + name); } /* 给页面上每个表格挂一个「导出」角标 */ function markTables() { var tables = document.querySelectorAll('table'); for (var i = 0; i < tables.length; i++) { var t = tables[i]; try { if (t.dataset.cfMark === '1') continue; var rows = t.querySelectorAll('tr').length; if (rows < 2) continue; /* 单行表格跳过(多是布局表格) */ var cols = 0; var firstTr = t.querySelector('tr'); if (firstTr) cols = firstTr.children.length; if (cols < 2 && rows < 3) continue; } catch (e) { continue; } try { t.dataset.cfMark = '1'; } catch (e) {} var btn = document.createElement('button'); btn.textContent = '导出 CSV'; btn.style.cssText = 'position:absolute;right:6px;top:6px;z-index:2147482000;' + 'background:#34c759;color:#fff;border:none;border-radius:7px;padding:4px 9px;' + 'font:600 11px/1.4 -apple-system,"Segoe UI",sans-serif;cursor:pointer;' + 'box-shadow:0 4px 12px rgba(52,199,89,.35);opacity:.92'; btn.onclick = function (ev) { ev.preventDefault(); ev.stopPropagation(); exportTable(this._cfTable, this._cfIdx); return false; }; btn._cfTable = t; btn._cfIdx = i; /* 表格容器加 relative,保证角标定位在表格右上角 */ var wrap = t.parentElement; try { var pos = getComputedStyle(wrap).position; if (pos === 'static') wrap.style.position = 'relative'; wrap.appendChild(btn); } catch (e) { try { t.appendChild(btn); } catch (e2) {} } } } /* ---------- 面板 ---------- */ var host = null, root = null, dot = null, tip = null; var CSS = [ '.dot{position:fixed;right:14px;bottom:56px;width:38px;height:38px;border-radius:50%;', 'background:linear-gradient(145deg,#34c759,#28a745);color:#fff;border:none;cursor:pointer;', 'font:600 13px/1 -apple-system,"Segoe UI",sans-serif;z-index:2147483000;', 'box-shadow:0 8px 20px rgba(52,199,89,.4);display:flex;align-items:center;justify-content:center}', '.dot.off{background:linear-gradient(145deg,#8e8e93,#6c6c70);box-shadow:0 8px 20px rgba(0,0,0,.2)}', '.card{position:fixed;right:14px;bottom:102px;width:236px;z-index:2147483001;', 'background:rgba(255,255,255,.97);border:.5px solid rgba(0,0,0,.1);border-radius:14px;', 'padding:12px 14px;font:13px/1.7 -apple-system,"Segoe UI",sans-serif;color:#1c1c1e;', 'box-shadow:0 12px 34px rgba(0,0,0,.22);display:none}', '.card h4{margin:0 0 8px;font-size:13px}', '.row{display:flex;justify-content:space-between;color:#8e8e93;font-size:11.5px;margin-bottom:6px}', '.row b{color:#1c1c1e}', '.sw{display:flex;align-items:center;justify-content:space-between;margin:10px 0 4px;font-size:12.5px}', '.tg{width:44px;height:24px;border-radius:99px;background:#e5e5ea;position:relative;cursor:pointer;transition:.2s}', '.tg.on{background:#34c759}', '.tg i{position:absolute;left:2px;top:2px;width:20px;height:20px;border-radius:50%;background:#fff;transition:.2s}', '.tg.on i{left:22px}', '.hint{color:#8e8e93;font-size:11px;margin-top:8px;line-height:1.6}', ].join(''); function toast(t) { if (tip) { tip.textContent = t; tip.style.opacity = '1'; return; } tip = document.createElement('div'); tip.textContent = t; tip.style.cssText = 'position:fixed;left:50%;top:18px;transform:translateX(-50%);z-index:2147483002;' + 'background:rgba(28,28,30,.92);color:#fff;padding:8px 16px;border-radius:99px;' + 'font:600 12.5px/1.4 -apple-system,sans-serif;transition:opacity .3s'; document.body.appendChild(tip); setTimeout(function () { if (tip) { tip.style.opacity = '0'; setTimeout(function () { if (tip) { tip.remove(); tip = null; } }, 400); } }, 1400); } function render() { if (!dot) return; dot.classList.toggle('off', !S.on); dot.title = S.on ? '复制解锁:已开启(点击设置)' : '复制解锁:已关闭'; try { if (root) { root.getElementById('st').textContent = S.on ? '已开启' : '已关闭'; var sw = root.getElementById('sw'); if (sw) sw.classList.toggle('on', S.on); root.getElementById('a1').textContent = S.removedAttrs; root.getElementById('a2').textContent = S.removedClasses; root.getElementById('a3').textContent = S.blockedCalls || 0; } } catch (e) {} } function build() { if (!document.body || document.getElementById('copyfree-host')) return; host = document.createElement('div'); host.id = 'copyfree-host'; root = host.attachShadow({ mode: 'open' }); var st = document.createElement('style'); st.textContent = CSS; root.appendChild(st); dot = document.createElement('button'); dot.className = 'dot'; dot.textContent = '解开'; root.appendChild(dot); var card = document.createElement('div'); card.className = 'card'; card.innerHTML = '

网页复制解锁

' + '
状态已开启
' + '
解除限制
' + '
清理内联事件0
' + '
清理禁选样式0
' + '
拦截 preventDefault0
' + '
正文提取复制' + '
' + '
表格转 CSV' + '
' + '
图片原图下载' + '
' + '
Alt + C 强制复制选中
Shift + Alt + C 复制全文
Shift + Alt + I 图片面板
'; root.appendChild(card); document.body.appendChild(host); dot.onclick = function () { card.style.display = card.style.display === 'block' ? 'none' : 'block'; }; var imgBtn = root.getElementById('imgbtn'); if (imgBtn) imgBtn.onclick = function () { imgPanel(); }; var artBtn = root.getElementById('artbtn'); if (artBtn) artBtn.onclick = function () { articlePanel(); }; var csvBtn = root.getElementById('csvbtn'); if (csvBtn) csvBtn.onclick = function () { markTables(); var n = document.querySelectorAll('table[data-cf-mark="1"]').length; toast(n ? '已标记 ' + n + ' 个表格,点角标导出' : '本页没找到可导出的表格'); }; var sw = root.getElementById('sw'); sw.onclick = function () { S.on = !S.on; try { localStorage.setItem(KEY, S.on ? '1' : '0'); } catch (e) {} applyStyle(); render(); }; render(); } function boot() { applyStyle(); try { setTimeout(markTables, 1200); setInterval(markTables, 4000); } catch (e) {} stripInline(document); stripClasses(document); build(); /* 动态内容:每 2 秒补扫一次(低成本) */ setInterval(function () { if (!S.on) return; stripClasses(document); }, 2000); window.addEventListener('load', function () { stripInline(document); stripClasses(document); }); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', boot); } else { boot(); } document.addEventListener('keydown', function (e) { if (e.altKey && e.shiftKey && (e.key === 'C' || e.key === 'c' || e.code === 'KeyC')) { e.preventDefault(); try { copyArticle(); } catch (err) {} } if (e.altKey && e.shiftKey && (e.key === 'I' || e.key === 'i' || e.code === 'KeyI')) { e.preventDefault(); try { imgPanel(); } catch (err) {} } }, true); window.__copyfree = { state: S, forceCopy: forceCopy, imgPanel: imgPanel, collectImages: collectImages, origUrl: origUrl, articlePanel: articlePanel, copyArticle: copyArticle, exportTable: exportTable, markTables: markTables }; })();