_ap_ufes{"success":true,"siteUrl":"www.jucktion.com/tech","urls":{"Home":"https://www.jucktion.com/tech","Category":"https://www.jucktion.com/tech/c/mobile/android/","Archive":"https://www.jucktion.com/tech/2018/12/","Post":"https://www.jucktion.com/tech/windows-network-traffic-analysis-single-app/","Page":"https://www.jucktion.com/tech/about/","Attachment":"https://www.jucktion.com/tech/windows-network-traffic-analysis-single-app/capture-traffic-specific-application/","Nav_menu_item":"https://www.jucktion.com/tech/3985/"}}_ap_ufee Remove random number of pins in Pinterest boards (JS Code) - Tech Junction

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

By | 18th March, 2017 | 0 Comments

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); });}

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.

Tags: ,

Category: JavaScript