Skip to content

Instantly share code, notes, and snippets.

@Dinh-Ng
Last active April 20, 2025 08:12
Show Gist options
  • Select an option

  • Save Dinh-Ng/ba15649db4f138b34f188aeccf04558f to your computer and use it in GitHub Desktop.

Select an option

Save Dinh-Ng/ba15649db4f138b34f188aeccf04558f to your computer and use it in GitHub Desktop.
Chặn Popup Quảng Cáo - Giữ Mở Tab Thủ Công
// ==UserScript==
// @name Chặn Popup Quảng Cáo - Giữ Mở Tab Thủ Công
// @namespace http://tampermonkey.net/
// @version 1.1
// @description Ngăn chặn các tab/quảng cáo popup tự động mở nhưng vẫn cho phép mở tab thủ công bằng chuột phải
// @author Bạn
// @match *://*.truyenqqgo.com/*
// @grant none
// @run-at document-start
// @icon https://st.truyenqqgo.com/template/frontend/images/favicon.ico
// ==/UserScript==
(function() {
'use strict';
// Lưu hàm gốc window.open
const originalOpen = window.open;
// Ghi đè window.open để kiểm tra trước khi mở
window.open = function(url, name, features) {
const e = window.event || arguments.callee.caller.arguments[0];
// Cho phép nếu là từ: chuột phải, Command/Ctrl, click giữa
if (e && (e.button === 2 || e.metaKey || e.ctrlKey || e.which === 2)) {
return originalOpen(url, name, features);
}
console.log('[Chặn Popup] Đã chặn mở tab: ' + url);
return null;
};
// Xử lý sự kiện click trên thẻ <a>
document.addEventListener('click', function(e) {
const target = e.target.closest('a[target="_blank"]');
if (!target) return;
// Cho phép nếu là: chuột phải, Command/Ctrl, click giữa
if (e.button === 2 || e.metaKey || e.ctrlKey || e.which === 2) {
return;
}
// Chặn các click trái thông thường
e.preventDefault();
e.stopImmediatePropagation();
console.log('[Chặn Popup] Đã chặn click trái mở tab');
}, true);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment