Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want a bookmarklet to quickly toggle the Gmail conversation view on and off.

Starting from @seahorsepip's solution, I have:

javascript:window.location.href = "https://mail.google.com/mail/u/0/#settings/general";setTimeout(function(){document.querySelector("div.AO table tbody tr:nth-child(8) table:nth-child(2) td:nth-child(1) input:not(:checked)").click();document.querySelector("[guidedhelpid=save_changes_button]").click();}, 1000);

The problem is that I need two bookmarklets.

Selector .AO tr:nth-child(8) table:nth-child(1) input selects the "Conversation ON" button; and .AO tr:nth-child(8) table:nth-child(2) input selects "Conversation OFF".

Is there a way to have one bookmarklet that will check the one that is not checked? (If I run the "wrong" one I see Cannot read property 'click' of null in console.)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
146 views
Welcome To Ask or Share your Answers For Others

1 Answer

You could simply add a condition to your bookmarklet, checking if

document.querySelector("div.AO table tbody tr:nth-child(8) table:nth-of-type(2) input").checked

isn't null:

window.location.href = "https://mail.google.com" + window.location.pathname + "#settings/general";
sBase = "div.AO table tbody tr:nth-child(8) table:nth-of-type(";
sOn = sBase + "1) input";
sOff = sBase + "2) input";

setTimeout(function(){
    if (document.querySelector(sOff).checked)
        document.querySelector(sOn).click();
    else
        document.querySelector(sOff).click();
    document.querySelector("[guidedhelpid=save_changes_button]").click();
}, 1000);

Giving:

javascript:window.location.href="https://mail.google.com"+window.location.pathname+"#settings/general";sBase="div.AO table tbody tr:nth-child(8) table:nth-of-type(";sOn=sBase+"1) input";sOff=sBase+"2) input";setTimeout(function(){if(document.querySelector(sOff).checked) document.querySelector(sOn).click();else document.querySelector(sOff).click();document.querySelector("[guidedhelpid=save_changes_button]").click()},1000)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...