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 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..a237e84 --- /dev/null +++ b/src/content_semantic_scholar.js @@ -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() \ No newline at end of file