Greasy Fork is available in English.

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.13
  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. $(document).ready(function($){
  13. $('div>div>ul>li:nth-child(1)>a').each(function(i) {
  14. var post = $(this).parents().eq(3);
  15. var toggleButton = $('<li class="site-viewer-' + i + '"><a href="#">view thread</a><li>');
  16. toggleButton.insertAfter(post.find('ul>li:nth-child(5)'));
  17. var insertButton = function(){
  18. $('<button class="inline-next-post" style="position: fixed; top: 95%; left: 85%;">Next Post</button>').insertAfter(post.find('ul>li:nth-child(6)'));
  19. post.find('.inline-next-post').click(function() {
  20. var nextI = ++i;
  21. $('.site-viewer-' + nextI).get(0).scrollIntoView();
  22. post.find('button').hide();
  23. });
  24. };
  25. var toggleButtonLink = $('.site-viewer-' + i + '>a');
  26. var closeThread = function(){
  27. toggleButtonLink.text('view thread');
  28. post.find('div.commentarea').hide();
  29. post.find('button').hide();
  30. };
  31. var viewThread = function(){
  32. toggleButtonLink.text('close thread');
  33. post.find('button').show();
  34. post.find('div.commentarea').show();
  35. };
  36. $('.site-viewer-' + i).click(function(e) {
  37. e.preventDefault();
  38. e.stopPropagation();
  39. if (toggleButtonLink.text() === 'close thread') {
  40. closeThread();
  41. } else {
  42. if (post.find('div.commentarea').length > 0) {
  43. viewThread();
  44. } else {
  45. toggleButtonLink.text('loading...');
  46. $('<iframe />').attr({
  47. 'src': $(this).attr('href'),
  48. 'frameborder': '0',
  49. 'width': window.innerWidth / 1.2,
  50. 'height': window.innerHeight
  51. }).appendTo(post);
  52. var iframe = post.find('iframe');
  53. iframe.hide();
  54. iframe.on('load', function() {
  55. toggleButtonLink.text('close thread');
  56. if ($('.inline-next-post').length > 0) {
  57. $('.inline-next-post').hide();
  58. }
  59. insertButton();
  60. iframe.contents().find('div.commentarea').appendTo(post);
  61. iframe.remove();
  62. $('<li class="inline-close-thread"><a href="#">close thread</a><li>').appendTo(post.find('div.commentarea'));
  63. $('.inline-close-thread').click(function(e){
  64. e.preventDefault();
  65. e.stopPropagation();
  66. closeThread();
  67. });
  68. });
  69. }
  70. }
  71. }.bind(this));
  72. });
  73. });