本文介绍了JavaScript中的书签以切换Gmail对话视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个bookmarklet快速切换Gmail对话视图。



从,我有:

  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); 

问题是我需要两个书签。



选择器 .AO tr:第n个孩子(8)表:第n孩子(1)输入选择对话开启按钮;和 .AO tr:nth-​​child(8)表:nth-​​child(2)输入选择会话关闭。



是否有一种方法可以让一个小书签检查未被检查的小书签? (如果我运行的是错误的,我会在控制台中看到无法读取属性'click'of null 。)

解决方案

您可以简单地为您的书签添加一个条件,检查是否

  document.querySelector (div.AO table tbody tr:nth-​​child(8)table:n-type-type(2)input)。 
$ b

不是 null

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

给:

  javascript:window.location.href =https://mail.google.com+ window.location.pathname +#settings / general; sBase =div.AO table tbody tr:n-child (8)table:nth-​​of-type(; sOn = sBase +1)input; sOff = sBase +2)input; setTimeout(function(){if(document.querySelector(sOff).checked)document。 1000)


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.)

解决方案

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)

这篇关于JavaScript中的书签以切换Gmail对话视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 19:34