私はGmailのためのスクリプトを作成しています。これは、受信トレイ、すべてのメール、スパム、および作成のような左側のさまざまなリンクを複製する必要があります。 私はすべてのリンクを作成する以外は動作しています。私がクリックすると何が起こっているのか分かりません。あなたは私のコードを以下に見つけることができます。私はあなたが新しいAJAX-YスタイルのGmailを使用している場合は、次のように*あなただけのコンURLにページのhrefを変更することができ、任意のヘルプgreasemonkeyでGMailの "compose"ボタンをプログラムでクリックするにはどうすればいいですか?
// ==UserScript==
// @name GMC Test
// @namespace com.pavelgutin
// @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 > 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);
へのGreasemonkeyスクリプトで異なる動作をするかもしれない、私はあなたが求めていない願っていますスパムジェネレータの作成に役立つ... – PowerUser
@PowerUser:同じことを考えました...しかし、Googleはボットをキャッチするためにかなりスマートにすべきです電子メールを送信します。 2では、GMAILをSMTP経由で直接使用できます。では、なぜGreaseMonkeyでそれをやるのですか? – turtlepick
あなたが知っているのがGreaseMonkeyで、新しい言語を習得せずに安価なスパンボットを作っていたら、(それがどれほど非効率であっても)行く方法の1つです。 – PowerUser