Skip to content

Instantly share code, notes, and snippets.

@nuest
Forked from LukasLohoff/README.md
Created March 27, 2017 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nuest/25ce303502d619243567be4e19fa0048 to your computer and use it in GitHub Desktop.
Save nuest/25ce303502d619243567be4e19fa0048 to your computer and use it in GitHub Desktop.
Userscript adding a "Upload to O2R" button to Zenodo / Zenodo Sandbox.

"Upload to O2R" - Userscript for Zenodo

Requirements

  • Firefox or Chrome Web Browser

Installation

  1. Install a browser extension to support userscripts

  2. Create a new Userscript and replace it with the code from below

Alternative

  • open your browser's console (F12 and switch to the console tab)
  • copy and paste the JavaScript code into the console
// ==UserScript==
// @name Zenodo O2R Integration
// @namespace o2r.info.zenodo
// @author Lukas Lohoff
// @include https://zenodo.org/record/*
// @include https://sandbox.zenodo.org/record/*
// @grant none
// @version 1
// ==/UserScript==
addButton();
function addButton() {
var btn = document.createElement('BUTTON');
var t = document.createTextNode(' Open as Executable Research Compendium');
var frm = document.createElement('FORM');
var icn = document.createElement('I');
icn.setAttribute('class', "fa fa-external-link");
btn.setAttribute('class', "btn btn-primary btn-block");
btn.appendChild(icn);
btn.appendChild(t);
frm.appendChild(btn);
//frm.setAttribute('action', "http://www.o2r.info");
frm.addEventListener("click", function(event) {
var collapse = document.getElementById('collapseTwo');
var frwrap = collapse.getElementsByClassName('forcewrap')[0];
var filename = frwrap.innerText;
var zenodoURL = window.location.href;
var finalURL = "https://o2r.uni-muenster.de/#!/home?zenodoURL=" + zenodoURL + "&filename=" + filename;
openO2RPage(finalURL);
event.preventDefault();
});
var menu = document.getElementsByClassName("col-sm-4 col-md-4 col-right")[0];
var metadata = document.getElementsByClassName("well metadata")[0];
//menu.appendChild(btn);
menu.insertBefore(frm, metadata);
}
function openO2RPage(url) {
//window.open uses default browser behavior (-> new tab) but is considered a popup and may be blocked
window.open(url);
//window.location.href = url;
}
// wait for async elements to load
//setTimeout(addButton, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment