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.9
  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. var insertButton = function(){
  15. var nextPost = $('.site-viewer-' + ++i).get(0);
  16. if (nextPost) {
  17. $('<button style="position: fixed; top: 95%; left: 85%;">Next Post</button>').insertAfter(post.find('ul>li:nth-child(6)'));
  18. post.find('button').click(function() {
  19. nextPost.scrollIntoView();
  20. post.find('button').remove();
  21. }.bind(this));
  22. }
  23. }.bind(this);
  24. $('<li class="site-viewer-' + i + '"><a href="#">view thread</a><li>').insertAfter(post.find('ul>li:nth-child(5)'));
  25. $('.site-viewer-' + i).click(function(e) {
  26. e.preventDefault();
  27. e.stopPropagation();
  28. if ($('.site-viewer-' + i + '>a').text() === 'close thread') {
  29. $('.site-viewer-' + i + '>a').text('view thread');
  30. post.find('div.commentarea').hide();
  31. post.find('button').detach();
  32. } else {
  33. if (post.find('div.commentarea').length > 0) {
  34. insertButton();
  35. $('.site-viewer-' + i + '>a').text('close thread');
  36. post.find('div.commentarea').show();
  37. } else {
  38. $('.site-viewer-' + i + '>a').text('loading...');
  39. $('<iframe />').attr({
  40. 'src': $(this).attr('href'),
  41. 'frameborder': '0',
  42. 'width': window.innerWidth / 1.2,
  43. 'height': window.innerHeight
  44. }).appendTo(post);
  45. var iframe = post.find('iframe');
  46. iframe.hide();
  47. iframe.on('load', function() {
  48. insertButton();
  49. $('.site-viewer-' + i + '>a').text('close thread');
  50. iframe.contents().find('div.commentarea').appendTo(post);
  51. iframe.remove();
  52. }.bind(this));
  53. }
  54. }
  55. }.bind(this));
  56. });