Greasy Fork is available in English.
左键选中
当前为
// ==UserScript==
// @name 左键限制解除
// @description 左键选中
// @version 1.2
// @match *://*/*
// @run-at document-start
// @grant none
// @namespace http://greasyfork.icu/users/12375
// ==/UserScript==
(function() {
// 默认规则配置
var rule = {
name: "default",
hook_eventNames: "contextmenu|select|selectstart|copy|cut|dragstart",
unhook_eventNames: "keydown|keyup",
dom0: true,
hook_addEventListener: true,
hook_preventDefault: true,
hook_set_returnValue: true
};
// 初始化
function init() {
// hook addEventListener
if(rule.hook_addEventListener) {
EventTarget.prototype.addEventListener = addEventListener;
document.addEventListener = addEventListener;
}
}
init();
// 视频控制保护逻辑
const EV = {
select: 1, selectstart: 2, copy: 4, cut: 8, contextmenu: 16,
mousedown: 32, mouseup: 64, mousemove: 128, click: 256
};
const videoElements = new WeakMap();
const isVideoControl = (target) => {
while(target) {
if(videoElements.has(target)) return videoElements.get(target);
if(target.tagName === 'VIDEO' ||
target.classList.contains('progress-bar') ||
target.closest('video, [role="video-controls"]')) {
videoElements.set(target, true);
return true;
}
target = target.parentElement;
}
return false;
};
const { addEventListener: protoAdd } = EventTarget.prototype;
const { preventDefault: protoPrevent } = Event.prototype;
EventTarget.prototype.addEventListener = function(type, listener, options) {
const eventFlag = EV[type] || 0;
if(eventFlag & 0b00011111 && !isVideoControl(this)) {
protoAdd.call(this, type, e => e.stopImmediatePropagation(), { capture: true, ...options });
} else {
protoAdd.call(this, type, listener, options);
}
};
})();