Last active
April 24, 2017 19:26
-
-
Save vyach-vasiliev/8dfb5f5b3c22e1fc74da180f00685929 to your computer and use it in GitHub Desktop.
Fix lock selection text on WEB-Page / UserScript
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
// ==UserScript== | |
// @name _Fix lock selection text [allsites] | |
// @version 1.3 | |
// @description fix blocking selection on all sites | |
// @author Vyachesl Vasiliev | |
// @include * | |
// @downloadURL https://gist.githubusercontent.com/vyach-vasiliev/8dfb5f5b3c22e1fc74da180f00685929/raw | |
// @updateURL https://gist.githubusercontent.com/vyach-vasiliev/8dfb5f5b3c22e1fc74da180f00685929/raw | |
// @copyright © MIT, 2017, Vyacheslav Vasiliev | |
// @grant none | |
// @run-at document-end | |
// ==/UserScript== | |
/* The MIT License | |
Copyright (c) 2017 Vyacheslav Vasiliev (vyach.vasiliev\аt\gmail\dоt\com) | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in | |
all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
THE SOFTWARE. */ | |
function bs_set_fix_selection() { | |
// setting fix for selection | |
window.bs_options = { | |
'fix_mode': true, | |
}; | |
document.addEventListener("selectionchange", function() { | |
bs_enable_selection(); | |
}); | |
document.addEventListener("keydown", function(e) { | |
// restoring hotkeys Ctrl+A, Ctrl+C, Ctrl+V | |
var key = event.keyCode || event.which; | |
if (event.ctrlKey && (key == 'A'.charCodeAt(0) || key == 'C'.charCodeAt(0) || key == 'V'.charCodeAt(0)) && window.bs_options && window.bs_options.fix_mode) { | |
e.returnValue = true; | |
// bs_enable_selection(); | |
} | |
}); | |
} | |
function bs_remove_fix_selection() { | |
// remove fix for selection | |
if (document.selection) { | |
delete document.selection.empty; | |
delete document.selection.clear; | |
} | |
delete window.getSelection().removeAllRanges; | |
if (window.bs_options) { | |
window.bs_options.fix_mode = false; | |
} | |
} | |
function bs_enable_selection() { | |
// the fix | |
if (document.selection) { | |
document.selection.empty = null; | |
document.selection.clear = null; | |
} else if (window.getSelection().removeAllRanges) { | |
window.getSelection().removeAllRanges = null; | |
} | |
} | |
bs_set_fix_selection(); | |
// for disable fix write to console bs_remove_fix_selection(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment