Open Link Under Mouse - Ctrl+Shift+Z

Mở liên kết tại vị trí con trỏ chuột hiện tại trong thẻ mới bằng Ctrl + Shift + Z

  1. // ==UserScript==
  2. // @name Open Link Under Mouse - Ctrl+Shift+Z
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Mở liên kết tại vị trí con trỏ chuột hiện tại trong thẻ mới bằng Ctrl + Shift + Z
  6. // @author Bạn
  7. // @match *://*/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. 'use strict';
  13.  
  14. let currentElement = null;
  15.  
  16. // Cập nhật phần tử dưới chuột
  17. document.addEventListener('mousemove', function (e) {
  18. currentElement = document.elementFromPoint(e.clientX, e.clientY);
  19. });
  20.  
  21. // Lắng nghe tổ hợp phím Ctrl + Shift + Z
  22. document.addEventListener('keydown', function (e) {
  23. if (e.ctrlKey && e.shiftKey && e.code === 'KeyZ') {
  24. if (!currentElement) return;
  25.  
  26. // Tìm phần tử là link gần nhất từ vị trí chuột
  27. let el = currentElement;
  28. while (el && el !== document.body) {
  29. if (el.tagName === 'A' && el.href) {
  30. window.open(el.href, '_blank');
  31. break;
  32. }
  33. el = el.parentElement;
  34. }
  35. }
  36. });
  37. })();