title: Select all images on Pinterest for moving to another board
body: <h2>UPDATE: (<em>2015-10-16</em>) [SOLVED!] -- <em>Fixed with trigger() and by limiting to 50 pins with slice().</em></h2>
  
  <p>Many thanks to <a href="https://stackoverflow.com/users/830936/abhas-tandon">Abhas Tandon</a> who offered that by using </p>
  
  <pre><code>$(this).trigger('click');
  </code></pre>
  
  <p>instead of</p>
  
  <pre><code>$(this).addClass('selected');
  </code></pre>
  
  <p>it will correctly select the images. I tested with a board consisting of 21 images and it worked perfect! However when trying to move 300+ pins, it failed with this error:</p>
  
  <pre><code>"You can only move 50 Pins at a time." 
  </code></pre>
  
  <p>I then solved that issue by using JavaScript's <strong>slice()</strong> function to grab only the first 50 images. Tested and it works correctly now. So my limitions are currently that I can only select and move 50 pins at a time, but that's much better than having to pick them one by one by hand!</p>
  
  <p><br /></p>
  
  <h2>FINAL WORKING CODE:</h2>
  
  <pre class="lang-js prettyprint-override"><code>function checkAll() {
      console.log("Checkboxes count: " + checkBoxes.length);
  
      $.each(checkBoxes, function(i, v) {
        console.log("Checkbox #: " + i)// + " = " + v);
        $(this).trigger('click');
  
      });
  }
  
  var checkBoxes = $("div &gt; div &gt; div.bulkEditPinWrapper &gt; button");
  
  var checkBoxes = checkBoxes.slice(1, 51);
  
  checkAll();
  </code></pre>
  
  <p><br /></p>
  
  <hr>
  
  <p><br /></p>
  
  <h2>DESCRIPTION OF ISSUE:</h2>
  
  <p>I'm having some trouble with a Pinterest interface (?) script (?) I'm developing. I'm a programmer, mostly self-taught, and I think I'm missing some key component of understanding about AJAX possibly? This is the second time I've tried to write a jQuery script to interface with Pinterest. The first one was an attempt to defeat the infinite scroll feature (AKA "load more" button) in order to have all images displayed on one page, from which I could scrape image links and then download them with a browser plugin to backup my Pinterest boards to my computer. My code all worked except it didn't actually end up downloading any images.</p>
  
  <p>Disappointed, I put that on hold to focus on other things. Eventually I revisited my code and did some digging and it should have worked. My research indicated that the CRITICAL FLAW that may have been preventing my program from doing what I wanted was something to with "Pinterest uses AJAX". While I'm aware of the term "Asynchronous JavaScript with XML" and "XMLHttpRequest", I'm not an expert by any stretch at implementing AJAX.</p>
  
  <p>With my latest code, I wrote a -- you would think it would be -- quick little jQuery script to select all images so that I can move them, delete, copy, etc ... The problem is that though checking all the boxes works (You must be in a board and click on "Move" for instance), when I click the "Move" button a second time which should pop-up a modal letting choose which board to move to, all I get is</p>
  
  <pre><code>Oops!
  Select the Pins you want to move.
  </code></pre>
  
  <p><BR />   </p>
  
  <h2><strong>USING:</strong></h2>
  
  <ul>
  <li>Chrome 45.0.2454.101</li>
  <li>Windows 8.1 64-bit</li>
  </ul>
  
  <p><BR />   </p>
  
  <h2>HOW TO REPRODUCE ISSUES:</h2>
  
  <ol>
  <li>Login to your Pinterest account on a laptop or desktop computer.</li>
  <li>Choose one of your boards or build a test board from scratch (so you don't loose any of your current pins).</li>
  <li>Click "Move" on the top right. This will make transparent checkboxes appear in the upper right of each image. Note: Pinterest shows their unchecked checkboxes WITH a check mark already in them. The way you know a box has been checked is that it retains the checkmark and the box background turns solid (not transparent anymore) red.</li>
  <li>In your browser launch your developer tools console (Firefox/Chrome: F12).</li>
  <li>Add the below script to your JavaScript console in your browser.</li>
  <li>Run the script. If it "worked" you should see all of the checkboxes are now red.</li>
  <li>Click the "More" button again. Now you will get the "Select the Pins you want to move." message, indicating that in actuality, the select all did not work.</li>
  </ol>
  
  <p>NOTE: I'm not concerned about pagination at this point, but if anyone wants to address that I'm open to solutions on that issue as well.</p>
  
  <p><BR />   </p>
  
  <h2>SCRIPT TO SELECT ALL IMAGES:</h2>
  
  <pre class="lang-js prettyprint-override"><code>/* 
     @Repo:     EHW-JavaScript-Pinterest-SelectAllImages.
  
     @Creator:  Eric Hepperle (CodeSlayer2010/CodeWizard13)
     @Date:     10/15/15
     @Version:  1.0
  
     @Purpose:  Click "Move" in Pinterest board to move pins.
                Once checkboxes are visible, run this in an
                F12 browser console to automatically check all
                visible image pins. You will have success when
                the color of all checkboxes turns red. Then
                click "Move" again to finish.
  
      @Notes:
          2015.10.15
              - Created script.
              - Checks all checkboxes, but does not allow moving.
  
  */
  
  function checkAll() {
      console.log("Checkboxes count: " + checkBoxes.length);
  
      $.each(checkBoxes, function(i, v) {
        console.log("Checkbox #: " + i)// + " = " + v);
        $(this).addClass('selected');
  
      });
  }
  
  //$(document).ready(function() {
      alert('hi');
  
      var checkBoxes = $("div &gt; div &gt; div.bulkEditPinWrapper &gt; button");
  
      checkAll();
  //});
  </code></pre>
  
  <p><BR />   </p>
  
  <h2>WHAT I TRIED TO FIX IT ALREADY:</h2>
  
  <ol>
  <li><p>Googled for solution. I found the following articles. That last one seemed like it might be what I needed, but it did not seem to be focused enough on my issue.</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/14582724/jquery-to-add-a-class-to-image-links-without-messing-up-when-the-link-passes-var">StackOverflow | jQuery to add a class to image links without messing up when the link passes variables</a></li>
  <li><a href="https://www.quora.com/Pinterest-User-Feedback/Can-you-provide-options-to-select-multiple-pins-and-pin-them-into-a-board-or-to-pin-an-image-into-multiple-boards-at-a-time" rel="nofollow noreferrer">Quora | Pinterest User Feedback: Can you provide options to "select multiple pins and pin them into a board" or "to pin an image into multiple boards at a time"?</a></li>
  <li><a href="https://stackoverflow.com/questions/13796859/identify-extract-the-title-description-of-an-image-data-scraping-pinterest">StackOverflow | Identify &amp; Extract the title/description of an Image (Data Scraping Pinterest)</a></li>
  <li><a href="https://stackoverflow.com/questions/18312479/get-all-images-from-a-board-from-a-pinterest-web-address">StackOverflow | Get all images from a board from a Pinterest web address</a></li>
  </ul></li>
  <li><p>Originally tried setting each checkbox's "checked" property to "true", but it did not end up checking the boxes (why??). But,then I observed in a browser console that when I clicked to select an image the "selected" class was applied to that image. So, I used addClass() to apply that class to all checkboxes in my code and I was able to get all the checkboxes to select properly then ... or so it seemed.</p></li>
  <li><p>I tried the code with a call to $(document).ready, but it gave me the error</p>
  
  <pre><code>"Uncaught ReferenceError: checkBoxes is not defined(…)"
  </code></pre></li>
  </ol>
  
  <p><BR />   </p>
  
  <p>It took me forever to format this ... thanks in advance for your help. I'm happy to clarify if anything was unclear. Also, please let me know if this post belongs in a different forum. Thanks.</p>