Skip to content

Instantly share code, notes, and snippets.

@tani
Last active January 13, 2020 15:06
Show Gist options
  • Save tani/271bcf292a9b6d6f26a2b9ca9e04e22d to your computer and use it in GitHub Desktop.
Save tani/271bcf292a9b6d6f26a2b9ca9e04e22d to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name arXiv File Namer
// @namespace Violentmonkey Scripts
// @match https://arxiv.org/abs/*
// @grant GM_xmlhttpRequest
// @grant GM_download
// ==/UserScript==
const id = location.href.replace(/.*\//,"")
GM_xmlhttpRequest({
method: "GET",
responseType: "json",
url: `https://api.altmetric.com/v1/arxiv/${id}`,
onload: ({response}) => {
const anchor = document.querySelector("a[href^='/pdf/']")
const author = response.authors[0].replace(/.* /,"")
const published_on = new Date(response.published_on * 1000)
const url = anchor.href
const year = published_on.getFullYear()
const name = `${author}${year}.pdf`
anchor.onclick = () => {
GM_download(url, name)
return false
}
}
})
// ==UserScript==
// @name Google Scholar File Namer
// @namespace Violentmonkey Scripts
// @match https://scholar.google.co.jp/*
// @grant GM_download
// ==/UserScript==
// https://github.com/ekmartin/bibtex-search/blob/d6cbf6061d1b128a699071e4073e6d61943385aa/index.js#L103-L114
document.querySelectorAll("span+a[data-clk-atid],a[data-clk-atid]:not([id])").forEach((anchor)=>{
const id = anchor.dataset.clkAtid
const info = document.querySelector(`div[data-cid="${id}"] .gs_a`).innerText
const author = info.split(/\s-\s/)[0].split(",")[0].replace(/.* /,"")
const year = info.match(/(?:19|20)\d\d/)[0]
const name = `${author}${year}.pdf`
const url = anchor.href
anchor.parentNode.setAttribute("ontouchstart", null)
anchor.onclick = () => {
GM_download(url, name)
return false
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment