0
在特定論壇中,單擊答覆按鈕會生成一個帶有文本窗體的新窗口來鍵入答覆。我想實現一個腳本來在主頁面中創建特定的文本格式(而不是產生一個新的窗口)。我會如何去做這件事?使用Greasemonkey和JQuery向特定頁面添加動態表單
這裏是我想要實現對腳本的網頁源代碼:
http://pastebin.com/2UaUVGJA(主要討論頁) http://pastebin.com/hAx2SPUu(回覆頁)
這裏是企圖腳本(注意,我仍然需要一些方法來提取適當的post_id值,並根據該id創建表單),但根本不起作用。
// ==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> \
'
);
}
令人難以置信的指導!感謝您花時間回答我的問題,並對代碼進行評論。但是,腳本不起作用。無論如何,我可以調試它來發現問題嗎?我是否必須導入Jquery數據庫,還是需要這樣的聲明才能爲我做? – Parseltongue 2010-06-27 19:04:25
是的,「require」語句處理jQuery的導入。它僅在安裝腳本時執行一次。所以,如果您認爲這已經損壞或者您做了重大更改,請使用Greasemonkey「管理用戶腳本」面板來卸載並重新安裝該腳本。 – 2010-06-27 21:05:21
*如何*它不起作用?它對我的頁面本地副本非常有用 - 當然,我無法發佈實際的回覆。至於調試...是的,這並不難。安裝Firebug擴展(http://getfirebug.com/)。然後打開Firebug的JavaScript控制檯,打開所有錯誤跟蹤,然後重新加載頁面。請注意由腳本引起的任何錯誤(唉,大多數頁面本身都會導致大量錯誤)。更多Firebug使用信息:http://stackoverflow.com/questions/511539/using-firebug-where-are-the-js-errors-shown/511563#511563 – 2010-06-27 21:17:07