arXiv:一键复制 BibTeX 按钮
在论文标题旁添加按钮,一键将含 arXiv ID、作者和年份的 BibTeX 条目复制到剪贴板。
可复制的代码
// Add a one-click "Copy BibTeX" button next to the paper title
(function () {
function bibtex() {
var id = (location.pathname.match(/\/abs\/([\w.\-\/]+)/) || [])[1];
if (!id) { return null; }
var titleEl = document.querySelector('h1.title');
var title = titleEl ? titleEl.textContent.replace(/^\s*Title:\s*/i, '').trim() : id;
var authorEls = document.querySelectorAll('.authors a');
var authors = Array.from(authorEls).map(function (a) { return a.textContent.trim(); }).join(' and ');
var year = ((document.querySelector('.dateline, .submission-history') || {}).textContent || '').match(/(19|20)\d{2}/);
year = year ? year[0] : '';
var key = id.replace(/[^a-zA-Z0-9]/g, '');
return '@article{arxiv' + key + ',\n title = {' + title + '},\n author = {' + authors + '},\n journal= {arXiv preprint arXiv:' + id + '},\n year = {' + year + '}\n}';
}
function mount() {
if (document.getElementById('jzArxBibBtn')) { return; }
var host = document.querySelector('h1.title') || document.querySelector('#abs');
if (!host) { return; }
var btn = document.createElement('button');
btn.id = 'jzArxBibBtn';
btn.type = 'button';
btn.textContent = 'Copy BibTeX';
btn.style.cssText = 'margin-left:10px;padding:4px 10px;background:#b31b1b;color:#fff;border:0;border-radius:4px;font-size:13px;cursor:pointer;font-weight:600;';
btn.addEventListener('click', function () {
var t = bibtex();
if (!t) { return; }
navigator.clipboard.writeText(t).then(function () {
btn.textContent = 'Copied!';
setTimeout(function () { btn.textContent = 'Copy BibTeX'; }, 1500);
});
});
host.appendChild(btn);
}
mount();
new MutationObserver(mount).observe(document.body, { childList: true, subtree: true });
})();
如何使用此示例
- 用上方按钮复制代码。
- 安装 JustZix(2 分钟),在目标页面打开扩展。
- 添加一条匹配该页面的新规则。
- 将代码粘贴到规则的 JavaScript 面板并保存 — 每次访问页面时都会运行。
为此示例评分
暂无评分 — 成为第一个。