Skip to content

Commit 26b01d7

Browse files
authored
Add support for the old style arxiv ID (#15)
* Add a regex for old id format * Simplify regexes
1 parent a44c1b6 commit 26b01d7

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/js/popup.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ UIKit.use(Icons);
1212

1313
const TEST_URL = 'https://arxiv.org/abs/2308.04079';
1414
const ARXIV_API = 'http://export.arxiv.org/api/query/search_query';
15-
1615
class UI {
1716
constructor() {
1817
this.setupProgressBar();
@@ -101,10 +100,9 @@ class UI {
101100
if (this.isArxivUrl(url)) return this.getArXivInfo(url);
102101
if (this.isOpenReviewUrl(url)) return this.getOpenReviewInfo(url);
103102
}
104-
parseArXivId(str) {
105-
const paperId = str.match(/\d+.\d+/);
106-
return paperId;
107-
}
103+
// ref: https://info.arxiv.org/help/arxiv_identifier.html
104+
// e.g. (new id format: 2404.16782) | (old id format: hep-th/0702063)
105+
parseArXivId = (str) => str.match(/(\d+\.\d+$)|((\w|-)+\/\d+$)/)?.[0];
108106

109107
setFormContents(paperTitle, abst, comment, authors) {
110108
document.getElementById('js-title').value = paperTitle;
@@ -135,7 +133,7 @@ class UI {
135133
console.log(xmlData);
136134

137135
const entry = xmlData.querySelector('entry');
138-
const id = entry.querySelector('id')?.textContent.match(/\d+\.\d+/)?.[0];
136+
const id = this.parseArXivId(entry.querySelector('id')?.textContent);
139137
const paperTitle = entry.querySelector('title').textContent;
140138
const abst = entry.querySelector('summary').textContent;
141139
const authors = Array.from(entry.querySelectorAll('author')).map(

0 commit comments

Comments
 (0)