Skip to content

Commit

Permalink
Merge pull request #11 from denkiwakame/openreview
Browse files Browse the repository at this point in the history
OpenReview URL support
  • Loading branch information
denkiwakame authored Jan 17, 2024
2 parents 5c4919b + 1d56e17 commit 7088486
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 9 deletions.
10 changes: 7 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "arxiv2notion",
"description": "easy-to-use arXiv clipper for notion.so",
"version": "1.1.0",
"version": "1.2.0",
"icons": {
"128": "icon128.png"
},
Expand All @@ -16,8 +16,12 @@
"page": "options.html",
"open_in_tab": false
},
"permissions": ["activeTab", "storage"],
"host_permissions": ["*://api.notion.com/*", "*://www.notion.so/*"],
"permissions": ["tabs", "activeTab", "storage"],
"host_permissions": [
"*://api.notion.com/*",
"*://www.notion.so/*",
"*://openreview.net/*"
],
"content_security_policy": {
"extension_pages": "script-src 'self'; object-src 'self'"
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "arxiv2notion",
"version": "1.1.0",
"version": "1.2.0",
"description": "easy-to-use arXiv clipper",
"contributors": [
"denkiwakame<[email protected]>",
Expand Down
5 changes: 3 additions & 2 deletions src/js/notion.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export default class Notion {
const paperUrl = data.url;
const authorsFormatted = data.authors.join(', ');
const published = data.published;
const publisher = data.publisher;
const comment = data.comment;
const authors = authorsFormatted.split(', ');
const authorsMultiSelect = authors.map((author) => {
Expand All @@ -129,7 +130,7 @@ export default class Notion {
Publisher: {
id: 'conference',
type: 'select',
select: { name: 'arXiv' },
select: { name: publisher },
},
URL: {
id: 'url',
Expand Down Expand Up @@ -207,7 +208,7 @@ export default class Notion {
body: JSON.stringify(body),
});
const data = await res.json();
data.results.forEach((result) => {
data.results?.forEach((result) => {
const option = `<option value=${result.id}>${result.title[0].text.content}</option>`;
document
.getElementById('js-select-database')
Expand Down
52 changes: 49 additions & 3 deletions src/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,20 @@ class UI {
}, 200);
}
isDebugUrl(url) {
return url && url.indexOf('chrome-extension://') === 0;
return url?.startsWith('chrome-extension://') || false;
}
isArxivUrl(url) {
return url && url.indexOf('https://arxiv.org') === 0;
return url?.startsWith('https://arxiv.org') || false;
}
isOpenReviewUrl(url) {
return url?.startsWith('https://openreview.net/') || false;
}
isPDF(url) {
return url && url.split('.').pop() === 'pdf';
}
async getPaperInfo(url) {
if (this.isArxivUrl(url)) return this.getArXivInfo(url);
// if (this.isPDF(url)) return this.getPDFInfo(url); // TODO
if (this.isOpenReviewUrl(url)) return this.getOpenReviewInfo(url);
}
parseArXivId(str) {
const paperId = str.match(/\d+.\d+/);
Expand Down Expand Up @@ -151,6 +154,49 @@ class UI {
url: url,
published: published,
comment: comment,
publisher: 'arXiv',
};
}

async getOpenReviewInfo(url) {
this.showProgressBar();
const id = new URLSearchParams(new URL(url).search).get('id');

const res = await fetch(url);
const html = await res.text();
const parser = new DOMParser();
const xml = parser.parseFromString(html, 'text/html');

const authors = Array.from(
xml.querySelectorAll('meta[name="citation_author"]')
).map((author) => {
return author.getAttribute('content');
});
const paperTitle = xml
.querySelector('meta[name="citation_title"]')
.getAttribute('content');

const abst = xml
.querySelector('meta[name="citation_abstract"]')
.getAttribute('content');

const date = xml
.querySelector('meta[name="citation_online_date"]')
.getAttribute('content');
// -> ISO 8601 date string
const published = new Date(date).toISOString().split('T')[0];
const comment = 'none';

this.setFormContents(paperTitle, abst, comment, authors);
return {
id: id,
title: paperTitle,
abst: abst,
authors: authors,
url: url,
published: published,
comment: comment,
publisher: 'OpenReview',
};
}

Expand Down

0 comments on commit 7088486

Please sign in to comment.