Reddit Inline Comments Viewer

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

2015-12-14 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

  1. // ==UserScript==
  2. // @name Reddit Inline Comments Viewer
  3. // @namespace http://reddit.com
  4. // @version 0.8
  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. $('<button style="position: fixed; top: 95%; left: 85%;">Next Post</button>').insertAfter(post.find('ul>li:nth-child(6)'));
  16. post.find('button').click(function() {
  17. $('.site-viewer-' + ++i).get(0).scrollIntoView();
  18. post.find('button').remove();
  19. }.bind(this));
  20. }.bind(this);
  21. $('<li class="site-viewer-' + i + '"><a href="#">view thread</a><li>').insertAfter(post.find('ul>li:nth-child(5)'));
  22. $('.site-viewer-' + i).click(function(e) {
  23. e.preventDefault();
  24. e.stopPropagation();
  25. if ($('.site-viewer-' + i + '>a').text() === 'close thread') {
  26. $('.site-viewer-' + i + '>a').text('view thread');
  27. post.find('div.commentarea').hide();
  28. post.find('button').detach();
  29. } else {
  30. if (post.find('div.commentarea').length > 0) {
  31. insertButton();
  32. $('.site-viewer-' + i + '>a').text('close thread');
  33. post.find('div.commentarea').show();
  34. } else {
  35. $('.site-viewer-' + i + '>a').text('loading...');
  36. $('<iframe />').attr({
  37. 'src': $(this).attr('href'),
  38. 'frameborder': '0',
  39. 'width': window.innerWidth / 1.2,
  40. 'height': window.innerHeight
  41. }).appendTo(post);
  42. var iframe = post.find('iframe');
  43. iframe.hide();
  44. iframe.on('load', function() {
  45. insertButton();
  46. $('.site-viewer-' + i + '>a').text('close thread');
  47. iframe.contents().find('div.commentarea').appendTo(post);
  48. iframe.remove();
  49. }.bind(this));
  50. }
  51. }
  52. }.bind(this));
  53. });
  54. // ==UserScript==
  55. // @name Reddit Inline Comments Viewer
  56. // @namespace http://reddit.com
  57. // @version 0.7
  58. // @description View inline Reddit threads from the front page or any subreddit.
  59. // @author jaszhix
  60. // @match http*://www.reddit.com/*
  61. // @exclude http*://www.reddit.com/*/*/comments/*
  62. // @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
  63. // @run-at document-end
  64. // ==/UserScript==
  65. $('div>div>ul>li:nth-child(1)>a').each(function(i) {
  66. var post = $(this).parents().eq(3);
  67. var insertButton = function(){
  68. $('<button style="position: fixed; top: 95%; left: 85%;">Next Post</button>').insertAfter(post.find('ul>li:nth-child(6)'));
  69. post.find('button').click(function() {
  70. $('.site-viewer-' + ++i).get(0).scrollIntoView();
  71. post.find('button').remove();
  72. }.bind(this));
  73. }.bind(this);
  74. $('<li class="site-viewer-' + i + '"><a href="#">view thread</a><li>').insertAfter(post.find('ul>li:nth-child(5)'));
  75. $('.site-viewer-' + i).click(function(e) {
  76. e.preventDefault();
  77. e.stopPropagation();
  78. if ($('.site-viewer-' + i + '>a').text() === 'close thread') {
  79. $('.site-viewer-' + i + '>a').text('view thread');
  80. post.find('div.commentarea').hide();
  81. post.find('button').detach();
  82. } else {
  83. if (post.find('div.commentarea').length > 0) {
  84. insertButton();
  85. $('.site-viewer-' + i + '>a').text('close thread');
  86. post.find('div.commentarea').show();
  87. } else {
  88. $('.site-viewer-' + i + '>a').text('loading...');
  89. $('<iframe />').attr({
  90. 'src': $(this).attr('href'),
  91. 'frameborder': '0',
  92. 'width': window.innerWidth / 1.2,
  93. 'height': window.innerHeight
  94. }).appendTo(post);
  95. var iframe = post.find('iframe');
  96. iframe.hide();
  97. iframe.on('load', function() {
  98. insertButton();
  99. $('.site-viewer-' + i + '>a').text('close thread');
  100. iframe.contents().find('div.commentarea').appendTo(post);
  101. iframe.remove();
  102. }.bind(this));
  103. }
  104. }
  105. }.bind(this));
  106. });