d0g User

Trying to write a script that will add a button (or even use a bookmarklet) to toggle Conversation View on and off.

This works, some of the time, to do the toggling:

window.location.href = "https://mail.google.com"+window.location.pathname+"#settings/general";
setTimeout(function() {
    convTogs = document.getElementsByName("bx_vmb");
        if (convTogs[0].checked) convTogs[1].click(); 
        else convTogs[0].click();
        document.querySelector("[guidedhelpid=save_changes_button]").click();
}, 5000);

This adds the button where I want it:

var btn = document.createElement("div");
btn.id = "cvtoggle";
btn.classList.add("G-Ni","J-J5-Ji");
btn.innerHTML = "ConversationView";
btn.setAttribute("onclick", _____code____);
document.getElementsByClassName("Cr aqJ")[0].prepend(btn)

The method of going to Settings is poor; it causes a full refresh.

The selector for the "Setting" link in the gear menu is
document.querySelector('#ms > div')
but I can't figure out how to "click" it.