A Bookmarklet to Enable All Text Selection
I have noticed at least one lyrics website has started preventing users from copying lyrics. (As if the lyrics website has a copyright on someone else’s song lyrics!) While there are some good user-experience reasons to disable text selection for certain parts of a web app, but clearly entire the point of a lyrics website is to look up lyrics — and selecting lines can make it easier to read in your browser, or perhaps you want to paste the lyrics into an MP3’s ID3 data (“Get Info” in iTunes).
So screw that.
Here’s a bookmarklet that should allow you to select anything on a web page. It’s not an ultimate solution, but it works for me. Just click it on an offending page.
Install it by dragging the above bookmarklet to your browser’s bookmarks bar, or by copying its target and pasting it as a new bookmark.
Then go try it out at an offending lyrics site or this test page (the latter affects Safari/Chrome/Firefox only, currently).
Or, if your system displays this symbol (a mathematical, serif, capital letter I, reminiscent of a text-selection I-beam cursor), I think it makes for a neater bookmarklet:
More Bookmarklets
You can see even more of my little bookmarklets here. I hope some prove useful!
The Code
The script works by disabling JavaScript that intercepts the user’s mouse clicks and selections, and by removing a CSS property that prevents selection.
It is quite possible that this script won’t work on some pages. Don’t send nasty comments if this turns out to be true.
javascript:(function(){
function allowTextSelection(){
var styles='*,p,div{user-select:text !important;-moz-user-select:text !important;-webkit-user-select:text !important;}';
jQuery('head').append(jQuery('<style />').html(styles));
window.console&&console.log('allowTextSelection');
var allowNormal = function(){
return true;
};
window.console&&console.log('Elements unbound: '+
jQuery('*[onselectstart], *[ondragstart], *[oncontextmenu], #songLyricsDiv'
).unbind('contextmenu').unbind('selectstart').unbind('dragstart'
).unbind('mousedown').unbind('mouseup').unbind('click'
).attr('onselectstart',allowNormal).attr('oncontextmenu',allowNormal
).attr('ondragstart',allowNormal).size());
}
function allowTextSelectionWhenPossible() {
window.console&&console.log('allowTextSelectionWhenPossible');
if(window.jQuery){
window.console&&console.log('jQuery has now loaded');
allowTextSelection();
} else {
window.console&&console.log('jQuery still not loaded.');
window.setTimeout(allowTextSelectionWhenPossible, 100);
}
}
if(window.jQuery) {
window.console&&console.log('jQuery exists; will use');
allowTextSelection();
}else{
window.console&&console.log('jQuery not loaded; will include.');
var s=document.createElement('script');
s.setAttribute('src','http://jquery.com/src/jquery-latest.js');
document.getElementsByTagName('body')[0].appendChild(s);
allowTextSelectionWhenPossible();
}
})();