Created
November 18, 2021 08:23
-
-
Save sbwww/d9067a698372908711e528450ee7e776 to your computer and use it in GitHub Desktop.
quickly download multiple papers from Semantic Scholar library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name SemanticScholar-Download | |
// @namespace sbwww.github.io | |
// @version 0.1 | |
// @description quickly download multiple papers from Semantic Scholar library | |
// @author sbwww | |
// @match https://www.semanticscholar.org/me/library/* | |
// @icon https://www.google.com/s2/favicons?domain=semanticscholar.org | |
// @grant none | |
// ==/UserScript== | |
function download_list() { | |
var url_list = document.querySelectorAll(".cl-paper-view-paper"); | |
var title_list = document.querySelectorAll(".cl-paper-title span span"); | |
var t = document.querySelector("#progress"); | |
var len = url_list.length; | |
for (let i = 0; i < len; ++i) { | |
let item = url_list[i]; | |
let url = item.attributes["href"].nodeValue; | |
let title_text = title_list[i].innerText; | |
const regex = /[\@\#\$\%\^\&\*\(\)\{\}\:\"\<\>\?\[\]]/gi; | |
title_text = title_text.replace(regex, ""); | |
console.log(url, title_text); | |
if (url.match(".*.pdf")) { | |
// mostly, arxiv can be downloaded | |
fetch(url) | |
.then(function (res) { | |
return res.blob().then((b) => { | |
var a = document.createElement("a"); | |
a.href = URL.createObjectURL(b); | |
a.setAttribute("download", title_text + ".pdf"); | |
a.click(); | |
a.remove(); | |
}); | |
}) | |
.catch(() => { | |
// but acl, it throws an cors-error | |
// not sure how to solve it, so just open the page by clicking it | |
item.click(); | |
}); | |
} else { | |
// ieee, acm don't offer a direct link to pdf, open the page instead | |
item.click(); | |
} | |
t.innerHTML = i + 1 + " / " + len; | |
} | |
} | |
window.onload = () => { | |
var pos = document.querySelector(".research-list__header__content"); | |
var b = document.createElement("button"); | |
b.innerHTML = "Download"; | |
b.onclick = download_list; | |
pos.appendChild(b); | |
var t = document.createElement("text"); | |
t.id = "progress"; | |
pos.appendChild(t); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO: