Created
October 10, 2017 17:19
-
-
Save ghing/b90def55d93ed629281c180dd6febf4c to your computer and use it in GitHub Desktop.
Dailygraphics markdown links bookmarklet
This file contains hidden or 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
javascript:(function(){ | |
/* Modified from https://gist.github.com/bradleybossard/3667ad5259045f839adc */ | |
/* The version there is more robust */ | |
var copyToClipboard = function (text) { | |
var textarea = document.createElement("textarea"); | |
textarea.textContent = text; | |
textarea.style.position = "fixed"; /* Prevent scrolling to bottom of page in MS Edge.*/ | |
document.body.appendChild(textarea); | |
textarea.select(); | |
return document.execCommand("copy"); /* Security exception may be thrown by some browsers.*/ | |
document.body.removeChild(textarea); | |
}; | |
var pathBits = window.location.pathname.split('/') | |
.filter(function(s) { | |
return s !== ""; | |
}); | |
var slug = pathBits[pathBits.length - 1]; | |
var urls = { | |
staging: document.querySelector('.btn.staging').getAttribute('href'), | |
production: document.querySelector('.btn.production').getAttribute('href'), | |
spreadsheet: document.querySelector('.parent-header .right .segment:last-child .btn').getAttribute('href') | |
}; | |
var markdown = ['staging', 'production', 'spreadsheet'].reduce(function(prev, linkType) { | |
return prev + "[" + linkType + "]" + "(" + urls[linkType] + ")" + " "; | |
}, slug + " "); | |
copyToClipboard(markdown); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment