') + ')', 'gi');
if (regex.test(text)) {
found = true;
var frag = document.createDocumentFragment();
var parts = text.split(regex);
parts.forEach(function(part, i) {
if (i % 2 === 0) {
frag.appendChild(document.createTextNode(part));
} else {
var span = document.createElement('span');
span.className = 'userscript-highlight';
span.textContent = part;
frag.appendChild(span);
}
});
node.parentNode.replaceChild(frag, node);
}
});
} else if (node.nodeType === 1 && node.childNodes) { // element
var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];
if (!skipTags.includes(node.tagName)) {
Array.from(node.childNodes).forEach(highlight);
}
}
}
highlight(document.body);
// Re-highlight on dynamic content
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(m) {
m.addedNodes.forEach(function(node) {
if (node.nodeType === 1 || node.nodeType === 3) highlight(node);
});
});
});
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); }
})();
(function(){
try {
var __m = "*";
var __re = new RegExp('^' + ".*" + ', 'i');
if (__m === '*' || __re.test(location.href)) {
// Strip utm_, fbclid, gclid, etc. from all links on page
(function() {
var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',
'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',
'ref', 'ref_src', 'source', 'medium', 'campaign'];
function cleanUrl(url) {
try {
var u = new URL(url, window.location.origin);
var changed = false;
trackingParams.forEach(function(p) {
if (u.searchParams.has(p)) {
u.searchParams.delete(p);
changed = true;
}
});
return changed ? u.toString() : url;
} catch (e) {
return url;
}
}
function cleanLinks() {
document.querySelectorAll('a[href]').forEach(function(a) {
var clean = cleanUrl(a.href);
if (clean !== a.href) a.href = clean;
});
}
cleanLinks();
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(m) {
m.addedNodes.forEach(function(node) {
if (node.nodeType === 1) {
if (node.tagName === 'A') cleanLinks();
node.querySelectorAll('a[href]').forEach(function(a) {
var clean = cleanUrl(a.href);
if (clean !== a.href) a.href = clean;
});
}
});
});
});
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); }
})();
(function(){
try {
var __m = "youtube.com";
var __re = new RegExp('^' + "youtube\\.com" + ', 'i');
if (__m === '*' || __re.test(location.href)) {
// Auto-enable theater mode on YouTube
(function() {
function tryTheater() {
var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]');
if (btn && !btn.classList.contains('activated')) {
btn.click();
}
}
// Try immediately
tryTheater();
// Try after navigation (SPA)
var lastUrl = location.href;
setInterval(function() {
if (location.href !== lastUrl) {
lastUrl = location.href;
setTimeout(tryTheater, 500);
}
}, 1000);
// Also try on player load
var observer = new MutationObserver(tryTheater);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); }
})();
(function(){
try {
var __m = "*";
var __re = new RegExp('^' + ".*" + ', 'i');
if (__m === '*' || __re.test(location.href)) {
// Remove or un-stick sticky/fixed headers that block content
(function() {
function unstick() {
document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) {
if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {
el.style.position = 'static';
el.style.top = 'auto';
el.style.zIndex = 'auto';
}
});
}
unstick();
var observer = new MutationObserver(unstick);
observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });
})();
}
} catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); }
})();
})();
GitHub - Hugo-YH/ocrMyPDF · GitHub
Repository files navigation 一个基于 ocrmypdf 的 PDF OCR 自动化处理工具,支持中文和英文识别,适用于 macOS 系统。支持拖拽 PDF 文件或文件夹到终端自动处理,并可替换原文件。
🧠 自动识别并 OCR 处理 PDF(中文简体 + 英文) 📁 支持拖拽文件或文件夹,自动遍历 PDF 🔁 可覆盖原始文件或另存为 _ocr.pdf 🚀 自动检测并使用多核 CPU 加速 🔧 集成进度提示与异常处理 🍎 优化支持 macOS(Apple Silicon) 确保你已安装以下工具(macOS 用户建议使用 Homebrew):
brew install ocrmypdf tesseract ghostscript 安装语言包:
brew install tesseract-lang # 或
wget https://github.com/tesseract-ocr/tessdata/raw/main/chi_sim.traineddata \
-P /opt/homebrew/share/tessdata/ 你可以在 /opt/homebrew/bin/ocrmypdf 路径找到程序。
可选:创建 Python 虚拟环境
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt 方法一:运行 Python 脚本(推荐)
根据提示拖入 PDF 文件或文件夹:
📥 PDF OCR 工具已启动,可反复拖拽 PDF 路径到终端中使用
📂 拖入 PDF 文件路径(输入 Q 回车退出):
>> '/Users/you/Documents/example.pdf'
方法二:使用 run.sh 脚本快速启动
参数 含义 --force-ocr 无论是否存在文本层,强制重新 OCR --language 设置语言(此处为 "chi_sim+eng") --image-dpi 图像 DPI,推荐为 300 --tesseract-oem 1 使用 LSTM 引擎 --deskew 自动校正倾斜页面 --output-type pdf 输出 PDF 格式 --jobs auto 自动并行处理(根据 CPU 核心数)
ocrMyPDF/
├── ocrMyPDF.py # 主程序:拖拽文件或文件夹自动识别
├── run.sh # 运行启动脚本
├── requirements.txt # 可选依赖(如果使用虚拟环境)
└── README.md # 当前说明文档
📄 开始处理:example.pdf
✅ 已保存至:example.pdf
如遇以下警告:
DecompressionBombWarning: Image size exceeds limit...
建议预处理图像或使用压缩工具降低分辨率。
输出为 PDF/A,部分元数据可能被清理。 若未能识别中文,请确认是否正确安装 chi_sim.traineddata。 文件太大可能触发 Pillow 的安全限制(默认 250MP 像素)。 如有建议或改进想法,欢迎提出 issue 或直接交流!
You can’t perform that action at this time.