当使用AJAX提交的Greasemonkey脚本附加文字,表格,?脚本、表格、文字、AJAX

2023-09-10 20:04:16 作者:枕边徒留芳香

所以,我想提出一个的Greasemonkey脚本,针对一MyBB的论坛。它的作用是,当你提交后它增加了code的开始和帖子的末尾。那么,即使这是一个不好解释只看code,它解释了自己

 函数form_submit(事件){
VAR形式=事件?将event.target:这一点;
   VAR arTextareas = form.getElementsByTagName('文本区域');
   对于(VAR I = arTextareas.length  -  1; I> = 0;我 - ){
       VAR elmTextarea = arTextareas [I]
       elmTextarea.value =[字体=宋体] [颜色=白]+ elmTextarea.value +[/ COLOR] [/ font];
   }

   form._submit();
}

window.addEventListener('提交',form_submit,真正的);
HTMLFormElement.prototype._submit = HTMLFormElement.prototype.submit;
HTMLFormElement.prototype.submit = form_submit;
 

现在它的工作原理无处不在,我希望它除了 quickreply 的发表回复按钮。我假定这是因为 quickreply 的按钮使用AJAX来提交表单的页面不会被重新加载。

所以,我想知道我怎么可以这样,当我点击的 quickreply 的按钮,就追加我希望它的文本。我寻觅一段时间了,任何事情,我能找到没有工作

另外,这里是$ C $下使用AJAX(不与上述code工作的按钮)

按钮

 <输入ID =quick_reply_submit级=按钮类型=提交ACCESSKEY =S的tabindex =2值=发表回复>
 

这里是它的位置

 <  - 启动:showthread_quickreply  - >

< BR />
<形式方法=邮报行动=newreply.php TID = 2023403&放大器;加工= 1NAME =quick_reply_formID =quick_reply_form>
    <输入类型=隐藏名称=my_post_key值=de77ee8401edd4fe176f2c6a3787d411/>
    <输入类型=隐藏名称=主题值=*/>
    <输入类型=隐藏名称=行动值=do_newreply/>
    <输入类型=隐藏名称=posthash值=a67ff7b68df0a0951770f7f4a24cce8fID =posthash/>
    <输入类型=隐藏名称=quoted_ids值=ID =quoted_ids/>
    <输入类型=隐藏名称=lastpidID =lastpid值=18370730/>
    <输入类型=隐藏名称=from_page值=1/>
    <输入类型=隐藏名称=TID值=2023403/>

    <输入类型=隐藏名称=方法值=quickreply/>

    <表格边框=0CELLSPACING =1的cellpadding =4级=tborder>
        < THEAD>
            &其中; TR>
                &所述; TD类=THEAD列跨度=2>
                    < D​​IV CLASS =expcolimage>< IMG SRC =htt​​p://cdn.myforums.net/images/blackreign/collapse.gifID =quickreply_img级=膨胀ALT =[ - ] 标题=[ - ]/>< / DIV>
                    < D​​IV><强>快速回复< / STRONG>< / DIV>
                < / TD>

            < / TR>
        < / THEAD>
        < TBODY风格=ID =quickreply_e>
            &其中; TR>
                < TD类=trow1VALIGN =顶WIDTH =22%>
                    <强>消息< / STRONG>< BR />
                    <跨度类=smalltext>键入此消息在这里您的回复< BR />< BR />
                    <标签><输入类型=复选框级=复选框名称=postoptions [签名]值=1检查=检查/>&安培; NBSP;<强>签名< / STRONG&GT ;< /标签>< BR />

                    <标签><输入类型=复选框级=复选框名称=postoptions [disablesmilies]值=1/>&安培; NBSP;<强>禁用表情符号< / STRONG>< /标签>< / SPAN>
                < / TD>
                < TD类=trow1>
                    < D​​IV的风格=宽度:95%>
                        < textarea的风格=宽度:100%;填充:4PX;保证金:0;行=8COLS =80名称=消息的id =消息的tabindex =1>&所述; / textarea的>
                    < / DIV>
                    < D​​IV CLASS =editor_control_bar的风格=宽度:95%;填充:4PX;的margin-top:的3px;显示:无;的id =quickreply_multiquote>
                        <跨度类=smalltext>

                            您已选择一个或多个回复。 < A HREF =./ newreply.php TID = 2023403&放大器; load_all_quotes = 1的onclick =返回Thread.loadMultiQuoted();现在与其中引用这些职位;&GT / a取代;或LT; A HREF =JavaScript的:Thread.clearMultiQuoted();>取消选择和LT; / a取代。
                        < / SPAN>
                    < / DIV>
                < / TD>
            < / TR>

            &其中; TR>
                < TD合并单元格=2ALIGN =中心类=TFOOT><输入类型=提交级=按钮值=发表回复的tabindex =2ACCESSKEY =S标识=quick_reply_submit/> <输入类型=提交级=按钮NAME =previewpost值=preVIEW邮报的tabindex =3/>< / TD>

            < / TR>
        < / TBODY>
    < /表>
< /形式GT;
!<  - 端:showthread_quickreply  - >
 
greasemonkey Firefox中Greasemonkey用户脚本的初学者指南

解决方案

您需要向我们表明赞同该按钮的JavaScript。如果它的AJAX供电,这是要知道它在做什么的唯一方式。

这是说,这code会的也许的工作:

 函数form_submit(事件){

    变种形式,bClickNotSubmit;

    如果(事件和放大器;&安培; Event.type访问==点击){
        bClickNotSubmit = TRUE;
        表=的document.getElementById('quick_reply_form');
    }
    其他 {
        bClickNotSubmit = FALSE;
        形式=事件?将event.target:这一点;
    }

    VAR arTextareas = form.getElementsByTagName('文本区域');

    对于(VAR I = arTextareas.length  -  1; I> = 0;我 - ){
        VAR elmTextarea = arTextareas [I]
        elmTextarea.value =[字体=宋体] [颜色=白]+ elmTextarea.value +[/ COLOR] [/ font];
    }

    如果(!bClickNotSubmit){
        form._submit();
    }
}

window.addEventListener('提交',form_submit,真正的);
。的document.getElementById('quick_reply_submit')的addEventListener('点击',form_submit,真正的);

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

如果它不工作,目标页面(完整的HTML,JS,CSS)保存到磁盘,压缩文件,共同承担这个拉链 - 这样我们就可以看到正在发生的事情与该按钮

So I am making a Greasemonkey script for a mybb forum. What it does is that when you submit a post it adds code to the beginning and the end of the post. Well even though that is a bad explanation just look at the code, it explains itself

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;

Now it works everywhere I want it to except the quickreply post reply button. I am assuming this is because the quickreply button uses AJAX to submit the form and the page does not get reloaded.

So I am wondering how I can have it so that when I click the quickreply button it appends the text I want it to. I have searched around for a while and anything that i could find did not work

Also, here is the code for the button that uses ajax(The button that doesn't work with the above code)

<input id="quick_reply_submit" class="button" type="submit" accesskey="s" tabindex="2" value="Post Reply">

And here is where it is located

<!-- 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 -->

解决方案

You need to show us the javascript that associates itself to that button. If it's AJAX powered, that's the only way to know what it's doing.

That said, this code will probably work:

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;

If it doesn't work, save the target page (complete HTML, JS, CSS) to a disk, zip the files together and share the zip -- so that we can see what is happening with that button.