Created
May 18, 2021 17:17
-
-
Save astronasutarou/77c91f233227f30b248e09aa6e8962ef to your computer and use it in GitHub Desktop.
Greasemonky script to post an arXiv entry to your Scrapbox.io
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 post new paper to Scrapbox | |
// @description post arXiv.or.js to your Scrapbox.io | |
// @namespace http://xr0038.net | |
// @include https://arxiv.org/abs/* | |
// @run-at document-end | |
// @version 1 | |
// ==/UserScript== | |
(function(Scrapbox){ | |
function pop_meta(key, name) { | |
const metas = document.getElementsByTagName('meta'); | |
for (const x of metas) { | |
if (x.getAttribute(key) == name) | |
return x.getAttribute('content'); | |
} | |
} | |
function count_meta(key, name) { | |
const metas = document.getElementsByTagName('meta'); | |
let count = 0; | |
for (const x of metas) | |
count += (x.getAttribute(key) == name); | |
return count; | |
} | |
function get_title() { return pop_meta('name','citation_title'); } | |
function get_author() { | |
const first_author = pop_meta('name', 'citation_author'); | |
const num_author = count_meta('name', 'citation_author'); | |
if (num_author>1) | |
return first_author.replace(/,.*/, ', et al.'); | |
return first_author; | |
} | |
const title = get_title(); | |
const author = get_author(); | |
const url = document.location; | |
const post_url = `${Scrapbox}${title}?body=${author} ${url}`; | |
const bookmarks = document.getElementsByClassName('bookmarks')[0]; | |
let logo = document.createElement('img'); | |
logo.setAttribute('src', 'https://nota.github.io/press-kit/S-icon.svg'); | |
logo.setAttribute('height', '16pix'); | |
logo.setAttribute('alt', 'Scrapbox'); | |
let scrapbox = document.createElement('a'); | |
scrapbox.appendChild(logo); | |
scrapbox.setAttribute('class','abs-button abs-button-grey abs-button-small'); | |
scrapbox.setAttribute('href', encodeURI(post_url)); | |
scrapbox.setAttribute('target', '_blank'); | |
scrapbox.setAttribute('title','Post on Scrapbox'); | |
bookmarks.appendChild(scrapbox); | |
})("https://scrapbox.io/NAME_OF_YOUR_SPACE/"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment