Greasy Fork is available in English.

Reddit Inline Comments Viewer

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

  1. // ==UserScript==
  2. // @name Reddit Inline Comments Viewer
  3. // @namespace http://reddit.com
  4. // @version 0.16
  5. // @description View inline Reddit threads from the front page or any subreddit.
  6. // @author jaszhix
  7. // @include 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. $(document).ready(function($){
  13. var login = false;
  14. if ($('form.logout>a').length > 0) {
  15. login = true;
  16. }
  17. $('div>div>ul>li:nth-child(1)>a').each(function(i) {
  18. var post = $(this).parents().eq(3);
  19. var toggleButton = $('<li class="site-viewer-' + i + '"><a href="#">view thread</a><li>');
  20. if (login) {
  21. toggleButton.insertAfter(post.find('ul>li:nth-child(5)'));
  22. } else {
  23. toggleButton.insertAfter(post.find('ul>li:nth-child(2)'));
  24. }
  25. var scrollToNextPost = function(){
  26. var nextI = ++i;
  27. $('.site-viewer-' + nextI).get(0).scrollIntoView();
  28. };
  29. var insertButton = function(){
  30. if (login) {
  31. $('<button class="inline-next-post" style="position: fixed; top: 95%; left: 85%;">Next Post</button>').insertAfter(post.find('ul>li:nth-child(6)'));
  32. } else {
  33. $('<button class="inline-next-post" style="position: fixed; top: 95%; left: 85%;">Next Post</button>').insertAfter(post.find('ul>li:nth-child(3)'));
  34. }
  35. post.find('.inline-next-post').click(function() {
  36. scrollToNextPost();
  37. post.find('button').hide();
  38. });
  39. };
  40. var toggleButtonLink = $('.site-viewer-' + i + '>a');
  41. var closeThread = function(){
  42. toggleButtonLink.text('view thread');
  43. post.find('div.commentarea').hide();
  44. post.find('button').hide();
  45. };
  46. var viewThread = function(){
  47. toggleButtonLink.text('close thread');
  48. post.find('button').show();
  49. post.find('div.commentarea').show();
  50. };
  51. $('.site-viewer-' + i).click(function(e) {
  52. e.preventDefault();
  53. e.stopPropagation();
  54. if (toggleButtonLink.text() === 'close thread') {
  55. closeThread();
  56. } else {
  57. if (post.find('div.commentarea').length > 0) {
  58. viewThread();
  59. } else {
  60. toggleButtonLink.text('loading...');
  61. $('<iframe />').attr({
  62. 'src': $(this).attr('href'),
  63. 'frameborder': '0',
  64. 'width': window.innerWidth / 1.2,
  65. 'height': window.innerHeight
  66. }).appendTo(post);
  67. var iframe = post.find('iframe');
  68. iframe.hide();
  69. iframe.on('load', function() {
  70. toggleButtonLink.text('close thread');
  71. if ($('.inline-next-post').length > 0) {
  72. $('.inline-next-post').hide();
  73. }
  74. insertButton();
  75. iframe.contents().find('div.commentarea').appendTo(post);
  76. iframe.remove();
  77. $('<li class="inline-close-thread"><a href="#">close thread</a><li>').appendTo(post.find('div.commentarea'));
  78. $('.inline-close-thread').click(function(e){
  79. e.preventDefault();
  80. e.stopPropagation();
  81. closeThread();
  82. $('.site-viewer-' + i).get(0).scrollIntoView();
  83. });
  84. });
  85. }
  86. }
  87. }.bind(this));
  88. });
  89. });