Last active
February 15, 2017 17:07
-
-
Save themadsens/d37d5c1ed2f5124919928b41fb51c76a to your computer and use it in GitHub Desktop.
Install: Copy from 'javascript:' onwards, and paste into a bookmark. Usage: Triple click filename in github and click bookmark
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
// javascript: | |
(function() { | |
function getSelectionHtml() { | |
var html = ""; | |
if (typeof window.getSelection != "undefined") { | |
var sel = window.getSelection(); | |
if (sel.rangeCount) { | |
var container = document.createElement("div"); | |
for (var i = 0, len = sel.rangeCount; i < len; ++i) { | |
container.appendChild(sel.getRangeAt(i).cloneContents()); | |
} | |
html = container.innerHTML; | |
} | |
} else if (typeof document.selection != "undefined") { | |
if (document.selection.type == "Text") { | |
html = document.selection.createRange().htmlText; | |
} | |
} | |
return html; | |
} | |
var rex = /<a href="\/(.+?)\/(.+?)\/(?!releases\/)(?:(?:blob|raw)\/)?(.+?)\/([^"]+)"/i; | |
var sel = getSelectionHtml(); | |
var val = sel.match(rex); | |
var res = val ? 'Copy URL:\nhttps://rawgit.com/'+val[1]+'/'+val[2]+'/'+val[3]+'/'+val[4] | |
: "Triple click file to select, then click this bookmarklet"; | |
console.log("RES", val, res); | |
alert(res); | |
res = null; | |
}()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment