-
-
Save lyoshenka/6124401 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/ttscoff/6109434/raw/Bullseye.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
// Bullseye 0.2 | |
// Resolves relative urls | |
// removes Twitter intent links | |
// tries to update lazy loaded image urls | |
// loads from raw source, with fallback for dynamically-loaded content | |
(function () { | |
function callback() { | |
(function ($) { | |
var jQuery = $; | |
$('#loadingp').fadeOut("fast", function () { | |
$(this).remove(); | |
}); | |
$("div,table,article,section,aside").on("mouseover mouseout click", function (a) { | |
a.stopPropagation(); | |
a.type === "mouseover" ? $(this).css({ | |
outline: "1px solid rgb(194, 130, 148)" | |
}).addClass("mkhovered") : $("div,table,article,section,aside").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(" ").join(".")+index); | |
} else { | |
elpath.push(tag+index); | |
} | |
}); | |
var loadpath = window.location.pathname+" "+elpath.join(" "); | |
$("<div>").load(loadpath, function() { | |
var raw = this; | |
if ($(raw).text() === "") { | |
raw = $("<div>").append($container.html()).get(0); | |
} | |
$(raw).find('a[href*="twitter.com/intent"],a[href*="app.net/intent"]').remove(); | |
$(raw).find("a,img").each(function(){ | |
var el = this, $el = $(el), attr = el.tagName === "A" ? "href" : "src"; | |
if (el.tagName === "IMG") { | |
if ($el.data("original") !== undefined) { | |
$el.attr(attr,$el.data("original")); | |
} | |
} | |
if (!/^http/.test($el.attr(attr))) { | |
if (/^\//.test($el.attr(attr))) | |
var baselink = window.location.protocol + "//" + window.location.hostname; | |
else | |
var baselink = window.location.href.split("/").slice(0,-1).join("/") + "/"; | |
$el.attr(attr, baselink + $el.attr(attr)); | |
} | |
}); | |
var $form = $("<form>").attr("method", "post").attr("action", "http://heckyesmarkdown.com/go/?callback=?") | |
.append($("<input name=html>").val(encodeURIComponent(raw.innerHTML))) | |
.append($("<input name=read>").val("0")) | |
.append($("<input name=output>").val("md")) | |
.append($("<input name=showframe>").val("1")); | |
$form.submit(); | |
}); | |
} | |
}) | |
})(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