You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.3 KiB
44 lines
1.3 KiB
// ==UserScript==
|
|
// @name Disable Pop-ups Button
|
|
// @namespace http://tampermonkey.net/
|
|
// @version 1.0
|
|
// @description 在任意页面添加按钮,点击后禁用 window.open 弹窗行为
|
|
// @author Jack
|
|
// @match *://*/*
|
|
// @grant none
|
|
// ==/UserScript==
|
|
|
|
(function() {
|
|
'use strict';
|
|
|
|
// 创建按钮
|
|
const button = document.createElement('button');
|
|
button.textContent = "Disable Pop-ups";
|
|
|
|
// 按钮样式
|
|
button.style.position = "fixed";
|
|
button.style.top = "12.5%";
|
|
button.style.right = "1%";
|
|
button.style.transform = "translateY(-50%)";
|
|
button.style.padding = "3px 8px";
|
|
button.style.fontSize = "10px";
|
|
button.style.backgroundColor = "#007baf";
|
|
button.style.color = "#fff";
|
|
button.style.border = "none";
|
|
button.style.borderRadius = "5px";
|
|
button.style.cursor = "pointer";
|
|
button.style.zIndex = "10000";
|
|
|
|
// 点击事件,覆盖 window.open
|
|
button.addEventListener('click', () => {
|
|
const originalOpen = window.open;
|
|
window.open = function() {
|
|
return originalOpen('', '_self');
|
|
};
|
|
// 可选:点击后提示用户已禁用弹窗
|
|
alert('Pop-ups have been disabled for this page.');
|
|
});
|
|
|
|
// 挂载按钮到页面
|
|
document.body.appendChild(button);
|
|
})();
|
|
|