Reddit Inline Comments Viewer

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

2015-12-14 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Reddit Inline Comments Viewer
// @namespace    http://reddit.com
// @version      0.13
// @description  View inline Reddit threads from the front page or any subreddit.
// @author       jaszhix
// @match        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($){
  $('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>');
    toggleButton.insertAfter(post.find('ul>li:nth-child(5)'));
    var insertButton = function(){
      $('<button class="inline-next-post" style="position: fixed; top: 95%; left: 85%;">Next Post</button>').insertAfter(post.find('ul>li:nth-child(6)'));
      post.find('.inline-next-post').click(function() {
        var nextI = ++i;
        $('.site-viewer-' + nextI).get(0).scrollIntoView();
        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();
            });
          });
        }
      }
    }.bind(this));
  });
});