-
-
Save tslmy/023322bc6e19d940af7653f2f5cb50d7 to your computer and use it in GitHub Desktop.
A bookmarklet for grabbing just a piece of a web page and converting it to Markdown using heckyesmarkdown.com.
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
// version 0.5 | |
// Uses nvALT. | |
// Not using remote/external loading because it is often blocked by allowed-origin. | |
// Now serves under HTTPS. | |
// version 0.4 | |
// Bugfix for Firefox | |
// | |
// 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 | |
// | |
// Version 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 = $, $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(" "); | |
// console.log(loadpath); | |
// return; | |
$("<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", "https://heckyesmarkdown.com/go/") | |
.append($("<input name=html>").val(encodeURIComponent(raw.innerHTML))) | |
.append($("<input name=read>").val("0")) | |
.append($("<input name=output>").val("nv")) | |
.append($("<input name=showframe>").val("0")) | |
.appendTo('body'); | |
$form.submit(function(event){ | |
$.ajax({ | |
url: $form.attr('action'), | |
type: $form.attr('method'), | |
data : $form.serialize(), | |
success: function(e) { | |
location.assign(e); | |
} | |
}); | |
event.preventDefault(); | |
}); | |
$form.submit(); | |
}); | |
} | |
}); | |
$(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); | |
})(); |
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
!function(){function t(){!function(t){var e=t("div,table,article,section,aside");t("#loadingp").fadeOut("fast",function(){t(this).remove()}),e.on("mouseover mouseout click",function(a){if(a.stopPropagation(),"mouseover"===a.type?t(this).css({outline:"1px solid rgb(194, 130, 148)"}).addClass("mkhovered"):e.css({outline:"none"}).removeClass("mkhovered"),"click"===a.type){a.preventDefault(),t(".mkhovered").css({outline:"none"}).removeClass("mkhovered");var n=t(this),o=[],i=n.parentsUntil("body").add(n);i.each(function(e,a){var n=t(a).index();n=2>n?":first":":nth-of-type("+(n-1)+")";var i=a.tagName.toLowerCase();void 0!==t(a).attr("id")?o.push("#"+t(a).attr("id")):""!==a.className?o.push(i+"."+a.className.split(" ")[0]+n):o.push(i+n)});var r=window.location.pathname+" "+o.join(" ");t("<div>").load(r,function(){var e=this;""===t(e).text()&&(e=t("<div>").append(n.html()).get(0)),t(e).find('a[href*="twitter.com/intent"],a[href*="app.net/intent"]').remove(),t(e).find("a,img").each(function(){var e=this,a=t(e),n="A"===e.tagName?"href":"src";if("IMG"===e.tagName&&void 0!==a.data("original")&&a.attr(n,a.data("original")),!/^http/.test(a.attr(n))){if(/^\//.test(a.attr(n)))var o=window.location.protocol+"//"+window.location.hostname;else var o=window.location.href.split("/").slice(0,-1).join("/")+"/";a.attr(n,o+a.attr(n))}});var a=t("<form>").attr("method","post").attr("action","https://heckyesmarkdown.com/go/").append(t("<input name=html>").val(encodeURIComponent(e.innerHTML))).append(t("<input name=read>").val("0")).append(t("<input name=output>").val("nv")).append(t("<input name=showframe>").val("0")).appendTo("body");a.submit(function(e){t.ajax({url:a.attr("action"),type:a.attr("method"),data:a.serialize(),success:function(t){location.assign(t)}}),e.preventDefault()}),a.submit()})}}),t(document).bind("keyup",function(a){return 27===a.keyCode&&(e.unbind("mouseover mouseout click"),t(".mkhovered").css("outline","none").removeClass("mkhovered"),t(document).unbind("keyup")),!0})}(jQuery.noConflict(!0))}var e=document.createElement("script");e.src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js",e.addEventListener?e.addEventListener("load",t,!1):e.readyState&&(e.onreadystatechange=t),document.body.appendChild(e)}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment