// ==UserScript==
// @name DBLP Bib Helper
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Copy BibTeX records quickly within search results.
// @author yusanshi
// @license MIT
// @match https://dblp.org/search?*
// @icon https://www.google.com/s2/favicons?sz=64&domain=dblp.org
// @require https://cdn.jsdelivr.net/npm/arrive@2.4.1/minified/arrive.min.js
// @require https://cdn.jsdelivr.net/gh/ORCID/bibtexParseJs@b55dc9e4015f9dec67921f56f8f23dadb71697ad/bibtexParse.min.js
// @grant GM_addStyle
// @downloadURL none
// ==/UserScript==
(function () {
'use strict';
if (new URL(document.location).searchParams.get('clean') === 'true') {
// https://stackoverflow.com/questions/4277792/hide-all-elements-except-one-div-and-its-child-element
// DBLP has loaded jquery 3.x itself, no need to @require it.
$('#completesearch-publs')
.show()
.parentsUntil('body')
.addBack()
.siblings()
.hide();
// why $('#completesearch-facets').hide() not working
GM_addStyle('#completesearch-facets {display:none!important}');
}
const entrySelector = '#completesearch-publs li.entry';
document.arrive(entrySelector, { existing: true }, async function () {
this.querySelector('cite').insertAdjacentHTML(
'beforeend',
'
'
);
const entryIndex = Array.from(
document.querySelectorAll(entrySelector)
).indexOf(this);
await new Promise((r) => setTimeout(r, 3000 * entryIndex));
const bibURL = this.querySelector(
'nav.publ > ul > li:nth-child(2) > div.head > a'
).href.replace('.html', '.bib');
const bibText = await fetch(bibURL).then((e) => e.text());
const bibJSON = bibtexParse.toJSON(bibText);
bibJSON[0].citationKey = bibJSON[0].citationKey.replace(
/[^a-zA-Z0-9]+/g,
'_'
);
this.querySelector('.bib-textarea').value = bibtexParse.toBibtex(
bibJSON,
false
);
});
})();