Reddit link expander

Changes continue this thread links so that they load inline

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

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

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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 link expander
// @description    Changes continue this thread links so that they load inline
// @author         James Skinner <[email protected]> (http://github.com/spiralx)
// @namespace      http://spiralx.org/
// @match          *://*.reddit.com/r/*/comments/*
// @version        0.1.0
// @grant          GM_getResourceURL
// @run-at         document-start
// @resource       spinner http://cdn.www.easportsworld.com/static/20130920.102812/images/prod/clubs/sw/common/spinner.gif
// @resource       expand http://www.iba-berlin.com/design/iba_berlin/javascript/partner_ajax/images/icon_expand.gif
// @require        https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.js
// @require        https://greasyfork.org/scripts/7602-mutation-observer/code/mutation-observer.js
// ==/UserScript==

var spinnerUrl = GM_getResourceURL('spinner'),
    expandUrl = GM_getResourceURL('expand');


var observer = new MutationSummary({
  callback: function(summaries) {
    //console.info('Added %d spans', summaries[0].added.length);
    
    summaries[0].added.forEach(function(elem) {
      var $span = jQuery(elem),
        $a = $span.children('a'),
        href = $a.prop('href');
        
      //console.log(href);

      jQuery('<img src="' + expandUrl + '">')
        .css({
          display: 'inline-block',
          position: 'relative',
          top: '1px',
          marginRight: '4px',
          visibility: 'visible'
        })
        .prependTo($a);

      $a
        .css('font-size', '1.1em')
        .one('click', function() {
          $span
            .removeClass('deepthread')
            .html('<img src="' + spinnerUrl + '">');
          
          jQuery.get(href, function(data) {
            var $page = jQuery(data),
                $child = jQuery('.nestedlisting > .comment > .child', $page);
            
            $span
              .parentsUntil('.comment')
              .last()
              .replaceWith($child);
          });
          
          return false;
        });
    });
  },
  rootNode: document.body,
  queries: [
    { element: 'span.deepthread' }
  ]
});