Search code examples
javascriptjquerybrowserconsolepushbullet

Console Script to Trigger 3,000+ Consecutive Click-enabled Front-end Actions


The Problem

Pushbullet, due to some bug caused by the outdated version of Android on my Asus Nexus 7, erroneously added the device thousands of times.

I need to delete all of these entries in a programatic way (via a script) because the sheer number of deletions (each requiring multiple clicks) is just too much to do manually. (And I've contacted Pushbullet but they will not help -- no beef. Seriously, I completely understand. Also PushBullet is awesome.)


The Code As It Is on Pushbullet's Device Listing Page

Originally, the buttons I need to click appear like this:

  <table class="crud" style="width:100%;white-space:nowrap">
    <tr>
      <td><input type="text" placeholder="nickname" value="Sony D5803" name="nickname" onchange="window._handler[12].apply(null, arguments);" onblur="window._handler[13].apply(null, arguments);" onkeypress="window._handler[14].apply(null, arguments);" /></td>
      <td>added 6 days ago</td>
      <td><button class="hover-red" onclick="window._handler[15].apply(null, arguments);">Delete</button></td>
    </tr>

    <tr>
      <td><input type="text" placeholder="nickname" value="Firefox" name="nickname" onchange="window._handler[20].apply(null, arguments);" onblur="window._handler[21].apply(null, arguments);" onkeypress="window._handler[22].apply(null, arguments);" /></td>
      <td>added 4 months ago</td>
      <td><button class="hover-red" onclick="window._handler[23].apply(null, arguments);">Delete</button></td>
    </tr>

    <-- I need to delete THESE entries below -->    
    <-- I need to delete THESE entries below -->    
    <-- I need to delete THESE entries below -->    
    <tr>
      <td><input type="text" placeholder="nickname" value="Asus Nexus 7" name="nickname" onchange="window._handler[28].apply(null, arguments);" onblur="window._handler[29].apply(null, arguments);" onkeypress="window._handler[30].apply(null, arguments);" /></td>
      <td>added 6 months ago</td>
      <td><button class="hover-red" onclick="window._handler[31].apply(null, arguments);">Delete</button></td>
    </tr>

    <tr>
      <td><input type="text" placeholder="nickname" value="Asus Nexus 7" name="nickname" onchange="window._handler[32].apply(null, arguments);" onblur="window._handler[33].apply(null, arguments);" onkeypress="window._handler[34].apply(null, arguments);" /></td>
      <td>added 6 months ago</td>
      <td><button class="hover-red" onclick="window._handler[35].apply(null, arguments);">Delete</button></td>
    </tr>
    <-- I need to delete THESE entries above -->    
    <-- I need to delete THESE entries above -->    
    <-- I need to delete THESE entries above -->    
    ...

After clicking the "Delete" button, A "Cancel" button goes in place of the "Delete" button, and the "Delete" button is moved to the side, next to the "Cancel" button.

In order for an item/device to be deleted, I need it to click the first "Delete" button, and then the second "Delete" button. I refer to them as "first" and "second" because originally the "Delete" button has the class ".hover-red" but after clicking it, the updated "Delete" button has class ".red" like so:

<tr>
    <td><input type="text" placeholder="nickname" value="Asus Nexus 7" name="nickname" onchange="window._handler[32].apply(null, arguments);" onblur="window._handler[33].apply(null, arguments);" onkeypress="window._handler[34].apply(null, arguments);" /></td>
    <td>added 6 months ago</td>
    <td>
<-- this is what the button code changes to once clicking a "Delete" button -->
        <button class="red" onclick="window._handler[39].apply(null, arguments);">Delete</button> 
        <button class="gray" onclick="window._handler[40].apply(null, arguments);">Cancel</button>
    </td>    
</tr>

What I've Tried So Far

I've tried many scripts, some simpler, some more convoluted, but none seem to work. So far, this gives best results. It clicks the buttons (though I can't tell in which order) but it does not delete any entries. This code is limited to 5 entries as when I do the whole list, it goes on for like 5 minutes without results -- at least this way I find out quickly that it's not working.

My selectors are correct because when I do console.logging, all the right stuff is selected, but the clicking still fails. Also to note, my code always leaves one of the buttons in the list open (as in, it successfully clicks the buttons, and the last "Delete" button clicked leaves a "Delete" button and a "Cancel" button in its place once the code is done running).

function deleteAsus() {
    var n;
    $('.crud input[value="Asus Nexus 7"]').each(function(){
        n++;
        if (n =< 5) {
            //console.log(this); //works!
            //console.log($(this).parent().parent().find('.hover-red')); //works!
            //console.log($(this).parent().parent().find('.red')); //works!
            $(this).parent().parent().find('.hover-red').click().delay(3000).parent().parent().find('.red').click();
            //$(this).parent().parent().find('.red').click();
        } else {
            return;
        }
    });
}
deleteAsus();

As you see in the code above, my latest attempt is in putting a delay between clicking "first Delete" button and "second Delete" button, but this seems to do nothing and the delay doesn't even seem to work at all.

I know it's difficult to help with this as it's not really possible to recreate the "Pushbullet device screen" code unless you have your own Pushbullet account, so if there is any way I can help you help me, please let me know (And show me the money!)


Solution

  • I've finally figured out a way to write this code to

    1. Click first "Delete" button
    2. Wait for 1.5 seconds for DOM to change --> the first button's class and position/CSS changes
    3. Then to press the new Red "Delete" button
    4. Finally, it waits another 1.5 seconds for good measure and restarts the process
    5. This continues until all the devices with the duplicate name are deleted

    It's deleting the duplicate devices, 1 per 3 seconds, as we speak. The total was at 1420 when I started and as I type this I am down to about 1300.

    The code:

    var assNex7 = $('.crud input[value="Asus Nexus 7"]');
    var n = 0;
    function clickRed() {
        n++;
        setTimeout(function() {
            $('.red').click();
            setTimeout(function() {
                deleteDevice();
            }, 1500);
        }, 1500);
    }
    function clickDelete() {
        $('.crud input[value="Asus Nexus 7"]').eq(0).parent().parent().find('.hover-red').click();
        clickRed();
    }
    function deleteDevice() {
        if (n < assNex7.length) clickDelete();
    }
    deleteDevice();