Skip to content Skip to sidebar Skip to footer

Greasemonkey Script To Append Text, To A Form, When Submitted With Ajax?

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

Solution 1:

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:

functionform_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.

Post a Comment for "Greasemonkey Script To Append Text, To A Form, When Submitted With Ajax?"