ClickButton

Click on every button containing the text inserted

当前为 2016-09-09 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         ClickButton
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Click on every button containing the text inserted
// @author       Leonard Okaz
// @match        http://*/*
// @match        https://*/*
// @grant        none
// ==/UserScript==

(function() {
    var button = document.createElement("BUTTON");
    var text = "ClickButton script Tampermonkey";
    var buttonText = document.createTextNode(text);
    button.appendChild(buttonText);
    button.style.background = "#8A2BE2";
    button.style.color = "white";
    button.style.position = "relative";
    button.style.zIndex = "1000";
    button.onclick = function() {
        var matchingText = prompt("Please enter the text", "ClickButton script Tampermonkey");
        if(matchingText !== null) {
            var buttons = document.getElementsByTagName('button');
            for (var iteratorButton = 0; iteratorButton < buttons.length; iteratorButton++) {
                // Check if the button is not hidden and clickable, otherwise it can become a source of hack
                if (buttons[iteratorButton].style.display ===  "none") continue;
                else if (buttons[iteratorButton].innerHTML === matchingText) {
                    buttons[iteratorButton].click();
                }
            }
        }
    };
    document.body.insertBefore(button, document.body.firstChild);
})();