-2

I know nothing on how to code so i need help making this one. I'm trying to auto click a button on a page as soon as it come up. I'm using the Chrome extension called tampermonkey to do this.

The HTML button i'm trying to click is this:

<div class="content preAppear fadeIn" style="position: absolute; margin-top: 0px; top: 277px; left: 730px;">
    <div class="header cf">
        <a class="btn_close"></a>
    </div>
    <div class="innerContent" style="display: block;"><p>Are you sure you want to leave this conversation?</p><p><a data-conversationid="12874874" class="btn_blue btn_confirm">Leave</a><a class="btn_blue btn_cancel">Cancel</a></p></div>
</div>

I have no idea what i'm doing so please be patient and ask me anything. I've look at other people similar problems and I can't figure out how to use it for mine. I need specific help on this.

Fogey
  • 15
  • 4
  • You should really use google to find the existing solutions and there are [lots of them](https://www.google.com/search?q=stackoverflow+greasemonkey%7Ctampermonkey+click+button). Also do note that Stack Overflow isn't a tutoring place so you've got to have skills to use the solution. – wOxxOm Nov 29 '15 at 02:30

1 Answers1

0
// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You

// @match        http://bungie.net

// @grant        none
// ==/UserScript==
/* jshint -W097 */
'use strict';

var btnShowObserver = function() {

  var innerContent = document.getElementsByClassName('innerContent')[0];

  if (innerContent.style.display === 'block') {
    innerContent.getElementsByClassName('btn_confirm')[0].click();
  }
}

window.setInterval(btnShowObserver, 500);
Rex Hsu
  • 464
  • 2
  • 7
  • Doesn't work. Unless i'm doing it wrong. Am I supposed to remove the line below "// want to click cancel button" if I want to click confirm right away? – Fogey Nov 30 '15 at 01:52
  • If you want to click confirm button, remove "btn_cancel.click();" – Rex Hsu Nov 30 '15 at 04:03
  • It still doesn't work. I do have the right @match set because it shows it active on the website. Is there anything else i'm supposed to change? – Fogey Nov 30 '15 at 17:39
  • Can you paste the website link? – Rex Hsu Dec 01 '15 at 01:09
  • It's not on the page right away, you have to click 2 things before it shows on the page. Its [Bungie.net](http://Bungie.net) and you can get to it anywhere on the site. You have to click on [This](http://pastebin.com/TYjuXwqQ) to beable to click on [This](http://pastebin.com/MqUjcgDa). Then once you click on those it makes [This](http://pastebin.com/emstRxck) pop up. [Here](http://pastebin.com/0eTMhi8k) is the whole pages code, i think. Sorry if that was confusing, so here is a list in order. First Buttion – Fogey Dec 01 '15 at 03:57
  • [Bungie.net](http://Bungie.net) -> [First Button](http://pastebin.com/TYjuXwqQ) -> [Second Button](http://pastebin.com/MqUjcgDa) -> [Whole page](http://pastebin.com/0eTMhi8k) – Fogey Dec 01 '15 at 04:04
  • So, you want the script to auto click the 'Leave' button when the site shows 'Are you sure you want to leave this conversation?' – Rex Hsu Dec 01 '15 at 06:16
  • Can you paste the full URL of 'Whole page'? – Rex Hsu Dec 02 '15 at 01:52
  • What full URL? The button is across the whole website and i have the code for the one page on there. Do you mean https://www.bungie.net? – Fogey Dec 02 '15 at 03:58
  • 'bungie.net' is domain, 'www.bungie.net/en/Support' is full URL. – Rex Hsu Dec 02 '15 at 04:34
  • But it's not specifically on /en/support. I guess you could just put any /blablabla you want because you can get it on any page. Its not on a specific page. So here are a few. https://www.bungie.net/en/Profile, https://www.bungie.net/en/Community, and https://www.bungie.net/en/Armory – Fogey Dec 02 '15 at 04:40
  • Try the post, it's edited. – Rex Hsu Dec 02 '15 at 05:34
  • YES!!! It worked, Thank you so much!! – Fogey Dec 02 '15 at 05:50
  • The function will check every 500 millisecond, you can modify the check interval shorter or longer. (change the number '500') – Rex Hsu Dec 02 '15 at 06:56