Reddit Inline Comments Viewer

View inline Reddit threads from the front page or any subreddit.

As of 2015-12-14. See the latest version.

  1. // ==UserScript==
  2. // @name Reddit Inline Comments Viewer
  3. // @namespace http://reddit.com
  4. // @version 0.7
  5. // @description View inline Reddit threads from the front page or any subreddit.
  6. // @author jaszhix
  7. // @match http*://www.reddit.com/*
  8. // @exclude http*://www.reddit.com/*/*/comments/*
  9. // @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
  10. // @run-at document-end
  11. // ==/UserScript==
  12. $('div>div>ul>li:nth-child(1)>a').each(function(i) {
  13. var post = $(this).parents().eq(3);
  14. $('<li class="site-viewer-' + i + '"><a href="#">view thread</a><li>').insertAfter(post.find('ul>li:nth-child(5)'));
  15. $('.site-viewer-' + i).click(function(e) {
  16. e.preventDefault();
  17. e.stopPropagation();
  18. if ($('.site-viewer-' + i + '>a').text() === 'close thread') {
  19. $('.site-viewer-' + i + '>a').text('view thread');
  20. post.find('div.commentarea').hide();
  21. post.find('button').detach();
  22. } else {
  23. if (post.find('div.commentarea').length > 0) {
  24. $('.site-viewer-' + i + '>a').text('close thread');
  25. post.find('div.commentarea').show();
  26. } else {
  27. $('.site-viewer-' + i + '>a').text('loading...');
  28. $('<iframe />').attr({
  29. 'src': $(this).attr('href'),
  30. 'frameborder': '0',
  31. 'width': window.innerWidth / 1.2,
  32. 'height': window.innerHeight
  33. }).appendTo(post);
  34. var iframe = post.find('iframe');
  35. iframe.hide();
  36. iframe.on('load', function() {
  37. $('<button style="position: fixed; top: 95%; left: 85%;">Next Post</button>').insertAfter(post.find('ul>li:nth-child(6)'));
  38. post.find('button').click(function() {
  39. $('.site-viewer-' + ++i).get(0).scrollIntoView();
  40. post.find('button').remove();
  41. }.bind(this));
  42. $('.site-viewer-' + i + '>a').text('close thread');
  43. iframe.contents().find('div.commentarea').appendTo(post);
  44. iframe.remove();
  45. }.bind(this));
  46. }
  47. }
  48. }.bind(this));
  49. });