-3

I am trying to hide "Add to Cart" and "Buy Now" buttons on shopping websites that a user might visit. Following is my code, it works great on Amazon India but does not on any other website. I am trying to hide the span ID but would like to know how can we hide the button type or input action?

// ==UserScript==
// @name         Google - Amazon Shopping Button Disappear
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Make the shopping button disappear in Amazon.In when a page is loaded
// @author       Wipro
// @match        http://*/*
// @require       http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @grant        none
// ==/UserScript==

$("span.a-button-inner") 
           .hide ();

I have also tried the following with no luck.

document.getElementById('button').style.visibility = "hidden"; 

Regards, Shrey

  • 1
    You would have to add your HTML code so we can see what element you are trying to hide. – Koby Douek Apr 27 '17 at 13:46
  • How do you know they've named the "Buy Now" button the same thing on every website? – entropic Apr 27 '17 at 13:48
  • Your code is necessary to help you fix the bug. Share it and we can help you. – Damien Apr 27 '17 at 13:51
  • Do you have any console errors through a web inspector? – DraganAscii Apr 27 '17 at 14:10
  • I am using tampermonkey on Chrome to use the code. I am using the following code, $("span.a-button-inner") .hide (); I tried the code given by @UberGrunk, however I figured out that all websites have different button names. Is there a way we can make all buttons disappear in any website. Can we make element type "hidden"? – Shrey Srivastava Apr 28 '17 at 06:39

1 Answers1

0

I think something like this might be your best bet altho it might be slow on large sites

A code example for you

var aTags = document.getElementsByTagName("a");
var buttonTags = document.getElementsByTagName("button");
var searchText1 = "Add To Cart", searchText2 = "Buy Now";

for (var i = 0; i < aTags.length; i++) {
    if (aTags[i].textContent == searchText1 || aTags[i].textContent == searchText2) {
        aTags[i].style.visibility = "hidden";
    }
}

for (var i = 0; i < buttonTags.length; i++) {
    if (buttonTags[i].textContent == searchText1 || buttonTags[i].textContent == searchText2) {
        buttonTags[i].style.visibility = "hidden";
    }
}

You might want to make the text comparison less sensitive tho

Community
  • 1
  • 1
UberGrunk
  • 63
  • 8
  • I tried the code, however I figured out that all websites have different button names. Is there a way we can make all buttons disappear in any website. Can we make element type "hidden"? I am using TamperMonkey on Chrome to run the codes. – Shrey Srivastava Apr 28 '17 at 06:41
  • Well, you just remove the if()-condition in the loops and the style.visibility = "hidden" will be applied to all of the elements, this will also remove all links tho and all buttons regardless of what they do so it might break for example page navigation and functionality – UberGrunk Apr 28 '17 at 10:59