0

So, I've got a tampermonkey script being injected into Twitter, and I want to add action to the beginning of an eventqueue when the Tweet button is clicked. So far, I have my action firing, but return false; and e.preventDefault() neither one stop the form from submitting when adding a click listener to the button or a submit listener to the form. The submit listener event never actually is triggered, but the button one is. So, my question is, what's the best way to make sure:

  • My action happens first
  • No other actions happen until my ajax is done

I can't seem to stop or find the way that Twitter is submitting the tweet. Unfortunately, my action fires off an ajax call and that ajax call doesn't call its done callback until after the tweet is submitted.

UPDATE: I've also tried e.stopImmediatePropogation() to no avail..

Christopher Wirt
  • 1,108
  • 1
  • 10
  • 21

1 Answers1

0

This is only a guess and maybe not that much helpful, but i think on the submit is already a linked javascript eventListener/function from Twitter. Don't know if this is part of the problem how you can handle this.

See (open the browser console to see the output):

var myApp = new function() {
    this.init = function() {
        var myForm = document.getElementById('myForm');
        
        //first eventListener
        myForm.addEventListener("submit", function(e){
            e.preventDefault();
            console.log('submit');
        });
        
        //second eventListener
        myForm.addEventListener("submit", function(e){
            e.preventDefault();
            console.log('submit2');
            e.stopPropagation();
            return false;
        });
    }
};

myApp.init();
<form id="myForm">
    <input type="submit" value="click" />
</form>

Edit: i found this and it's possible helpful: How to find event listeners on a DOM node when debugging or from the JavaScript code?

Community
  • 1
  • 1
MrDeclare
  • 13
  • 5