Skip to content

Commit 58ab638

Browse files
authored
Merge pull request #190 from vict0rsch/oup
2 parents 6c2258f + b3b2c27 commit 58ab638

File tree

7 files changed

+85
-9
lines changed

7 files changed

+85
-9
lines changed

src/popup/js/handlers.js

-1
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,6 @@ const hideTitleTooltip = (id, isPopup) => {
484484
};
485485

486486
const getHandleTitleTooltip = (func, delay, isPopup) => {
487-
console.log("delay: ", delay);
488487
return (e) => {
489488
const id = isPopup ? global.state.currentId : eventId(e);
490489
let timerId = global.state.timerIdMap.get(e.target) ?? 0;

src/popup/min/popup.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/shared/js/utils/bibtexParser.js

+33-1
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,30 @@ function BibtexParser() {
329329
};
330330
}
331331

332+
/**
333+
* Removes surrounding braces of `{some title is wrapped}`
334+
* but not of `{some} title is {wrapped}`
335+
* @param {string} str
336+
* @returns {string} str without surrounding braces
337+
*/
338+
const safeRemoveSurroundingBraces = (str) => {
339+
let opened = 0;
340+
let closed = 0;
341+
let remove = true;
342+
for (const c of str.slice(1, -1)) {
343+
if (c === "{") opened++;
344+
if (c === "}") closed++;
345+
if (closed > opened) {
346+
remove = false;
347+
break;
348+
}
349+
}
350+
if (remove) {
351+
return str.slice(1, -1);
352+
}
353+
return str;
354+
};
355+
332356
const bibtexToObject = (bibtex) => {
333357
var b = new BibtexParser();
334358
b.setInput(bibtex);
@@ -339,6 +363,11 @@ const bibtexToObject = (bibtex) => {
339363
entryType: entry.entryType,
340364
citationKey: entry.citationKey,
341365
};
366+
for (const [key, value] of Object.entries(obj)) {
367+
if (value.startsWith("{") && value.endsWith("}")) {
368+
obj[key] = safeRemoveSurroundingBraces(value);
369+
}
370+
}
342371
return obj;
343372
};
344373

@@ -361,7 +390,10 @@ const bibtexToString = (bibtex) => {
361390
const keyLen = Math.max(...Object.keys(bibtex).map((k) => k.length));
362391
for (const key in bibtex) {
363392
if (bibtex.hasOwnProperty(key) && bibtex[key]) {
364-
const value = bibtex[key].replaceAll(/\s+/g, " ").trim();
393+
let value = bibtex[key].replaceAll(/\s+/g, " ").trim();
394+
if (value.startsWith("{") && value.endsWith("}")) {
395+
value = safeRemoveSurroundingBraces(value);
396+
}
365397
const bkey = key + " ".repeat(keyLen - key.length);
366398
bstr += `\t${bkey} = {${value}},\n`;
367399
}

src/shared/js/utils/config.js

+7
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ global.knownPaperPages = {
189189
"openreview.net/pdf",
190190
"openreview.net/attachment",
191191
],
192+
oup: [
193+
(url) =>
194+
(url
195+
.split("https://academic.oup.com/")[1]
196+
?.split("/")[1]
197+
?.indexOf("article") ?? -1) >= 0,
198+
],
192199
plos: [(url) => /journals\.plos\.org\/.+\/article.+id=/gi.test(url)],
193200
pmc: ["ncbi.nlm.nih.gov/pmc/articles/PMC"],
194201
pmlr: ["proceedings.mlr.press/"],

src/shared/js/utils/paper.js

+13
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ const paperToAbs = (paper) => {
178178
case "mdpi":
179179
abs = paper.pdfLink.split("/pdf")[0];
180180
break;
181+
case "oup":
182+
abs = `https://doi.org/${paper.doi}`;
183+
break;
181184

182185
default:
183186
abs = "https://xkcd.com/1969/";
@@ -288,6 +291,9 @@ const paperToPDF = (paper) => {
288291
case "mdpi":
289292
break;
290293

294+
case "oup":
295+
break;
296+
291297
case "website":
292298
abs = paper.pdfLink;
293299
break;
@@ -895,6 +901,13 @@ const parseIdFromUrl = async (url, tab = null) => {
895901
.split("/notes")[0]
896902
);
897903
idForUrl = findPaperForProperty(papers, "mdpi", miniHash(mdpiId));
904+
} else if (is.oup) {
905+
url = noParamUrl(url).split("https://academic.oup.com/").last();
906+
if (isPdfUrl(url)) {
907+
url = url.split("/").slice(0, -1).join("/");
908+
}
909+
const num = url.split("/").slice(2).join("");
910+
idForUrl = findPaperForProperty(papers, "oup", miniHash(num));
898911
} else if (is.localFile) {
899912
idForUrl = is.localFile;
900913
} else if (is.parsedWebsite) {

src/shared/js/utils/parsers.js

+25
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,26 @@ const makeMDPIPaper = async (url) => {
14421442
return { author, bibtex, id, key, note, pdfLink, title, venue, year, doi };
14431443
};
14441444

1445+
const makeOUPPaper = async (url) => {
1446+
url = noParamUrl(url);
1447+
const resourceId = url.split("/").last();
1448+
let bibtex = await fetchText(
1449+
`https://academic.oup.com/Citation/Download?resourceId=${resourceId}&resourceType=3&citationFormat=2`
1450+
);
1451+
const paper = bibtexToObject(bibtex);
1452+
delete paper.abstract;
1453+
bibtex = bibtexToString(paper);
1454+
let { title, year, author, journal, doi, citationKey, eprint } = paper;
1455+
author = flipAndAuthors(author);
1456+
const venue = journal;
1457+
const note = `Published @ ${venue} (${year})`;
1458+
const key = citationKey;
1459+
const num = url.split("https://academic.oup.com/")[1].split("/").slice(2).join("");
1460+
const id = `OUP-${year}_${miniHash(num)}`;
1461+
const pdfLink = eprint?.replaceAll("\\", "") ?? url;
1462+
1463+
return { author, bibtex, id, key, note, pdfLink, title, venue, year, doi };
1464+
};
14451465
// -------------------------------
14461466
// ----- PREPRINT MATCHING -----
14471467
// -------------------------------
@@ -1898,6 +1918,11 @@ const makePaper = async (is, url, tab = false) => {
18981918
if (paper) {
18991919
paper.source = "mdpi";
19001920
}
1921+
} else if (is.oup) {
1922+
paper = await makeOUPPaper(url);
1923+
if (paper) {
1924+
paper.source = "oup";
1925+
}
19011926
} else {
19021927
throw new Error("Unknown paper source: " + JSON.stringify({ is, url }));
19031928
}

src/shared/min/utils.min.js

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)