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.11
  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. $('<li class="site-viewer-' + i + '"><a href="#">view thread</a><li>').insertAfter(post.find('ul>li:nth-child(5)'));
  15. var insertButton = function(){
  16. $('<button style="position: fixed; top: 95%; left: 85%;">Next Post</button>').insertAfter(post.find('ul>li:nth-child(6)'));
  17. post.find('button').click(function() {
  18. $('.site-viewer-' + ++i).get(0).scrollIntoView();
  19. post.find('button').remove();
  20. });
  21. };
  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. $('.site-viewer-' + i + '>a').text('close thread');
  32. insertButton();
  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. $('.site-viewer-' + i + '>a').text('close thread');
  46. insertButton();
  47. iframe.contents().find('div.commentarea').appendTo(post);
  48. iframe.remove();
  49. });
  50. }
  51. }
  52. }.bind(this));
  53. });