From ee174e8eafd40332a54950fde9f59425415e1a70 Mon Sep 17 00:00:00 2001 From: Elad Richardson Date: Fri, 31 Dec 2021 12:20:32 +0200 Subject: [PATCH] Fixed bug with new paperswithcode version --- README.md | 86 +++++++++++++++++++++--------------------- manifest.json | 2 +- src/background.js | 58 ++++++++++++++-------------- src/content_arxiv.js | 18 ++++----- src/content_scholar.js | 24 ++++++------ 5 files changed, 95 insertions(+), 93 deletions(-) diff --git a/README.md b/README.md index 3220431..300cbca 100644 --- a/README.md +++ b/README.md @@ -1,42 +1,44 @@ -# Scholar With Code - -[![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`. - -

- -

-
-

- -

- -## Recent Updates -**`2020.07.15`**: Added arXiv Support - -**`2020.06.24`**: Chrome Extension release - -**`2020.06.16`**: First Release - - -## 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. - -I've noticed that a thing that I do a lot is to start from a paper I know, go through the "Papers that cite this work" page on `Google Scholar`, and then for each paper check whether it has a code implementation using `Papers With Code`. - -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`. - -

- -

- - ## Installation - - Extension is available in the [Chrome Web Store](https://chrome.google.com/webstore/detail/scholar-with-code/nlnjigejpgngahmoainkakaafabijeki). Alternatively you can download the project directory and drag it to your chrome extensions. - - -## TODOs -- [x] Publish to Chrome Web Store -- [x] Check how to remove permissions to all sites -- [x] Support arXiv.org +# Scholar With Code + +[![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 implementations (via `Papers With Code`) for articles listed on `Google Scholar` and `arXiv`. + +

+ +

+
+

+ +

+ +## Recent Updates +**`2021.11.18`**: Minor fix to support changes in `Papers With Code` + +**`2020.07.15`**: Added arXiv Support + +**`2020.06.24`**: Chrome Extension release + +**`2020.06.16`**: First Release + + +## 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. + +I've noticed that a thing that I do a lot is to start from a paper I know, go through the "Papers that cite this work" page on `Google Scholar`, and then for each paper check whether it has a code implementation using `Papers With Code`. + +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`. + +

+ +

+ + ## Installation + + Extension is available in the [Chrome Web Store](https://chrome.google.com/webstore/detail/scholar-with-code/nlnjigejpgngahmoainkakaafabijeki). Alternatively you can download the project directory and drag it to your chrome extensions. + + +## TODOs +- [x] Publish to Chrome Web Store +- [x] Check how to remove permissions to all sites +- [x] Support arXiv.org diff --git a/manifest.json b/manifest.json index d920707..2bfd361 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "Scholar with Code", - "version": "1.0.3", + "version": "1.0.4", "icons":{ "493":"docs/logo.png" }, diff --git a/src/background.js b/src/background.js index eee04b9..216f0e3 100644 --- a/src/background.js +++ b/src/background.js @@ -1,29 +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 - } - } - sendResponse({txt: txt, paper_link: paper_link, payload: request.payload}); - } - } - xhr.send(); - return true; -}); +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[1].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; +}); diff --git a/src/content_arxiv.js b/src/content_arxiv.js index 0de7d6d..7cbc37b 100644 --- a/src/content_arxiv.js +++ b/src/content_arxiv.js @@ -1,9 +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); -}); +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); +}); diff --git a/src/content_scholar.js b/src/content_scholar.js index 096633a..3b7fd51 100644 --- a/src/content_scholar.js +++ b/src/content_scholar.js @@ -1,12 +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); - }); -} +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); + }); +}