Skip to content

Instantly share code, notes, and snippets.

@wakhub
Created August 11, 2012 01:52
Show Gist options
  • Save wakhub/3319875 to your computer and use it in GitHub Desktop.
Save wakhub/3319875 to your computer and use it in GitHub Desktop.
Quote Bookmarklet
// javascript:(function(js,d,s){d=document,s=function(src,sc,date){sc=d.createElement('script');sc.setAttribute('src',src);d.body.appendChild(sc);};date=(new Date()).getTime();s(js+'?'+date);})('//raw.github.com/gist/3319875/quote.js');
(function(){
var d = document,
t = d.getElementById('_____blockQuote');
if (!t) {
t = d.createElement('textarea');
t.setAttribute('id', '_____blockQuote');
d.body.appendChild(t);
}
with (t.style) {
position = 'fixed';
top = '1em';
right = '1em';
opacity = '0.8';
width = '300px';
height = '500px';
zIndex = 10000;
}
var main = function(){
var fmt = " {{body}}\n\n `{{title}} <{{url}}>`_\n",
body = getSelText().replace(/\n/g, "\n ");
t.value = fmt.replace('{{body}}', body)
.replace('{{title}}', document.title)
.replace('{{url}}', location.href);
};
try {
main();
} catch (e) {
alert(e);
}
// http://www.codetoad.com/javascript_get_selected_text.asp
function getSelText() {
var text = '';
if (window.getSelection) {
text = window.getSelection() || '';
}
if (document.getSelection) {
text = document.getSelection() || '';
}
if (document.selection) {
text = document.selection.createRange().text || '';
}
return text.toString();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment