// ==UserScript==
// @
name 打开链接弹出框
// @
namespace http://your.namespace.com// @
version 0.1
// @
description 在按下 Shift 键的同时单击左键时,在弹出框中打开链接
// @
author Your Name
// @
match http://*/*
// @
match https://*/*
// @
grant none
// ==/UserScript==
(function() {
document.addEventListener('click', function(event) {
if (event.shiftKey && event.button === 0) {
event.preventDefault();
var targetElement = event.target;
while (targetElement && targetElement.tagName !== 'A') {
targetElement = targetElement.parentElement;
}
if (targetElement && targetElement.tagName === 'A') {
var url = targetElement.href;
var popupWidth = 600;
var popupHeight = 400;
var left = (window.innerWidth - popupWidth) / 2;
var top = (window.innerHeight - popupHeight) / 2;
var popup = window.open(url, '_blank', 'width=' + popupWidth + ',height=' + popupHeight + ',top=' + top + ',left=' + left);
if (popup) {
popup.focus();
} else {
alert('请允许弹出窗口以查看链接!');
}
}
}
});
})();