Skip to content

Instantly share code, notes, and snippets.

@whipsch
Created October 22, 2015 05:38
Show Gist options
  • Save whipsch/00368361937cb69fe897 to your computer and use it in GitHub Desktop.
Save whipsch/00368361937cb69fe897 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name gist-rust-playpen
// @description Adds a Rust Playpen button to Gists that contain a Rust file.
// @namespace whipsch
// @include https://gist.github.com/*
// @version 1
// @grant none
// ==/UserScript==
if (document.querySelector("div.file > div.type-rust")) {
var gist_id = null;
var target = document.querySelector("meta[name='octolytics-dimension-gist_name']");
if (target) {
gist_id = target.getAttribute("content");
}
target = document.querySelector("div.repository-sidebar > div.only-with-full-nav");
if (gist_id && target) {
var button = document.createElement("a");
button.setAttribute("href", "https://play.rust-lang.org/?gist=" + gist_id);
button.setAttribute("target", "_blank");
button.setAttribute("class", "btn btn-block");
var icon = document.createElement("span");
icon.setAttribute("class", "octicon octicon-gear");
button.append(icon);
button.append(document.createTextNode(" Rust Playpen"));
target.append(button);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment