Reddit link expander

Changes continue this thread links so that they load inline

目前為 2015-01-22 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Reddit link expander
  3. // @description Changes continue this thread links so that they load inline
  4. // @author James Skinner <spiralx@gmail.com> (http://github.com/spiralx)
  5. // @namespace http://spiralx.org/
  6. // @match *://*.reddit.com/r/*/comments/*
  7. // @version 0.1.0
  8. // @grant GM_getResourceURL
  9. // @run-at document-start
  10. // @resource spinner http://cdn.www.easportsworld.com/static/20130920.102812/images/prod/clubs/sw/common/spinner.gif
  11. // @resource expand http://www.iba-berlin.com/design/iba_berlin/javascript/partner_ajax/images/icon_expand.gif
  12. // @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.js
  13. // @require https://greasyfork.org/scripts/7602-mutation-observer/code/mutation-observer.js
  14. // ==/UserScript==
  15.  
  16. var spinnerUrl = GM_getResourceURL('spinner'),
  17. expandUrl = GM_getResourceURL('expand');
  18.  
  19.  
  20. var observer = new MutationSummary({
  21. callback: function(summaries) {
  22. //console.info('Added %d spans', summaries[0].added.length);
  23. summaries[0].added.forEach(function(elem) {
  24. var $span = jQuery(elem),
  25. $a = $span.children('a'),
  26. href = $a.prop('href');
  27. //console.log(href);
  28.  
  29. jQuery('<img src="' + expandUrl + '">')
  30. .css({
  31. display: 'inline-block',
  32. position: 'relative',
  33. top: '1px',
  34. marginRight: '4px',
  35. visibility: 'visible'
  36. })
  37. .prependTo($a);
  38.  
  39. $a
  40. .css('font-size', '1.1em')
  41. .one('click', function() {
  42. $span
  43. .removeClass('deepthread')
  44. .html('<img src="' + spinnerUrl + '">');
  45. jQuery.get(href, function(data) {
  46. var $page = jQuery(data),
  47. $child = jQuery('.nestedlisting > .comment > .child', $page);
  48. $span
  49. .parentsUntil('.comment')
  50. .last()
  51. .replaceWith($child);
  52. });
  53. return false;
  54. });
  55. });
  56. },
  57. rootNode: document.body,
  58. queries: [
  59. { element: 'span.deepthread' }
  60. ]
  61. });