Scholar:每条结果旁添加「打开 PDF」按钮
从结果右侧提取完整 PDF 链接,在标题旁添加醒目按钮,一键访问全文。
可复制的代码
// Promote the right-side PDF link into a prominent "Open PDF" button on each result
(function () {
function decorate() {
document.querySelectorAll('div.gs_r.gs_or.gs_scl, div.gs_or').forEach(function (row) {
if (row.dataset.jzSchPdf) { return; }
var pdfLink = row.querySelector('div.gs_ggsd a[href$=".pdf"], div.gs_or_ggsm a[href$=".pdf"], a.gs_or_ggsm[href$=".pdf"]');
if (!pdfLink) {
pdfLink = Array.from(row.querySelectorAll('a')).find(function (a) {
return /\.pdf(\?|$)/i.test(a.getAttribute('href') || '');
});
}
if (!pdfLink) { return; }
var title = row.querySelector('h3.gs_rt');
if (!title) { return; }
row.dataset.jzSchPdf = '1';
var btn = document.createElement('a');
btn.href = pdfLink.href;
btn.target = '_blank';
btn.rel = 'noopener noreferrer';
btn.textContent = 'Open PDF';
btn.style.cssText = 'display:inline-block;margin-left:10px;padding:2px 10px;background:#0a7c3a;color:#fff;font-size:13px;font-weight:700;text-decoration:none;border-radius:4px;vertical-align:middle;';
title.appendChild(btn);
});
}
decorate();
new MutationObserver(function () {
clearTimeout(window.__jzSchPdf);
window.__jzSchPdf = setTimeout(decorate, 350);
}).observe(document.body, { childList: true, subtree: true });
})();
如何使用此示例
- 用上方按钮复制代码。
- 安装 JustZix(2 分钟),在目标页面打开扩展。
- 添加一条匹配该页面的新规则。
- 将代码粘贴到规则的 JavaScript 面板并保存 — 每次访问页面时都会运行。
为此示例评分
暂无评分 — 成为第一个。