|
1#
楼主 |
发表于 2021-9-29 20:46:37
|
只看该作者
// ==UserScript==
// @name AutoClick
// @namespace http://diveintomark.org/projects/greasemonkey/
// @description hover over links for 0.5 seconds to open in a new tab
// @include *
// ==/UserScript==
function mouseover(event) {
document._clickTarget = event.currentTarget;
document._autoclickTimeoutID = window.setTimeout(autoclick, 500);
}
function mouseout(event) {
document._clickTarget = null;
if (document._autoclickTimeoutID) {
window.clearTimeout(document._autoclickTimeoutID);
}
}
function clear(elmLink) {
if (!elmLink) { return; }
elmLink.removeEventListener('mouseover', mouseover, true);
elmLink.removeEventListener('mouseout', mouseout, true);
elmLink.removeEventListener('click', click, true);
}
function click(event) {
var elmLink = event.currentTarget;
if (!elmLink) { return false; }
clear(elmLink);
mouseout(event);
return true;
}
function autoclick() {
if (!document._clickTarget) { return; }
GM_openInTab(document._clickTarget.href);
clear(document._clickTarget);
}
if (typeof GM_openInTab != 'undefined') {
for (var i = document.links.length - 1; i >= 0; i--) {
var elmLink = document.links;
if (elmLink.href && elmLink.href.indexOf('javascript:') == -1) {
elmLink.addEventListener('mouseover', mouseover, true);
elmLink.addEventListener('mouseout', mouseout, true);
elmLink.addEventListener('click', click, true);
}
}
} |
|