Skip to content

Instantly share code, notes, and snippets.

@noromanba
Last active July 9, 2016 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noromanba/a350b4060098c8ddcc91 to your computer and use it in GitHub Desktop.
Save noromanba/a350b4060098c8ddcc91 to your computer and use it in GitHub Desktop.
free restricted key/pointer handlers for UserScript/Bookmarklet
// ==UserScript==
// @name restore my rights
// @namespace http://noromanba.flavors.me
// @description free restricted key/pointer handlers for UserScript/Bookmarklet
// @include http://example.com/DIY/*
// @grant none
// @noframes
// @run-at document-end
// @version 2016.7.9.0
// @homepage https://gist.github.com/noromanba/a350b4060098c8ddcc91
// @downloadURL https://gist.github.com/noromanba/a350b4060098c8ddcc91/raw/restore-my-rights.user.js
// @contributor yuta25 http://let.hatelabo.jp/yuta25/let/hLHWnL_HmJof
// @license MIT License http://nrm.mit-license.org/2016
// @author noromanba http://noromanba.flavors.me
// @icon https://upload.wikimedia.org/wikipedia/commons/thumb/3/36/Pictograms-nps-accessibility-sign_language_interpretation.svg/32px-Pictograms-nps-accessibility-sign_language_interpretation.svg.png
// @icon64 https://upload.wikimedia.org/wikipedia/commons/thumb/3/36/Pictograms-nps-accessibility-sign_language_interpretation.svg/64px-Pictograms-nps-accessibility-sign_language_interpretation.svg.png
// ==/UserScript==
// Icon (PD by NPS Graphics, ZyMOS)
// https://commons.wikimedia.org/wiki/File:Pictograms-nps-accessibility-sign_language_interpretation.svg
// Bookmarklet
// http://let.hatelabo.jp/noromanba/let/hLHWv_bVvfVX
// Devel
// https://gist.github.com/noromanba/a350b4060098c8ddcc91
// rel.
// http://furyu.hatenablog.com/entry/20150706/1436182102
// http://let.hatelabo.jp/furyu-tei/let/hLHXzbfzoZkS
// https://github.com/furyutei/KashiKaikin
//*/
(() => {
const clearHandlers = (node) => {
node.getAttribute && node.getAttribute('unselectable') && node.setAttribute('unselectable', 'off');
node.onkeydown = null;
node.onkeypress = null;
node.onkeyup = null;
node.onmousedown = null;
node.oncontextmenu = null;
node.onselectstart = null;
node.onselect = null;
node.oncopy = null;
node.oncut = null;
if (!node.style) return;
[
'',
//'-moz-', // *1
'-webkit-',
'-khtml-',
'-ms-',
'-o-'
].forEach(prefix => {
node.style[prefix + 'user-select'] = 'initial';
});
// *1: Fx can not access by bracket-notation; node.style['-moz-user-select']
// e.g. http://www.softel.co.jp/blogs/tech/archives/2909
// alt; node.style.getPropertyValue('-moz-user-select')
// property works well
node.style.MozUserSelect && (node.style.MozUserSelect = 'initial');
};
clearHandlers(document);
const clearHandlersAll = (ctx) => {
Array.from(ctx.querySelectorAll('*'), node => {
clearHandlers(node);
});
};
clearHandlersAll(document);
new MutationObserver(records => {
records.forEach(record => {
// TBD addedNodes
const ctx = record.target;
if (!ctx.tagName || !ctx.querySelectorAll) return;
clearHandlersAll(ctx);
});
}).observe(document.body, { childList: true, subtree: true });
})();
/*/
javascript:(()=>{const clearHandlers=(node)=>{node.getAttribute&&node.getAttribute('unselectable')&&node.setAttribute('unselectable','off');node.onkeydown=null;node.onkeypress=null;node.onkeyup=null;node.onmousedown=null;node.oncontextmenu=null;node.onselectstart=null;node.onselect=null;node.oncopy=null;node.oncut=null;if(!node.style)return;['','-webkit-','-khtml-','-ms-','-o-'].forEach(prefix=>{node.style[prefix+'user-select']='initial';});node.style.MozUserSelect&&(node.style.MozUserSelect='initial');};clearHandlers(document);const clearHandlersAll=(ctx)=>{Array.from(ctx.querySelectorAll('*'),node=>{clearHandlers(node);});};clearHandlersAll(document);new MutationObserver(records=>{records.forEach(record=>{const ctx=record.target;if(!ctx.tagName||!ctx.querySelectorAll)return;clearHandlersAll(ctx);});}).observe(document.body,{childList:true,subtree:true});})();
//*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment