Reddit Inline Comments Viewer

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

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

  1. // ==UserScript==
  2. // @name Reddit Inline Comments Viewer
  3. // @namespace http://reddit.com
  4. // @version 0.6
  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. $('<li class="site-viewer-' + i + '"><a href="#">view thread</a><li>').insertAfter($(this).parents().eq(3).find('ul>li:nth-child(5)'));
  14. $('.site-viewer-' + i).click(function(e) {
  15. e.preventDefault();
  16. e.stopPropagation();
  17. if ($('.site-viewer-' + i + '>a').text() === 'close thread') {
  18. $('.site-viewer-' + i + '>a').text('view thread');
  19. $(this).parents().eq(3).find('div.commentarea').hide();
  20. $(this).parents().eq(3).find('button').detach();
  21. } else {
  22. $('<button style="position: fixed; top: 95%; left: 85%;">Next Post</button>').insertAfter($(this).parents().eq(3).find('ul>li:nth-child(6)'));
  23. $(this).parents().eq(3).find('button').click(function(){
  24. $('.site-viewer-' + ++i).get(0).scrollIntoView();
  25. $(this).parents().eq(3).find('button').remove();
  26. }.bind(this));
  27. if ($(this).parents().eq(3).find('div.commentarea').length > 0) {
  28. $('.site-viewer-' + i + '>a').text('close thread');
  29. $(this).parents().eq(3).find('div.commentarea').show();
  30. } else {
  31. $('.site-viewer-' + i + '>a').text('loading...');
  32. $('<iframe />').attr({
  33. 'src': $(this).attr('href'),
  34. 'frameborder': '0',
  35. 'width': window.innerWidth / 1.2,
  36. 'height': window.innerHeight
  37. }).appendTo($(this).parents().eq(3));
  38. $(this).parents().eq(3).find('iframe').hide();
  39. $(this).parents().eq(3).find('iframe').on('load', function() {
  40. $('.site-viewer-' + i + '>a').text('close thread');
  41. $(this).parents().eq(3).find('iframe').contents().find('div.commentarea').appendTo($(this).parents().eq(3));
  42. $(this).parents().eq(3).find('iframe').remove();
  43. }.bind(this));
  44. }
  45. }
  46. }.bind(this));
  47. });