連結開啟方式提示增強器

根據鏈接打開方式顯示提示,新標籤頁藍色提示,當前頁面紅色提示,支援中英文切換。

目前為 2024-09-07 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Link Open Mode Tooltip Enhancer
  3. // @name:zh-CN 链接打开方式提示增强器
  4. // @name:zh-TW 連結開啟方式提示增強器
  5. // @name:ja リンクオープンモードツールチップエンハンサー
  6. // @namespace https://github.com/systemannounce/LinkTips
  7. // @version 0.0.2
  8. // @description Displays tooltips showing link open modes with color coding: blue for new tab, red for current page, supports Chinese and English.
  9. // @description:ja リンクの開き方に応じてツールチップを表示します。新しいタブは青色、同じタブは赤色で表示され、言語は中英に対応します。
  10. // @description:zh-CN 根据链接打开方式显示提示,新标签页蓝色提示,当前页面红色提示,支持中英文切换。
  11. // @description:zh-TW 根據鏈接打開方式顯示提示,新標籤頁藍色提示,當前頁面紅色提示,支援中英文切換。
  12. // @author Felix_SANA
  13. // @license MIT
  14. // @match *://*/*
  15. // @grant none
  16. // ==/UserScript==
  17.  
  18. (function() {
  19. 'use strict';
  20.  
  21. const userLang = navigator.language || navigator.userLanguage;
  22. const isChinese = userLang.includes('zh');
  23.  
  24. const messages = {
  25. newTab: isChinese ? "新标签页打开" : "New tab",
  26. currentTab: isChinese ? "当前页面覆盖" : "Current page"
  27. };
  28.  
  29. const tooltip = document.createElement("div");
  30. tooltip.className = "link-tooltip";
  31. document.body.appendChild(tooltip);
  32.  
  33. const style = document.createElement('style');
  34. style.textContent = `
  35. .link-tooltip {
  36. position: fixed;
  37. bottom: 30px;
  38. left: 10px;
  39. padding: 5px 10px;
  40. color: white;
  41. border-radius: 5px;
  42. font-size: 12px;
  43. display: none;
  44. pointer-events: none;
  45. z-index: 1000;
  46. }
  47. .link-tooltip.new-tab {
  48. background-color: blue;
  49. }
  50. .link-tooltip.current-tab {
  51. background-color: red;
  52. }
  53. `;
  54. document.head.appendChild(style);
  55.  
  56. document.addEventListener("mouseover", function(event) {
  57. const link = event.target.closest("a");
  58. if (link) {
  59. const isNewTab = link.target === "_blank";
  60. tooltip.textContent = isNewTab ? messages.newTab : messages.currentTab;
  61.  
  62. tooltip.className = `link-tooltip ${isNewTab ? 'new-tab' : 'current-tab'}`;
  63.  
  64. tooltip.style.display = "block";
  65. } else {
  66. tooltip.style.display = "none";
  67. }
  68. });
  69.  
  70. document.addEventListener("mouseout", function(event) {
  71. if (event.target.tagName === "A") {
  72. tooltip.style.display = "none";
  73. }
  74. });
  75. })();