Firefox extension - click only if 2 attributes are true

Scorpion Ghost

Jr. VIP
Jr. VIP
Joined
Mar 22, 2013
Messages
5,454
Reaction score
4,978
Website
smmorigins.com
I have a Firefox extension that clicks a certain button, and it works well.

This code does the clicking:

Code:
function xxBtn(){
  var btn = document.querySelector('button.ooo-qqq-vvv')
  if( !btn ){ return }
  btn.click()
}

My problem is that the extension clicks every 5 seconds, and I want it to do so, but only if an additional element is true.

This is the code the extension clicks:

Code:
<button class="ooo-qqq-vvv zzz-ttt" aria-label="One (k)" title="One (p)">
Code:
<button class="ooo-qqq-vvv zzz-ttt" aria-label="One (k)" title="Two (p)">
Code:
<button class="ooo-qqq-vvv zzz-ttt" aria-label="One (k)" title="Three (p)">

So the code changes sometimes, as you can see above. As long as the extension just clicks on "ooo-qqq-vvv" it will click every 5 seconds.

But if I can make it click on "ooo-qqq-vvv + One (p)" and also on "ooo-qqq-vvv + Two (p)" then I can have it work how I want. So both the class and title or aria-label to be true in order to make a successful click.

I feel like it's a simple edit, maybe something like this:

Code:
function xxBtn(){
  var btn = document.querySelector('button.ooo-qqq-vvv').getAttribute("title=('One (p)')");
  if( !btn ){ return }
  btn.click()
}

Anyone knows? @Gogol
 

Gogol

Jr. Executive VIP
Jr. VIP
Joined
Sep 10, 2010
Messages
8,656
Reaction score
13,314
Try something like


function xxBtn(){ var btn = document.querySelector('button.ooo-qqq-vvv'); if( typeof btn.getAttribute("title") == 'undefined' || (btn.getAttribute("title").trim() != 'One (p)' && btn.getAttribute("title").trim() != 'Two (p)') ) return; btn.click() }

Edit: for more element titles, you can expand the if condition and add more conditions into it.
 

Blackhat Lifter

Banned - Inappropriate behavior
Joined
Aug 4, 2013
Messages
3,596
Reaction score
8,861
Try something like


function xxBtn(){ var btn = document.querySelector('button.ooo-qqq-vvv'); if( typeof btn.getAttribute("title") == 'undefined' || (btn.getAttribute("title").trim() != 'One (p)' && btn.getAttribute("title").trim() != 'Two (p)') ) return; btn.click() }

Edit: for more element titles, you can expand the if condition and add more conditions into it.
dear so smart, wish to be like you one day.. javascript guru

enjoy the weekend deer
 

Scorpion Ghost

Jr. VIP
Jr. VIP
Joined
Mar 22, 2013
Messages
5,454
Reaction score
4,978
Website
smmorigins.com
Try something like


function xxBtn(){ var btn = document.querySelector('button.ooo-qqq-vvv'); if( typeof btn.getAttribute("title") == 'undefined' || (btn.getAttribute("title").trim() != 'One (p)' && btn.getAttribute("title").trim() != 'Two (p)') ) return; btn.click() }

Edit: for more element titles, you can expand the if condition and add more conditions into it.

Not quite a guru, but this is my bread and butter lol. ;)

happy weekend to you too deer :D

p.s. Scorpion, the code given can be further improved. I just gave u something quick and dirty. :p

Dude, you're the shit dude! Like good shit :D

It worked. Quick and dirty is exactly how I like it. Works every time dog haha ;)

So yeah, it worked. Thanks for going above and beyond and giving me a way to add 2 titles, because that's exactly what I wanted. I want a click to happen if One and Two are true in the title, but not if Three is true. And the code you gave did just that, and it works perfectly.

Thanks man, I don't know what I'd do without you :D

 
Top