Skip to content

Instantly share code, notes, and snippets.

@JT5D
Forked from ttscoff/grab links.bookmarklet
Created December 22, 2013 11:32
Show Gist options
  • Select an option

  • Save JT5D/8081144 to your computer and use it in GitHub Desktop.

Select an option

Save JT5D/8081144 to your computer and use it in GitHub Desktop.
javascript: (function(e, a, g, h, f, c, b, d) {
if (!(f = e.jQuery) || g > f.fn.jquery || h(f)) {
c = a.createElement("script");
c.type = "text/javascript";
c.src = "http://ajax.googleapis.com/ajax/libs/jquery/" + g + "/jquery.min.js";
c.onload = c.onreadystatechange = function() {
if (!b && (!(d = this.readyState) || d == "loaded" || d == "complete")) {
h((f = e.jQuery).noConflict(1), b = 1);
f(c).remove()
}
};
a.documentElement.childNodes[0].appendChild(c)
}
})(window, document, "1.7", function($, L) {
$(document).ready(function() {
var collection = [];
$("div,table,article,section,aside").on("mouseover mouseout click", function(a) {
a.type === "mouseover" ? $(this).css({
outline: "1px solid red"
}) : $("div,table,article,section,aside").css({
outline: "none"
});
if (a.type === "click") {
a.preventDefault();
var i, linkage = $(this).find("a");
linkage.each(function(i, link) {
var linktext = $(link).text() === undefined ? $(link).attr("href") : $(link).text().replace(/[\n\r\s]+/g, " ").replace(/(^\s*|\s*$)/g, "").slice(0, 100);
var url = /^http/.test($(link).attr("href")) ? $(link).attr("href") : document.location.protocol + "//" + document.location.hostname + $(link).attr("href");
collection.push(["- [" + linktext.replace(/[\[\]\|]+/g, "") + "](" + url + ")"]);
});
$("<div>").css({
position: "fixed",
top: "0",
left: "0",
right: "0",
bottom: "0",
overflow: "auto",
backgroundColor: "#efefef",
color: "#333",
zIndex: "99999"
}).append($("<pre id=linkoutput>").css("padding", "20px").text(collection.join("\n"))).appendTo("body").click(function() {
var doc = document,
text = doc.getElementById("linkoutput"),
range, selection;
if (doc.body.createTextRange) {
range = doc.body.createTextRange();
range.moveToElementText(text);
range.select();
} else if (window.getSelection) {
selection = window.getSelection();
range = doc.createRange();
range.selectNodeContents(text);
selection.removeAllRanges();
selection.addRange(range);
}
});
return false;
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment