Created
August 10, 2014 17:15
-
-
Save jywarren/5694b9902cbdc99ebece to your computer and use it in GitHub Desktop.
Creates a PublicLab.org research note draft based on the selected text.
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
// Creates a PublicLab.org research note draft based on the selected text. | |
//Bookmarklet: javascript:(function(){document.body.appendChild(document.createElement('script')).src='http://publiclab.org/research-notify.js';})() | |
//Nice tips on jquery inclusion etc here: http://www.smashingmagazine.com/2010/05/23/make-your-own-bookmarklets-with-jquery/ | |
/* | |
To-do: | |
* make it check if there's already text selected | |
* get the HTML (or at least preserve spaces and links somehow -- remember Markdown can do HTML) | |
* preserve images | |
*/ | |
//####################################// | |
function getSelText() { | |
var SelText = ''; | |
if (window.getSelection) { | |
SelText = window.getSelection(); | |
} else if (document.getSelection) { | |
SelText = document.getSelection(); | |
} else if (document.selection) { | |
SelText = document.selection.createRange().text; | |
} | |
return SelText; | |
} | |
(function(){ | |
// the minimum version of jQuery we want | |
var v = "1.3.2"; | |
// check prior inclusion and version | |
if (window.jQuery === undefined || window.jQuery.fn.jquery < v) { | |
var done = false; | |
var script = document.createElement("script"); | |
script.src = "http://ajax.googleapis.com/ajax/libs/jquery/" + v + "/jquery.min.js"; | |
script.onload = script.onreadystatechange = function(){ | |
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) { | |
done = true; | |
initMyBookmarklet(); | |
} | |
}; | |
document.getElementsByTagName("head")[0].appendChild(script); | |
} else { | |
initMyBookmarklet(); | |
} | |
function initMyBookmarklet() { | |
(window.myBookmarklet = function() { | |
// your JavaScript code goes here! | |
$('body')[0].onmouseup = function(e) { | |
window.location = "http://publiclab.org/post?title="+$('#title').text()+"&body="+getSelText() | |
} | |
alert("Drag to select the content you want to open source at PublicLab.org") | |
})(); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment