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