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.10
  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 nextIterator = ++i;
  15. var insertButton = function(){
  16. var nextPost = $('.site-viewer-' + nextIterator).get(0);
  17. if (nextPost) {
  18. $('<button style="position: fixed; top: 95%; left: 85%;">Next Post</button>').insertAfter(post.find('ul>li:nth-child(6)'));
  19. post.find('button').click(function(e) {
  20. e.preventDefault();
  21. e.stopPropagation();
  22. nextPost.scrollIntoView();
  23. post.find('button').remove();
  24. }.bind(this));
  25. }
  26. }.bind(this);
  27. $('<li class="site-viewer-' + i + '"><a href="#">view thread</a><li>').insertAfter(post.find('ul>li:nth-child(5)'));
  28. $('.site-viewer-' + i).click(function(e) {
  29. e.preventDefault();
  30. e.stopPropagation();
  31. if ($('.site-viewer-' + i + '>a').text() === 'close thread') {
  32. $('.site-viewer-' + i + '>a').text('view thread');
  33. post.find('div.commentarea').hide();
  34. post.find('button').detach();
  35. } else {
  36. if (post.find('div.commentarea').length > 0) {
  37. $('.site-viewer-' + i + '>a').text('close thread');
  38. insertButton();
  39. post.find('div.commentarea').show();
  40. } else {
  41. $('.site-viewer-' + i + '>a').text('loading...');
  42. $('<iframe />').attr({
  43. 'src': $(this).attr('href'),
  44. 'frameborder': '0',
  45. 'width': window.innerWidth / 1.2,
  46. 'height': window.innerHeight
  47. }).appendTo(post);
  48. var iframe = post.find('iframe');
  49. iframe.hide();
  50. iframe.on('load', function() {
  51. $('.site-viewer-' + i + '>a').text('close thread');
  52. insertButton();
  53. iframe.contents().find('div.commentarea').appendTo(post);
  54. iframe.remove();
  55. }.bind(this));
  56. }
  57. }
  58. }.bind(this));
  59. });