Reddit Inline Comments Viewer

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

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

  1. // ==UserScript==
  2. // @name Reddit Inline Comments Viewer
  3. // @namespace http://reddit.com
  4. // @version 0.2
  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. var iframe = null;
  13. $('div>div>ul>li:nth-child(1)>a').each(function(i) {
  14. $('<li class="site-viewer-' + i + '"><a href="#">view thread</a><li>').insertAfter($(this).parents().eq(3).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. $(this).parents().eq(3).find('div.commentarea').hide();
  21. } else {
  22. if ($(this).parents().eq(3).find('div.commentarea').length > 0) {
  23. $('.site-viewer-' + i + '>a').text('close thread');
  24. $(this).parents().eq(3).find('div.commentarea').show();
  25. } else {
  26. $('.site-viewer-' + i + '>a').text('loading...');
  27. console.log(e)
  28. $('<iframe />').attr({
  29. 'src': $(this).attr('href'),
  30. 'frameborder': '0',
  31. 'width': window.innerWidth / 1.2,
  32. 'height': window.innerHeight
  33. }).appendTo($(this).parents().eq(3));
  34. $(this).parents().eq(3).find('iframe').hide();
  35. $(this).parents().eq(3).find('iframe').on('load', function() {
  36. $('.site-viewer-' + i + '>a').text('close thread');
  37. $(this).parents().eq(3).find('iframe').contents().find('div.commentarea').appendTo($(this).parents().eq(3));
  38. }.bind(this));
  39. }
  40. }
  41. }.bind(this));
  42. });