*/
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;
}
/* ---------- 面板 ---------- */
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
' +
'图片原图下载' +
'
' +
'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 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();
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 === '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 };
})();