Skip to content

Commit

Permalink
Merge pull request #3 from idow09/master
Browse files Browse the repository at this point in the history
Added support for arXiv.org
  • Loading branch information
eladrich authored Jul 15, 2020
2 parents 9f74be2 + 6d538f8 commit c213ea8
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 53 deletions.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@

[![Chrome Web Store](https://img.shields.io/chrome-web-store/v/nlnjigejpgngahmoainkakaafabijeki)](https://chrome.google.com/webstore/detail/scholar-with-code/nlnjigejpgngahmoainkakaafabijeki)

A simple chrome extension to present the number of available code implementions (via `Papers With Code`) for articles listed on `Google Scholar`.
A simple chrome extension to present the number of available code implementions (via `Papers With Code`) for articles listed on `Google Scholar` and `arXiv`.

<p align="center">
<img src="teaser.gif" width="800px"/>
</p>
<img src="docs/teaser_scholar.gif" width="800px"/>
</p>
<br>
<p align="center">
<img src="docs/teaser_arxiv.gif" width="800px"/>
</p>

## Recent Updates
**`2020.06.24`**: Chrome Extension release

**`2020.06.16`**: First Release

**`2020.07.15`**: arXiv Support


## Why?
Two of the most used tools for me during research are `Google Scholar` and `Papers with Code`, together giving a full view of citations and code implementations.
Expand All @@ -22,7 +28,7 @@ I've noticed that a thing that I do a lot is to start from a paper I know, go th
As it is kind of annoying to go back and forth between the two, I've written a small chrome extension that shows whether the paper has code implementation and links to the matching page on `Papers with Code`.

<p align="center">
<img src="teaser.png" width="800px"/>
<img src="docs/teaser_scholar.png" width="800px"/>
</p>

## Installation
Expand All @@ -33,3 +39,4 @@ As it is kind of annoying to go back and forth between the two, I've written a s
## TODOs
- [x] Publish to Chrome Web Store
- [x] Check how to remove permissions to all sites
- [x] Support arXiv.org
5 changes: 0 additions & 5 deletions content.js

This file was deleted.

File renamed without changes
Binary file added docs/teaser_arxiv.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
18 changes: 10 additions & 8 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@
"manifest_version": 2,

"name": "Scholar with Code",
"version": "1.0.2",
"version": "1.0.3",
"icons":{
"493":"logo.png"
"493":"docs/logo.png"
},
"description": "An extension to show code implementations from Papers with Code directly in Google Scholar.",
"permissions":["https://paperswithcode.com/*","https://scholar.google.com/*","https://scholar.google.co.il/*"],
"description": "An extension to show code implementations from Papers with Code directly in Google Scholar.",
"permissions":["https://paperswithcode.com/*","https://scholar.google.com/*","https://scholar.google.co.il/*", "https://arxiv.org/*"],
"content_scripts": [{
"js": ["content.js"],
"js": ["src/content_scholar.js"],
"matches": ["https://scholar.google.com/*","https://scholar.google.co.il/*"]
},
{
"js": ["src/content_arxiv.js"],
"matches": ["https://arxiv.org/abs/*"]
}],
"background": {
"scripts": ["background.js"],
"scripts": ["src/background.js"],
"persistent": false
}


}
65 changes: 29 additions & 36 deletions background.js → src/background.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,29 @@
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
var xhr = new XMLHttpRequest();
xhr.responseType = "document"
var paperurl = "https://paperswithcode.com/search?q_meta=&q="+request.title.replace(/\s/g,"+") //Search in PapersWithCode
xhr.open("GET", paperurl, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
var paper_link = paperurl; // Initialize with search query
var elems = xhr.response.getElementsByClassName('col-lg-9 item-content')
if (elems.length == 0)
{
var txt = "no code implementation"; // No results
}
else {
var title = elems[0].childNodes[1].textContent.toUpperCase()
if (title == request.title.toUpperCase()){
var txt = elems[0].childNodes[3].childNodes[3].text;
paper_link = elems[0].childNodes[1].childNodes[0].href; // If exist, use page url
}
else {
var txt = "no code implementation"; // No result with same title
}
}
var code_str = "var panels = document.getElementsByClassName('gs_ri');"
+"var a = document.createElement('a');"
+"a.innerText =\"" + txt +"\";"
+"a.href =\"" + paper_link +"\";"
+ "panels[" + request.ind + "].childNodes[3].appendChild(a);"

chrome.tabs.executeScript( {
code: code_str
});
}
}
xhr.send();
});
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
var xhr = new XMLHttpRequest();
xhr.responseType = "document"
var paperurl = "https://paperswithcode.com/search?q_meta=&q="+request.title.replace(/\s/g,"+") //Search in PapersWithCode
xhr.open("GET", paperurl, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
var paper_link = paperurl; // Initialize with search query
var elems = xhr.response.getElementsByClassName('col-lg-9 item-content')
if (elems.length == 0)
{
var txt = "no code implementation"; // No results
}
else {
var title = elems[0].childNodes[1].textContent.toUpperCase()
if (title == request.title.toUpperCase()){
var txt = elems[0].childNodes[3].childNodes[3].text;
paper_link = elems[0].childNodes[1].childNodes[0].href; // If exist, use page url
}
else {
var txt = "no code implementation"; // No result with same title
}
}
sendResponse({txt: txt, paper_link: paper_link, payload: request.payload});
}
}
xhr.send();
return true;
});
9 changes: 9 additions & 0 deletions src/content_arxiv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var paper_title = document.querySelector("#abs h1").childNodes[1].textContent;
chrome.runtime.sendMessage({title: paper_title}, function(response) {
var a = document.createElement('a');
a.innerText = response.txt;
a.href = response.paper_link;
var li = document.createElement('li');
li.appendChild(a);
document.querySelector(".full-text ul").appendChild(li);
});
12 changes: 12 additions & 0 deletions src/content_scholar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var panels = document.getElementsByClassName('gs_ri');
// Go over all regions and add code implementations
for (var i = 0, l = panels.length; i < l; i++) {
var title = panels[i].childNodes[0].textContent;
chrome.runtime.sendMessage({title: title, payload: i}, function(response) {
var panels = document.getElementsByClassName('gs_ri');
var a = document.createElement('a');
a.innerText = response.txt;
a.href = response.paper_link;
panels[response.payload].childNodes[3].appendChild(a);
});
}

0 comments on commit c213ea8

Please sign in to comment.