Clickable Elements Highlighter

Highlights clickable elements on web pages.

Stan na 26-01-2024. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Clickable Elements Highlighter
// @namespace    http://your-namespace-here
// @version      1.0.5
// @description  Highlights clickable elements on web pages.
// @match        http*://*/*
// ==/UserScript==


// main.js

(function() {
  const clickableElements = document.querySelectorAll("a, button, input, select, textarea, [role=button], [role=link], [role=checkbox], [role=radio], [role=menuitem], [contenteditable=true]");

  clickableElements.forEach(element => {
    element.addEventListener("click", function(event) {
      this.style.border = "";
      event.stopPropagation();
    });
    element.addEventListener("mousedown", function(event) {
      if (event.which === 2) {
        this.style.border = "";
        event.stopPropagation();
      }
    });
    element.style.border = "1px solid red";
  });

  // Call function to mark clickable elements in other JavaScript files
  markClickableElementsInOtherFiles();

  // Toggle button for turning on/off the effect
  const toggleButton = document.createElement("button");
  toggleButton.textContent = "关闭效果";
  toggleButton.style.position = "fixed";
  toggleButton.style.top = "10px";
  toggleButton.style.right = "10px";
  toggleButton.style.padding = "10px";
  toggleButton.style.background = "white";
  toggleButton.style.border = "1px solid black";
  toggleButton.style.zIndex = "9999";

  let effectEnabled = true;

  toggleButton.addEventListener("click", function() {
    effectEnabled = !effectEnabled;

    if (effectEnabled) {
      toggleButton.textContent = "关闭效果";
      clickableElements.forEach(element => {
        element.style.border = "1px solid red";
      });
      markClickableElementsInOtherFiles();
    } else {
      toggleButton.textContent = "开启效果";
      clickableElements.forEach(element => {
        element.style.border = "";
      });
    }
  });

  document.body.appendChild(toggleButton);

function markElementsWithEvents() {
  const allElements = document.querySelectorAll('*');
  allElements.forEach(element => {
    for (let key in element) {
      if (key && key.startsWith("on") && typeof element[key] === "function") {
        element.style.border = "1px solid red";
        //break;// 如果发现任何事件,就停止搜索其他事件
      }
    }
  });
}

})();