我完全不熟悉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