Created
February 26, 2021 17:31
-
-
Save JTBrinkmann/315c090291c5b4b0b6bf4bcecfc3b9bc to your computer and use it in GitHub Desktop.
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 Springer Link add download-URLs to search results | |
// @version 0.1 | |
// @author J.-T. Brinkmann | |
// @include https://link.springer.com/search* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const DL_TEXT = "[dl]" | |
const DL_LOADING = "[dl...]" | |
;[...document.querySelectorAll('h2 a.title')].forEach($el => { | |
const url = $el.href | |
const $dl = document.createElement('a') | |
$dl.textContent = "[dl]" | |
$dl.style.marginLeft = "1em" | |
$dl.href = url | |
$dl.download = "" | |
let loaded = false | |
$dl.addEventListener('click', async (e) => { | |
if (!loaded) { | |
loaded = true | |
e.preventDefault() | |
console.log("loading", url) | |
$dl.style.color = "#aaa" | |
$dl.textContent = DL_LOADING | |
const res = await fetch(url).then(r=>r.text()) | |
const dlUrl = res.match(/<a href="([^"]*?)" [^>]*class="[^"]*?test-bookpdf-link/)[1] | |
$dl.href = dlUrl | |
$dl.click() | |
$dl.style.color = "" | |
$dl.textColor = DL_TEXT | |
} | |
}) | |
$el.after($dl) | |
}) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment