Remove random number of pins in Pinterest boards (JS Code)

This basically removes a random number of pins from a board. This is just a play on the javascript code and should work on other user boards checked Firefox and Chrome browser.

This is just a simple code I created to use with a different set of test tool I used. This basically removes a random number of pins from a board. This is just a play on the javascript code and should work on other user boards and I have checked it with Firefox and Chrome browser. Although I can’t claim 100% compatibility.

Pinterest before pin removal

I have created it with an random element added to remove from 1 to 5. But you can edit the r variable to remove as many number of pins from a page as you would like.

The code is as follows:

var r = Math.floor(Math.random() * (5 - 1) + 1 );
for (var i = 1; i< =r;i++){ var x = document.querySelectorAll(".ui-draggable:first-child"); Array.prototype.forEach.call(x, function(node){ node.parentNode.removeChild(node); });}

Explanation:
The first line basically creates a "r" variable and assigns a random number from 1 to 5. It changes every time you run the code. The second line starts a loop in which the code searches for a pins and them removes first element in each loop. The querySelectorAll acts as an CSS selector for the first object in the sequence.The last part is an array loop that goes back to the parent node of the selector then removes child element of the element. Hence removing the pin for us.

Pinterest after pin removal

This may not be the best optimized code to perform this. I will be happy to hear comments.

Leave a Reply