0

I'm 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)

but whatever ___code___ I use, I get an error in console:

Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'report-sample' 'nonce-30MWHJuxRebUkp5KrawUmw' 'unsafe-inline' 'strict-dynamic' https: http: 'unsafe-eval'". Note that 'unsafe-inline' is ignored if either a hash or nonce value is present in the source list.

Also, 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.

0

In order to toggle the conversation view your code should use the Gmail API which could imply the use of OAuth.

It looks that the only way to toggle the conversation view setting is through the Gmail Settings web page.

There is no way to avoid a full refresh as the setting affects how Google serves the Gmail's client-side code.

One alternative is to build your own email message list by using the Gmail API.

Reference https://developers.google.com/gmail

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.