ClickButton

Click on every button (or disguised button) containing the text inserted

  1. // ==UserScript==
  2. // @name ClickButton
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Click on every button (or disguised button) containing the text inserted
  6. // @author Leonard Okaz
  7. // @match http://*/*
  8. // @match https://*/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. var button = buildButton();
  14. button.onclick = function() {
  15. var matchingText = prompt("Please enter the text", null);
  16. if(matchingText !== null) {
  17. var buttons = document.querySelectorAll("button, input[type=submit], a");
  18. for (var iButton = 0; iButton < buttons.length; iButton++) {
  19. var button = buttons[iButton];
  20. alert(button.type);
  21. if (!securedButton(button)) { alert("Security"); continue; }
  22. else if (button.type === "button" || (button.type === "" && button.href !== "")) {
  23. if (button.innerHTML === matchingText) {
  24. buttons[iButton].click();
  25. }
  26. }
  27. else if (button.type === "submit") { //input[type=submit]
  28. if (button.value === matchingText) {
  29. buttons[iButton].click();
  30. }
  31. }
  32. }
  33. }
  34. };
  35. document.body.insertBefore(button, document.body.firstChild);
  36. })();
  37.  
  38. function buildButton() {
  39. var button = document.createElement("BUTTON");
  40. var buttonText = document.createTextNode("ClickButton script Tampermonkey");
  41. button.appendChild(buttonText);
  42. button.style.background = "#8A2BE2";
  43. button.style.color = "white";
  44. button.style.position = "relative";
  45. button.style.zIndex = "1000";
  46. return button;
  47. }
  48.  
  49. // Check if the button is not hidden and clickable, otherwise it can become a source of hack
  50. function securedButton(button) {
  51. if (button.style.display !== "none") {
  52. return true;
  53. }
  54. if (buttons[iteratorButton].style.opacity === "1" || (buttons[iteratorButton].style.opacity === "" && buttons[iteratorButton].style.opacity !== "0")) {
  55. return true;
  56. }
  57. return false;
  58. }