-
-
Save queuebit/6118987 to your computer and use it in GitHub Desktop.
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(){var p=document.createElement("p");p.innerHTML="<strong>Loading…</strong>";p.id="loadingp";p.style.padding="20px";p.style.background="#fff";p.style.left="20px";p.style.top=0;p.style.position="fixed";p.style.zIndex="9999999";p.style.opacity=".85";document.body.appendChild(p);document.body.appendChild(document.createElement("script")).src="https://gist.github.com/queuebit/6118987/raw/SelectBullseye.js?x="+(Math.random());})(); |
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
// SelectBullseye 0.2 | |
// Incorporated @ttscoff's changes from Bullseye 0.3 | |
// * Add escape key to cancel | |
// * Only use the first class when constructing path, potentially avoid dynamically-added classnames | |
// * Allow bookmarklet to be called with "window.bullseyeShowFrame=0" at the beginning to return just raw text | |
// | |
// SelectBullseye 0.1 | |
// adapted @ttscoff's Bullseye to perform text selection instead of markdown conversion | |
(function () { | |
function callback() { | |
(function ($) { | |
var jQuery = $, $els = $("div,table,article,section,aside"); | |
$('#loadingp').fadeOut("fast", function () { | |
$(this).remove(); | |
}); | |
$els.on("mouseover mouseout click", function (a) { | |
a.stopPropagation(); | |
a.type === "mouseover" ? $(this).css({ | |
outline: "1px solid rgb(194, 130, 148)" | |
}).addClass("mkhovered") : $els.css({ | |
outline: "none" | |
}).removeClass("mkhovered"); | |
if (a.type === "click") { | |
a.preventDefault(); | |
$(".mkhovered").css({ | |
outline: "none" | |
}).removeClass("mkhovered"); | |
var $container = $(this); | |
var elpath = [], $parents = $container.parentsUntil("body").add($container); | |
$parents.each(function(i,n) { | |
var index = $(n).index(); | |
index = (index < 2) ? ":first" : ":nth-of-type("+(index-1)+")"; | |
var tag = n.tagName.toLowerCase(); | |
if ($(n).attr("id") !== undefined) { | |
elpath.push("#"+$(n).attr("id")); | |
} else if (n.className !== "") { | |
elpath.push(tag+"."+n.className.split(" ")[0]+index); | |
} else { | |
elpath.push(tag+index); | |
} | |
}); | |
var loadpath = window.location.pathname+" "+elpath.join(" "); | |
// Changes for range selection | |
var doc = document, text = this, range, selection; | |
if (doc.body.createTextRange) { | |
range = document.body.createTextRange(); | |
range.moveToElementText(text); | |
range.select(); | |
} else if (window.getSelection) { | |
selection = window.getSelection(); | |
range = document.createRange(); | |
range.selectNodeContents(text); | |
selection.removeAllRanges(); | |
selection.addRange(range); | |
} | |
} | |
}); | |
$(document).bind("keyup",function(e) { | |
if (e.keyCode === 27) { | |
$els.unbind("mouseover mouseout click"); | |
$(".mkhovered").css("outline","none").removeClass("mkhovered"); | |
$(document).unbind("keyup"); | |
} | |
return true; | |
}); | |
})(jQuery.noConflict(true)) | |
} | |
var s = document.createElement("script"); | |
s.src = "https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"; | |
if (s.addEventListener) { | |
s.addEventListener("load", callback, false) | |
} else if (s.readyState) { | |
s.onreadystatechange = callback | |
} | |
document.body.appendChild(s); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment