Advertisement
Guest User

MeFi link lister

a guest
Feb 4th, 2017
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Bookmarklet:
  2.  
  3. javascript:(function(){if(!a)var a={};a.a=document.getElementsByClassName("comments");for(var b=0;b<a.a.length;b++)try{if(a.b=a.a[b].getElementsByClassName("smallcopy")[0],a.b.parentNode.removeChild(a.b),a.a[b].parentNode.removeChild(a.a[b].nextElementSibling.nextElementSibling),a.a[b].parentNode.removeChild(a.a[b].nextElementSibling),a.c=a.a[b].getElementsByTagName("a"),a.e=[],a.c.length>0){for(var c=0;c<a.c.length;c++)a.d=document.createElement("a"),a.d.setAttribute("href",a.c[c].getAttribute("href")),a.d.innerHTML=a.c[c].innerHTML,a.e.push(a.d),a.d=document.createElement("p"),a.d.innerHTML="<small>("+a.c[c].getAttribute("href")+")</small><br />",a.e.push(a.d);a.a[b].innerHTML="";for(var d in a.e)a.a[b].appendChild(a.e[d])}else a.a[b].parentNode.removeChild(a.a[b]),b--}catch(a){console.log(a);continue}a=null})();
  4.  
  5.  
  6.  
  7. Source:
  8.  
  9. javascript:(function(){
  10. if (!allLink) {var allLink = {}};
  11.  
  12. // Get a list of all the comment divs
  13. allLink.comments = document.getElementsByClassName('comments');
  14.  
  15. for (var id = 0; id < allLink.comments.length; id++) {
  16.  
  17.     try {
  18.    
  19.         // Remove the by line
  20.         allLink.byLine = allLink.comments[id].getElementsByClassName('smallcopy')[0];
  21.         allLink.byLine.parentNode.removeChild(allLink.byLine);
  22.        
  23.         // Remove the two <br> tags that follow each comment
  24.         allLink.comments[id].parentNode.removeChild(allLink.comments[id].nextElementSibling.nextElementSibling);
  25.         allLink.comments[id].parentNode.removeChild(allLink.comments[id].nextElementSibling);
  26.        
  27.         // Get any links in the comment
  28.         allLink.links = allLink.comments[id].getElementsByTagName('a');
  29.         allLink.replacement = [];
  30.        
  31.         // If there are links
  32.         if (allLink.links.length > 0) {
  33.            
  34.             // Create duplicate links
  35.             for (var i = 0; i < allLink.links.length; i++) {
  36.                
  37.                 // Link with original text
  38.                 allLink.newElement = document.createElement('a');
  39.                 allLink.newElement.setAttribute('href', allLink.links[i].getAttribute('href'));
  40.                 allLink.newElement.innerHTML = allLink.links[i].innerHTML;
  41.                 allLink.replacement.push(allLink.newElement);
  42.                
  43.                 // Subtitle with link url
  44.                 allLink.newElement = document.createElement('p');
  45.                 allLink.newElement.innerHTML = "<small>(" + allLink.links[i].getAttribute('href') + ")</small><br />"
  46.                 allLink.replacement.push(allLink.newElement);
  47.                
  48.             }
  49.            
  50.             // Clear the comment
  51.             allLink.comments[id].innerHTML = '';
  52.            
  53.             // Add the duplicate links
  54.             for (var j in allLink.replacement) {
  55.                
  56.                 allLink.comments[id].appendChild(allLink.replacement[j]);
  57.                
  58.             }
  59.        
  60.         // If there are no links
  61.         } else {
  62.            
  63.             // Remove the comment entirely
  64.             allLink.comments[id].parentNode.removeChild(allLink.comments[id]);
  65.             id--;
  66.            
  67.         }
  68.        
  69.     } catch (e) {
  70.    
  71.         console.log(e);
  72.         continue;
  73.        
  74.     }
  75.    
  76. };
  77.  
  78. allLink = null;
  79.  
  80. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement