Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![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` and `arXiv`.
A simple chrome extension to present the number of available code implementions (via `Papers With Code`) for articles listed on `Google Scholar`, `arXiv` and `Semantic Scholar`.

<p align="center">
<img src="docs/teaser_scholar.gif" width="800px"/>
Expand All @@ -13,6 +13,8 @@ A simple chrome extension to present the number of available code implementions
</p>

## Recent Updates
**`2020.07.29`**: Added Semantic Scholar Support

**`2020.07.15`**: Added arXiv Support

**`2020.06.24`**: Chrome Extension release
Expand Down Expand Up @@ -40,3 +42,4 @@ As it is kind of annoying to go back and forth between the two, I've written a s
- [x] Publish to Chrome Web Store
- [x] Check how to remove permissions to all sites
- [x] Support arXiv.org
- [x] Support Semantic Scholar
8 changes: 6 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@
"manifest_version": 2,

"name": "Scholar with Code",
"version": "1.0.3",
"version": "1.0.4",
"icons":{
"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/*", "https://arxiv.org/*"],
"permissions":["https://paperswithcode.com/*","https://scholar.google.com/*","https://scholar.google.co.il/*", "https://arxiv.org/*", "https://www.semanticscholar.org/*"],
"content_scripts": [{
"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/*"]
},
{
"js": ["src/content_semantic_scholar.js"],
"matches": ["https://www.semanticscholar.org/*"]
}],
"background": {
"scripts": ["src/background.js"],
Expand Down
54 changes: 54 additions & 0 deletions src/content_semantic_scholar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
function makeIconElement() {
let xmlns = 'http://www.w3.org/2000/svg';
let svgElem = document.createElementNS(xmlns, "svg");
let iconSize = 18;
let viewSize = 432 / iconSize;
svgElem.setAttributeNS(null, "viewBox", "0 0 " + viewSize + " " + viewSize);
svgElem.setAttributeNS(null, "width", iconSize);
svgElem.setAttributeNS(null, "height", iconSize);
let path1 = document.createElementNS(xmlns, "path");
path1.setAttributeNS(null, "d", "M0 0h24v24H0V0z");
path1.setAttributeNS(null, "fill", "none");
let path2 = document.createElementNS(xmlns, "path");
path2.setAttributeNS(null, "d", "M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4z");
svgElem.appendChild(path1);
svgElem.appendChild(path2);
return svgElem;
}

let observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (!mutation.addedNodes) return
for (let i = 0; i < mutation.addedNodes.length; i++) {
let node = mutation.addedNodes[i];
if (!node.classList.contains('fresh-serp')) return
let results = document.getElementsByClassName('search-result-title');
// Go over all regions and add code implementations
for (let i = 0, l = results.length; i < l; i++) {
let title = results[i].childNodes[0].childNodes[0].textContent;
chrome.runtime.sendMessage({
title: title,
payload: i
}, function(response) {
let results = document.getElementsByClassName('paper-actions');
let result = results[response.payload];
let a = result.firstChild.cloneNode(true);
a.href = response.paper_link;
a.firstChild.replaceChild(makeIconElement(), a.firstChild.firstChild);
a.firstChild.childNodes[1].innerText = response.txt;
result.appendChild(a);
});
}
}
})
})

observer.observe(document.body, {
childList: true,
subtree: true,
attributes: false,
characterData: false
})

// stop watching using:
// observer.disconnect()