Reddit Inline Comments Viewer

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

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Reddit Inline Comments Viewer
// @namespace    http://reddit.com
// @version      0.16
// @description  View inline Reddit threads from the front page or any subreddit.
// @author       jaszhix
// @include      http*://www.reddit.com/*
// @exclude      http*://www.reddit.com/*/*/comments/*
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// @run-at       document-end
// ==/UserScript==
$(document).ready(function($){
  var login = false;
  if ($('form.logout>a').length > 0) {
    login = true;
  }
  $('div>div>ul>li:nth-child(1)>a').each(function(i) {
    var post = $(this).parents().eq(3);
    var toggleButton = $('<li class="site-viewer-' + i + '"><a href="#">view thread</a><li>');
    if (login) {
      toggleButton.insertAfter(post.find('ul>li:nth-child(5)'));
    } else {
      toggleButton.insertAfter(post.find('ul>li:nth-child(2)'));
    }
    var scrollToNextPost = function(){
      var nextI = ++i;
      $('.site-viewer-' + nextI).get(0).scrollIntoView();
    };
    var insertButton = function(){
      if (login) {
        $('<button class="inline-next-post" style="position: fixed; top: 95%; left: 85%;">Next Post</button>').insertAfter(post.find('ul>li:nth-child(6)'));
      } else {
        $('<button class="inline-next-post" style="position: fixed; top: 95%; left: 85%;">Next Post</button>').insertAfter(post.find('ul>li:nth-child(3)'));
      }
      post.find('.inline-next-post').click(function() {
        scrollToNextPost();
        post.find('button').hide();
      });
    };
    var toggleButtonLink = $('.site-viewer-' + i + '>a');
    var closeThread = function(){
      toggleButtonLink.text('view thread');
      post.find('div.commentarea').hide();
      post.find('button').hide();
    };
    var viewThread = function(){
      toggleButtonLink.text('close thread');
      post.find('button').show();
      post.find('div.commentarea').show();
    };
    $('.site-viewer-' + i).click(function(e) {
      e.preventDefault();
      e.stopPropagation();
      if (toggleButtonLink.text() === 'close thread') {
        closeThread();
      } else {
        if (post.find('div.commentarea').length > 0) {
          viewThread();
        } else {
          toggleButtonLink.text('loading...');
          $('<iframe />').attr({
            'src': $(this).attr('href'),
            'frameborder': '0',
            'width': window.innerWidth / 1.2,
            'height': window.innerHeight
          }).appendTo(post);
          var iframe = post.find('iframe');
          iframe.hide();
          iframe.on('load', function() { 
            toggleButtonLink.text('close thread');
            if ($('.inline-next-post').length > 0) {
              $('.inline-next-post').hide();
            }
            insertButton();
            iframe.contents().find('div.commentarea').appendTo(post);
            iframe.remove();
            $('<li class="inline-close-thread"><a href="#">close thread</a><li>').appendTo(post.find('div.commentarea'));
            $('.inline-close-thread').click(function(e){
              e.preventDefault();
              e.stopPropagation();
              closeThread();
              $('.site-viewer-' + i).get(0).scrollIntoView();
            });
          });
        }
      }
    }.bind(this));
  });
});