我完全不熟悉JavaScript和Greasemonkey,所以请随时纠正我,如果我这样做效率低下或不正确。如何将动态表单附加到表的末尾?
在我发布的论坛中,单击“回复”按钮将弹出一个只有文本形式的新窗口,以便发布。我想创建一个greasemonkey脚本,将回复表单的脚本添加到实际线程中页。
因此,程序通过存储讨论的表格,并将childNode追加到表格的末尾。我希望childNode是在回复页面中创建的表单。
这里是我的脚本的骨架:
// ==UserScript==
// @name QuickEeply
// @namespace http://userscripts.org/users/181447
// @description Adds "QuickReply" forms to TCC discussion posts
// @include *
// ==/UserScript==
var tables = document.getElementsByTagName("td");
for (var i = 0; i < tables.length; i++) {
if (tables[i].className == "content")
{ var editTable = tables[i];
}
}
editTable.appendChild = ''
下面是我复制并从“答复页”粘贴脚本
<form method="POST" action="http://dl.tccd.edu/index.php/classforums/posts/event=saveReply">
<input type="hidden" name="subject" size="45" id="txt_subject" maxlength="200" value="">
<br>
Message:<br>
<textarea rows="20" style="width:70%;" name="message" id="message"></textarea>
<br>
<br>
<input type="submit" id="submit_post" value="Post Reply">
<input type="hidden" name="post_id" value="1010815">
<input type="hidden" name="thread_id" value="1010815">
</form>
所以,我怎么能去创建一个脚本找到当前页面的thread_id,并为线程实际所在页面上的每个页面创建一个回复框。
编辑:这是源代码 -
http://pastebin.com/2UaUVGJA(主要讨论页)
http://pastebin.com/hAx2SPUu(回复页)
编辑2:
I've used Brock's template, and it's not working. What do I need to do to correct it?
// ==UserScript==
// @name Quick_ReplyTest
// @namespace http://userscripts.org/users/181447
// @description Inserts QuickReply
// @include *
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// ==/UserScript==
/* Optional:
window.addEventListener ("load", Greasemonkey_main, false);
*/
$(document).ready (Greasemonkey_main);
function Greasemonkey_main()
{
/*--- Get the first node inside the id="main" span (Google.com)
If that's not there, then get the first node of the html body.
*/
var TargetNode = $("a[href*='event=reply/post']");
if (!TargetNode)
TargetNode = $("body *:first");
$(TargetNode).after
(
"<form method="POST" action="http://dl.tccd.edu/index.php/classforums/posts/event=saveReply">
+ "<input type="hidden" name="subject" size="45" id="txt_subject" maxlength="200" value="">"
+ "<br> Message:<br>"
+ "<textarea rows="20" style="width:70%;" name="message" id="message"></textarea>"
+ "<br> <br>"
+ "<input type="submit" id="submit_post" value="Post Reply">"
+ "<input type="hidden" name="post_id" value="1010815">"
+"<input type="hidden" name="thread_id" value="1010815">"
+"</form>"
);
}
很难说没有看到您正在查看的HTML。帖子ID和帖子ID变量是否可用? – desau 2010-06-26 00:37:56
我编辑过它以包含源代码。 – Parseltongue 2010-06-26 00:49:03