From 1d1b9b49e5b725df4c40b27f9438f3dec53341a4 Mon Sep 17 00:00:00 2001 From: idow09 Date: Tue, 28 Jul 2020 00:12:15 +0300 Subject: [PATCH 1/6] Introduced semantic scholar, icon not working --- manifest.json | 8 ++++-- src/content_semantic_scholar.js | 47 +++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 src/content_semantic_scholar.js diff --git a/manifest.json b/manifest.json index d920707..5f0395d 100644 --- a/manifest.json +++ b/manifest.json @@ -2,12 +2,12 @@ "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/*"] @@ -15,6 +15,10 @@ { "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"], diff --git a/src/content_semantic_scholar.js b/src/content_semantic_scholar.js new file mode 100644 index 0000000..39e1827 --- /dev/null +++ b/src/content_semantic_scholar.js @@ -0,0 +1,47 @@ +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 + var results = document.getElementsByClassName('search-result-title'); + // Go over all regions and add code implementations + for (let i = 0, l = results.length; i < l; i++) { + var title = results[i].childNodes[0].childNodes[0].textContent; + chrome.runtime.sendMessage({title: title, payload: i}, function(response) { + var results = document.getElementsByClassName('paper-actions'); + var result = results[response.payload]; + var a = result.firstChild.cloneNode(true); + a.firstChild.childNodes[0].classList[1] = "icon-fa-code"; + a.firstChild.childNodes[1].innerText = response.txt; + a.href = response.paper_link; + result.appendChild(a); + }); + } + } + }) +}) + +observer.observe(document.body, { + childList: true, + subtree: true, + attributes: false, + characterData: false +}) + +// stop watching using: +// observer.disconnect() + +/* +paper-actions example element: + + + + + + + View on IEEE + + + +*/ \ No newline at end of file From 0c289a39ef9a145a9837f7e4c8e47f8c97e91daa Mon Sep 17 00:00:00 2001 From: idow09 Date: Tue, 28 Jul 2020 20:05:51 +0300 Subject: [PATCH 2/6] Solved the icon issue: used an SVG icon from google's material lib --- src/content_semantic_scholar.js | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/content_semantic_scholar.js b/src/content_semantic_scholar.js index 39e1827..d773c31 100644 --- a/src/content_semantic_scholar.js +++ b/src/content_semantic_scholar.js @@ -12,7 +12,19 @@ let observer = new MutationObserver((mutations) => { var results = document.getElementsByClassName('paper-actions'); var result = results[response.payload]; var a = result.firstChild.cloneNode(true); - a.firstChild.childNodes[0].classList[1] = "icon-fa-code"; + let xmlns = 'http://www.w3.org/2000/svg'; + var svgElem = document.createElementNS(xmlns, "svg"); + svgElem.setAttributeNS(null, "viewBox", "0 0 24 24"); + svgElem.setAttributeNS(null, "width", 24); + svgElem.setAttributeNS(null, "height", 24); + var path1 = document.createElementNS(xmlns,"path"); + path1.setAttributeNS(null, "d", "M0 0h24v24H0V0z"); + path1.setAttributeNS(null, "fill", "none"); + var 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); + a.firstChild.replaceChild(svgElem, a.firstChild.firstChild); a.firstChild.childNodes[1].innerText = response.txt; a.href = response.paper_link; result.appendChild(a); @@ -30,18 +42,4 @@ observer.observe(document.body, { }) // stop watching using: -// observer.disconnect() - -/* -paper-actions example element: - - - - - - - View on IEEE - - - -*/ \ No newline at end of file +// observer.disconnect() \ No newline at end of file From a218566681d091b3c10563dea5d78afe0e7c3bac Mon Sep 17 00:00:00 2001 From: idow09 Date: Tue, 28 Jul 2020 20:59:27 +0300 Subject: [PATCH 3/6] Fixed icon size --- src/content_semantic_scholar.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/content_semantic_scholar.js b/src/content_semantic_scholar.js index d773c31..3c26a78 100644 --- a/src/content_semantic_scholar.js +++ b/src/content_semantic_scholar.js @@ -14,9 +14,11 @@ let observer = new MutationObserver((mutations) => { var a = result.firstChild.cloneNode(true); let xmlns = 'http://www.w3.org/2000/svg'; var svgElem = document.createElementNS(xmlns, "svg"); - svgElem.setAttributeNS(null, "viewBox", "0 0 24 24"); - svgElem.setAttributeNS(null, "width", 24); - svgElem.setAttributeNS(null, "height", 24); + 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); var path1 = document.createElementNS(xmlns,"path"); path1.setAttributeNS(null, "d", "M0 0h24v24H0V0z"); path1.setAttributeNS(null, "fill", "none"); From 77befcf67830dd1c65b2250891a758ea7eb0ac7d Mon Sep 17 00:00:00 2001 From: idow09 Date: Tue, 28 Jul 2020 21:38:40 +0300 Subject: [PATCH 4/6] var -> let --- src/content_semantic_scholar.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/content_semantic_scholar.js b/src/content_semantic_scholar.js index 3c26a78..9b414b0 100644 --- a/src/content_semantic_scholar.js +++ b/src/content_semantic_scholar.js @@ -4,25 +4,25 @@ let observer = new MutationObserver((mutations) => { for (let i = 0; i < mutation.addedNodes.length; i++) { let node = mutation.addedNodes[i]; if (!node.classList.contains('fresh-serp')) return - var results = document.getElementsByClassName('search-result-title'); + 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++) { - var title = results[i].childNodes[0].childNodes[0].textContent; + let title = results[i].childNodes[0].childNodes[0].textContent; chrome.runtime.sendMessage({title: title, payload: i}, function(response) { - var results = document.getElementsByClassName('paper-actions'); - var result = results[response.payload]; - var a = result.firstChild.cloneNode(true); + let results = document.getElementsByClassName('paper-actions'); + let result = results[response.payload]; + let a = result.firstChild.cloneNode(true); let xmlns = 'http://www.w3.org/2000/svg'; - var svgElem = document.createElementNS(xmlns, "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); - var path1 = document.createElementNS(xmlns,"path"); + let path1 = document.createElementNS(xmlns,"path"); path1.setAttributeNS(null, "d", "M0 0h24v24H0V0z"); path1.setAttributeNS(null, "fill", "none"); - var path2 = document.createElementNS(xmlns,"path"); + 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); From 4fd043e38296eb9ee322029e6c0999fd6199275f Mon Sep 17 00:00:00 2001 From: idow09 Date: Wed, 29 Jul 2020 00:00:05 +0300 Subject: [PATCH 5/6] Refactored and beutified --- src/content_semantic_scholar.js | 47 +++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/src/content_semantic_scholar.js b/src/content_semantic_scholar.js index 9b414b0..a237e84 100644 --- a/src/content_semantic_scholar.js +++ b/src/content_semantic_scholar.js @@ -1,3 +1,21 @@ +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 @@ -8,27 +26,16 @@ let observer = new MutationObserver((mutations) => { // 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); - 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); - a.firstChild.replaceChild(svgElem, a.firstChild.firstChild); - a.firstChild.childNodes[1].innerText = response.txt; + 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); }); } From a5031adc6563b1014fcf3eec9d2c0cca2428c28f Mon Sep 17 00:00:00 2001 From: idow09 Date: Wed, 29 Jul 2020 00:08:16 +0300 Subject: [PATCH 6/6] Update README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3220431..b1c8fe4 100644 --- a/README.md +++ b/README.md @@ -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`.

@@ -13,6 +13,8 @@ A simple chrome extension to present the number of available code implementions

## Recent Updates +**`2020.07.29`**: Added Semantic Scholar Support + **`2020.07.15`**: Added arXiv Support **`2020.06.24`**: Chrome Extension release @@ -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