Guest User

Untitled

a guest
Apr 3rd, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <p>
  2.   <a id="bookmarklet" href="javascript:(function(){
  3.      
  4. /*
  5.    This program is free software: you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation, either version 3 of the License, or
  8.    (at your option) any later version.*/
  9.  
  10. scriptName = 'Reddit Restore (1.1) by /u/SuperConductiveRabbi';
  11.    
  12. apiJSON = null;
  13. dupeJSON = null;
  14. ready = false;
  15. dupePosts = [];
  16. dupeHashSet = {};
  17. apiPosts = [];
  18. foundDeletion = false;
  19. deletionCount = 0;
  20. error = false;
  21.  
  22. apiURL='https://www.reddit.com/api/info.json?url='+escape($('.link .entry .title a:first').attr('href'));
  23. dupeURL=$('.choice:contains(other discussions)').attr('href') + '.json';
  24.  
  25. var printQuitMessage = function() {
  26.     console.log('\n\n**** Script ending ****');
  27. };
  28.  
  29. var nextStep = function() {
  30.    if (apiJSON && dupeJSON) {
  31.         ready = true;
  32.         /* Originating duplicate */
  33.         thePost = dupeJSON[0].data.children[0].data;
  34.         if (thePost.author != '[deleted]') {
  35.             dupePosts.push(thePost);
  36.             dupeHashSet[thePost.id] = 1;
  37.         }
  38.  
  39.         for (var i=0; i<dupeJSON[1].data.children.length; ++i) {
  40.             thePost = dupeJSON[1].data.children[i].data;
  41.             if (thePost.author != '[deleted]') {
  42.                 dupePosts.push(thePost);
  43.                 if (dupeHashSet[thePost.id]) {
  44.                     dupeHashSet[thePost.id] += 1;
  45.                 } else {
  46.                     dupeHashSet[thePost.id] = 1;
  47.                 }
  48.             }
  49.         }
  50.  
  51.         for (var i=0; i<apiJSON.data.children.length; ++i) {
  52.             thePost = apiJSON.data.children[i].data;
  53.             if (thePost.author != '[deleted]') {
  54.                 apiPosts.push(thePost);
  55.                 if (!dupeHashSet[thePost.id]) {
  56.                     foundDeletion = true;
  57.                     deletionCount++;
  58.                     var date = new Date(thePost.created_utc * 1000);
  59.                     console.log('Deletion detected!\n\tSubreddit: ' + thePost.subreddit + '\n\tDate: ' + date + '\n\tPermalink: \n\thttps://np.reddit.com' + thePost.permalink);
  60.                 }
  61.             }
  62.         }
  63.  
  64.         if (foundDeletion) {
  65.             alert(deletionCount + ' deletions found! Check the JavaScript console for information (F12)\n\n' + scriptName);
  66.         } else {
  67.             message = 'No deletions found.\n\nRemember to run this from the thread you wish to check!';
  68.             alert(message);
  69.             console.log(message);
  70.         }
  71.         printQuitMessage();
  72.  
  73.     }
  74.  
  75. };
  76.  
  77.  
  78. console.log('\n\n**** Script running ****');
  79. console.log(scriptName);
  80. console.log('************************');
  81.  
  82. /* Goes from other discussions to the first off-subreddit result, then gets THAT other discussions tab
  83. * This allows it to check to see if the origniating post was removed*/
  84. if (dupeURL != 'undefined.json' ) {
  85.     $.ajax({
  86.         dataType: 'json',
  87.         url: dupeURL,
  88.     }).then(function(data) {
  89.         if(data.length > 1 && data[1].data.children.length >= 1) {
  90.             re = /\/comments\//;
  91.             newURL = 'https://www.reddit.com' + data[1].data.children[0].data.permalink.replace(re, '/duplicates/') + '.json';    
  92.             $.ajax({
  93.                 dataType: 'json',
  94.                 url: newURL,
  95.             }).then(function(data) {
  96.                 dupeJSON = data;
  97.                 nextStep();
  98.             })
  99.             .fail(function() { printQuitMessage(); });
  100.         } else {
  101.             message = 'Sorry, but this script only works if a post has at least one result in the Other Discussions tab.';
  102.             console.log(message);
  103.             alert(message);
  104.             printQuitMessage();
  105.         }
  106.     })
  107.     .fail(function() { printQuitMessage(); });
  108. } else {
  109.     message = 'Sorry, but this script only works if a post has at least one result in the Other Discussions tab.';
  110.     console.log(message);
  111.     alert(message);
  112.     printQuitMessage();
  113. }
  114.  
  115. $.ajax({
  116.    dataType: 'json',
  117.     url: apiURL,
  118. }).then(function(data) {
  119.    apiJSON = data;
  120.    nextStep();
  121. });
  122.  
  123.  
  124.  
  125.  
  126.      
  127.       }());">Reddit Restore</a>
  128. </p>
  129.  
  130.  
  131.  
  132. <p>
  133. Reddit Restore checks for deletions on Reddit. Drag the above link into your bookmarks toolbar to install it.</p><p>v1.1 <a href="https://www.reddit.com/u/SuperConductiveRabbi">/u/SuperConductiveRabbi</a>
  134. <ul>
  135.    
  136. <li>Visit the comments section of a Reddit post you wish to check</li>
  137.  
  138.   <li>Click "Reddit Restore" in your bookmarks toolbar</li>
  139.  
  140.   <li>Wait a few seconds for a pop-up and/or check the Javascript console (F12) then "Console"</li>
  141.  
  142. </ul>
  143.  
  144.  
  145. <p>This script currently requires that the post has at least one "other discussion" listed. If you see "Other discussions (1)" or greater, it should work!</p>
  146. <p>
  147.   Stay tuned to <a href="https://www.reddit.com/r/undelete">/r/undelete</a> for new versions or bug fixes.
  148. </p>
  149. <p>Thanks to <a href="https://www.reddit.com/u/go1dfish">/u/go1dfish</a> for the JS help and for his tireless work to make censorship and removals more transparent on Reddit</p>
  150.  
  151. <p>Code licensed under the GPL</p>
  152. </ul>
  153.  
  154.  
  155. </p>
Add Comment
Please, Sign In to add comment