// ==UserScript== // @name Select text from links // @namespace http://operafan.net/forum/index.php?topic=11837.msg205482#msg205482 // @version 0.1 // @description Выделение текста ссылки // @include * // @grant none // @run-at document-start // ==/UserScript== // Выделение ссылок (function olls() { function OPLLS() { this.init.apply(this, arguments); } OPLLS.prototype = { handleEvent: function (e) { switch (e.type) { case 'mouseup': if (!getSelection() .toString()) break; // console.log('mouseup'); var t = e.target; while (t.nodeName != 'A' && t.nodeName != 'HTML') t = t.parentNode; if (!t.href) { // console.log('uninit'); this.uninit(); } break; case 'click': if (!getSelection() .toString()) { // console.log('clicked and uninit'); this.uninit(); break; } e.preventDefault(); e.stopPropagation(); // console.log('selected and uninit'); this.uninit(); } }, init: function (e) { var t = e.target; if (t.nodeName == 'IMG') return ; while (t.nodeName != 'A' && t.nodeName != 'HTML') t = t.parentNode; if (!t.href) return ; t.draggable = false; // console.log('OK'); document.addEventListener('mouseup', this, true); document.addEventListener('click', this, true); }, uninit: function () { document.removeEventListener('mouseup', this, true); document.removeEventListener('click', this, true); } } document.addEventListener('mousedown', function (e) { if (e.button != 0 || e.ctrlKey || e.altKey || e.shiftKey) return ; new OPLLS(e); }, false); })(); |