Reddit Inline Comments Viewer

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

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, Greasemonkey alebo Violentmonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey alebo Userscripts.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie správcu používateľských skriptov.

(Už mám správcu používateľských skriptov, nechajte ma ho nainštalovať!)

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

(Už mám správcu používateľských štýlov, nechajte ma ho nainštalovať!)

// ==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));
  });
});