Reddit Inline Comments Viewer

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

目前為 2015-12-11 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Reddit Inline Comments Viewer
  3. // @namespace http://reddit.com
  4. // @version 0.4
  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. $('<li class="site-viewer-' + i + '"><a href="#">view thread</a><li>').insertAfter($(this).parents().eq(3).find('ul>li:nth-child(5)'));
  14. $('.site-viewer-' + i).click(function(e) {
  15. e.preventDefault();
  16. e.stopPropagation();
  17. if ($('.site-viewer-' + i + '>a').text() === 'close thread') {
  18. $('.site-viewer-' + i + '>a').text('view thread');
  19. $(this).parents().eq(3).find('div.commentarea').hide();
  20. } else {
  21. if ($(this).parents().eq(3).find('div.commentarea').length > 0) {
  22. $('.site-viewer-' + i + '>a').text('close thread');
  23. $(this).parents().eq(3).find('div.commentarea').show();
  24. } else {
  25. $('.site-viewer-' + i + '>a').text('loading...');
  26. $('<iframe />').attr({
  27. 'src': $(this).attr('href'),
  28. 'frameborder': '0',
  29. 'width': window.innerWidth / 1.2,
  30. 'height': window.innerHeight
  31. }).appendTo($(this).parents().eq(3));
  32. $(this).parents().eq(3).find('iframe').hide();
  33. $(this).parents().eq(3).find('iframe').on('load', function() {
  34. $('.site-viewer-' + i + '>a').text('close thread');
  35. $(this).parents().eq(3).find('iframe').contents().find('div.commentarea').appendTo($(this).parents().eq(3));
  36. }.bind(this));
  37. }
  38. }
  39. }.bind(this));
  40. });