Skip to content

Instantly share code, notes, and snippets.

@duzun
Last active November 30, 2024 06:43
Show Gist options
  • Save duzun/d66c775a39a5be9fb519 to your computer and use it in GitHub Desktop.
Save duzun/d66c775a39a5be9fb519 to your computer and use it in GitHub Desktop.
Enable Right Click and Text Selection Bookmarklet
<a class="btn btn-default btn-info bookmarklet" href="javascript:(function(d){var a=d.document,h=function(){},c=a.body||a.getElementsByTagName("body")[0],f=a.documentElement||a.getElementsByTagName("html")[0],k=[c,f,a],l=["webkit","khtml","moz","ms",""],g=["contextmenu","selectstart","select","mousedown","mouseup"],b=d.Selection,e=b&&b.prototype;e&&(e.removeAllRanges=h,b=a.selection)&&(b.clear=h);for(e=k.length;e--;)if(f=k[e]){for(b=g.length;b--;)f["on"+g[b]]=null;if(a=f.style)for(a.cursor="",a.webkitTouchCallout="initial",b=l.length;b--;)a[((c=l[b])?"-"+c+"-":c)+"user-select"]="initial"}(c=d.jQuery||d.Zepto)&&c(d).off(g)})(this);">
Enable Select
</a>
(function (w) {
var d = w.document
, n = function(){}
, us = 'user-select'
, uv = 'initial'
, f = 'getElementsByTagName'
, b = d.body || d[f]('body')[0]
, h = d.documentElement || d[f]('html')[0]
, a = [b,h,d]
, p = ['webkit','khtml','moz','ms','']
, e = ['contextmenu','selectstart','select','mousedown','mouseup']
, s=w.Selection
, i=s&&s.prototype
;
if ( i ) {
i.removeAllRanges = n;
if(s=d.selection) s.clear = n;
}
for(i=a.length;i--;) if(h=a[i]) {
for(s=e.length;s--;) h['on'+e[s]] = null;
if(d=h.style) {
d.cursor = '';
d.webkitTouchCallout = uv;
for(s=p.length;s--;) d[((b=p[s])?'-'+b+'-':b)+us] = uv;
}
}
(b = w.jQuery || w.Zepto) && b(w).off(e);
}(this))
javascript:(function(d){var a=d.document,h=function(){},c=a.body||a.getElementsByTagName("body")[0],f=a.documentElement||a.getElementsByTagName("html")[0],k=[c,f,a],l=["webkit","khtml","moz","ms",""],g=["contextmenu","selectstart","select","mousedown","mouseup"],b=d.Selection,e=b&&b.prototype;e&&(e.removeAllRanges=h,b=a.selection)&&(b.clear=h);for(e=k.length;e--;)if(f=k[e]){for(b=g.length;b--;)f["on"+g[b]]=null;if(a=f.style)for(a.cursor="",a.webkitTouchCallout="initial",b=l.length;b--;)a[((c=l[b])?"-"+c+"-":c)+"user-select"]="initial"}(c=d.jQuery||d.Zepto)&&c(d).off(g)})(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment