2011-12-24 45 views
2

因此,我正在爲mybb論壇製作Greasemonkey腳本。它的作用是當你提交一篇文章時,它會在文章的開頭和結尾添加代碼。即使那麼這是一個不好解釋只是看看代碼,它解釋了自己Greasemonkey腳本在使用AJAX提交時將文本追加到表單中?

function form_submit(event) { 
var form = event ? event.target : this; 
    var arTextareas = form.getElementsByTagName('textarea'); 
    for (var i = arTextareas.length - 1; i >= 0; i--) { 
     var elmTextarea = arTextareas[i]; 
     elmTextarea.value = "[font=Tahoma][color=white]" + elmTextarea.value + "[/color][/font]"; 
    } 

    form._submit(); 
} 

window.addEventListener('submit',form_submit, true); 
HTMLFormElement.prototype._submit = HTMLFormElement.prototype.submit; 
HTMLFormElement.prototype.submit = form_submit; 

現在作品無處不在,我希望它除了quickreply發表回覆按鈕。我假設這是因爲quickreply按鈕使用AJAX提交表單,頁面不會重新加載。

所以我想知道我該怎麼做,所以當我點擊quickreply按鈕它附加我想要的文字。我已經尋找了一段時間和任何我能找到沒有工作

而且,這裏是一個使用AJAX(不與上面的代碼工作的按鈕)

<input id="quick_reply_submit" class="button" type="submit" accesskey="s" tabindex="2" value="Post Reply"> 
按鈕的代碼

這裏是所在

<!-- start: showthread_quickreply --> 

<br /> 
<form method="post" action="newreply.php?tid=2023403&processed=1" name="quick_reply_form" id="quick_reply_form"> 
    <input type="hidden" name="my_post_key" value="de77ee8401edd4fe176f2c6a3787d411" /> 
    <input type="hidden" name="subject" value="*" /> 
    <input type="hidden" name="action" value="do_newreply" /> 
    <input type="hidden" name="posthash" value="a67ff7b68df0a0951770f7f4a24cce8f" id="posthash" /> 
    <input type="hidden" name="quoted_ids" value="" id="quoted_ids" /> 
    <input type="hidden" name="lastpid" id="lastpid" value="18370730" /> 
    <input type="hidden" name="from_page" value="1" /> 
    <input type="hidden" name="tid" value="2023403" /> 

    <input type="hidden" name="method" value="quickreply" /> 

    <table border="0" cellspacing="1" cellpadding="4" class="tborder"> 
     <thead> 
      <tr> 
       <td class="thead" colspan="2"> 
        <div class="expcolimage"><img src="http://cdn.myforums.net/images/blackreign/collapse.gif" id="quickreply_img" class="expander" alt="[-]" title="[-]" /></div> 
        <div><strong>Quick Reply</strong></div> 
       </td> 

      </tr> 
     </thead> 
     <tbody style="" id="quickreply_e"> 
      <tr> 
       <td class="trow1" valign="top" width="22%"> 
        <strong>Message</strong><br /> 
        <span class="smalltext">Type your reply to this message here.<br /><br /> 
        <label><input type="checkbox" class="checkbox" name="postoptions[signature]" value="1" checked="checked" />&nbsp;<strong>Signature</strong></label><br /> 

        <label><input type="checkbox" class="checkbox" name="postoptions[disablesmilies]" value="1" />&nbsp;<strong>Disable Smilies</strong></label></span> 
       </td> 
       <td class="trow1"> 
        <div style="width: 95%"> 
         <textarea style="width: 100%; padding: 4px; margin: 0;" rows="8" cols="80" name="message" id="message" tabindex="1"></textarea> 
        </div> 
        <div class="editor_control_bar" style="width: 95%; padding: 4px; margin-top: 3px; display: none;" id="quickreply_multiquote"> 
         <span class="smalltext"> 

          You have selected one or more posts to quote. <a href="./newreply.php?tid=2023403&load_all_quotes=1" onclick="return Thread.loadMultiQuoted();">Quote these posts now</a> or <a href="javascript:Thread.clearMultiQuoted();">deselect them</a>. 
         </span> 
        </div> 
       </td> 
      </tr> 

      <tr> 
       <td colspan="2" align="center" class="tfoot"><input type="submit" class="button" value="Post Reply" tabindex="2" accesskey="s" id="quick_reply_submit" /> <input type="submit" class="button" name="previewpost" value="Preview Post" tabindex="3" /></td> 

      </tr> 
     </tbody> 
    </table> 
</form> 
<!-- end: showthread_quickreply --> 
+1

單挑:如果您不斷刪除您的問題,該網站將自動懲罰您,甚至禁止您提出進一步問題。耐心一點;好的答案有時會出現超過幾個小時。 – 2011-12-24 05:28:22

回答

0

您需要向我們展示本身到該按鈕關聯的JavaScript。如果它採用AJAX技術,那麼只有這樣才能知道它在做什麼。

這就是說,這段代碼將可能工作:

function form_submit (event) { 

    var form, bClickNotSubmit; 

    if (event && event.type == 'click') { 
     bClickNotSubmit = true; 
     form   = document.getElementById ('quick_reply_form'); 
    } 
    else { 
     bClickNotSubmit = false; 
     form   = event ? event.target : this; 
    } 

    var arTextareas = form.getElementsByTagName ('textarea'); 

    for (var i = arTextareas.length - 1; i >= 0; i--) { 
     var elmTextarea  = arTextareas[i]; 
     elmTextarea.value = "[font=Tahoma][color=white]" + elmTextarea.value + "[/color][/font]"; 
    } 

    if (! bClickNotSubmit) { 
     form._submit(); 
    } 
} 

window.addEventListener ('submit', form_submit, true); 
document.getElementById ('quick_reply_submit').addEventListener ('click', form_submit, true); 

HTMLFormElement.prototype._submit = HTMLFormElement.prototype.submit; 
HTMLFormElement.prototype.submit = form_submit; 


如果它不工作,目標頁面(完整的HTML,JS,CSS)保存到磁盤,壓縮文件一起分享郵編 - 這樣我們就可以看到該按鈕發生了什麼。