Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I programatically click the "compose" button in GMail with greasemonkey?
    primarykey
    data
    text
    <p>I am creating a script for GMail, which requires me to duplicate various links on left side like inbox, all mail, spam and compose. I have all the links working except compose. I can't figure out what's going when I click on. You can find my code below. I'd appreciate any help</p> <pre><code>// ==UserScript== // @name GMC Test // @namespace com.pbg // @description test // @include http*://mail.google.com* // ==/UserScript== //loading function function tryAgain(tries) { setTimeout(function() { init(tries++); }, 1000*tries); } //gets a node by XPath function getNodeByXPath(expression, parent) { var r = parent.evaluate(expression, parent, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null); return ((r != null) ? r.iterateNext() : null); } //initialize function init(tries) { tries = tries || 0; if (tries &gt; 3) return; // give up, too many tries // Locate the canvas_frame iframe var f = document.getElementById("canvas_frame"); if (f == null) return tryAgain(tries); // Locate the document var doc = f.contentWindow.document; if (doc == null) return tryAgain(tries); // make sure all the links are loaded if (getNodeByXPath("//a[contains(@href,'#inbox')]", doc) == null) return tryAgain(tries); go(); } function go() { function fireEvent(xPath,event)//https://developer.mozilla.org/en/DOM/element.dispatchEvent { var evt = document.createEvent("MouseEvents"); evt.initMouseEvent(event, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); var cb = getNodeByXPath(xPath, doc); var canceled = !cb.dispatchEvent(evt); GM_log("event canceled = " + canceled); } var doc = document.getElementById("canvas_frame").contentWindow.document; //THE LINE BELOW WORKS //setTimeout(function(){GM_log("let's click starred!");fireEvent("//a[contains(@href,'#starred')]", "click")}, 5000); //THIS DOENS'T WORK setTimeout(function(){GM_log("now let's click compose!");fireEvent("//div[@class='J-Zh-I J-J5-Ji L3')]", "click")}, 5000); } window.addEventListener('load', init, false ); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload