TJ

thread navigation helper for TJ club

当前为 2015-07-31 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // (C) Paul Potseluev, Stepan Kiryushkin, helldotcat
  3. // @name TJ
  4. // @namespace TJ
  5. // @include https://tjournal.ru/*
  6. // @version 1
  7. // @grant none
  8. // @description thread navigation helper for TJ club
  9. // @description:ru Расширение упращяет навигацию в обсуждениях в клубе TJ
  10. TJComments = {
  11. d: $(document),
  12. b: $('html, body'),
  13. up_icon: 'https://maxcdn.icons8.com/windows8/PNG/26/Arrows/up_circular-26.png',
  14. down_icon: 'https://maxcdn.icons8.com/windows8/PNG/26/Arrows/down_circular-26.png',
  15.  
  16. init: function() {
  17. this.createAnchors();
  18.  
  19. $('.b-comment__up').click(function(e) {
  20. e.preventDefault();
  21.  
  22. var $this = $(this),
  23. $previous = $this.prev(),
  24. parent_id = $previous.data('parent-id'),
  25. $parent = $('#commentBox' + parent_id),
  26. $children = $this.parents('.b-comment');
  27.  
  28. TJComments.scrollTo($parent);
  29. TJComments.createBack($parent, $children);
  30. });
  31.  
  32. TJComments.d.on('click', '.b-comment__down', function(e) {
  33. e.preventDefault();
  34.  
  35. var $this = $(this),
  36. children_id = $this.data('children-id'),
  37. $children = $('#commentBox' + children_id);
  38.  
  39. $this.remove();
  40. TJComments.scrollTo($children);
  41. });
  42. },
  43.  
  44. scrollTo: function($element) {
  45. TJComments.b.animate({ scrollTop: $element.offset().top }, 500)
  46. $element.effect("highlight", { color: 'rgba(217,239,55,0.1)' }, 1500);
  47. },
  48. createAnchors: function() {
  49. var html = '<a href="#" class="b-comment__up">' +
  50. '&nbsp;&nbsp;<img src="' + this.up_icon + '" width="12px" style="top:3px;position:relative;">' +
  51. '</a>';
  52.  
  53. $('.b-comment__datetime.highlightParent').after(html);
  54. },
  55.  
  56. createBack: function($parent, $children) {
  57. var html = '<a href="#" class="b-comment__down" data-children-id="' + $children.data('id') + '">' +
  58. '&nbsp;&nbsp;<img src="' + this.down_icon + '" width="12px" style="top:3px;position:relative;">' +
  59. '</a>';
  60.  
  61. $parent.find('.b-comment__datetime').after(html);
  62. }
  63. }
  64.  
  65. TJComments.d.ready(function() {
  66. TJComments.init();
  67. });
  68.  
  69. function illuminate($parentId) {
  70. var html = '<div class="b-illuminate" style="margin-left:6px;width:6px;height:6px;background:#ffb833;' +
  71. '-moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;"></div>';
  72. $parentId = '#commentBox' + $parentId;
  73. $($parentId).find('.icon-star').append(html);
  74. $parentId = $($parentId).find('.b-comment__datetime ').attr('data-parent-id');
  75. if ($parentId != 0) {
  76. illuminate($parentId);
  77. }
  78. }
  79.  
  80. function hide() {
  81. $('div.b-illuminate').remove();
  82. }
  83.  
  84. /*
  85. function makeSignature () {
  86. var $id;
  87. var html;
  88. var $commentsSecondLvl = $('.b-comment__up').parents(".b-comment__wrapper");
  89. $($commentsSecondLvl).each( function () {
  90. $id = $(this).find('.icon-star').attr('data-objectid');
  91. html = '<a class="tjhelper" href="#tjhelper' + $id + '">Посмотреть дискуссию</a>';
  92. $(this).find('.b-comment__reply-button').append(html);
  93. });
  94. }
  95. */
  96.  
  97. function makeSignature () {
  98. var $parentId;
  99. var $parentIdValue;
  100. var $name;
  101. var html;
  102. var $commentsSecondLvl = $('.b-comment__up').parents(".b-comment__wrapper");
  103. $($commentsSecondLvl).each( function () {
  104. $parentIdValue = $(this).find('.b-comment__datetime ').attr('data-parent-id');
  105. $parentId = '#commentBox' + $parentIdValue;
  106. $name = $($parentId).find('.b-comment__user').find("span").get(0);
  107. $name = $($name).html();
  108. html = '<a href="#comment'+ $parentIdValue + '"style="margin-left:-12px;">To ' + $name + ' </a>';
  109. $(this).find('.b-comment__datetime').find("a").prepend(html);
  110. });
  111. }
  112.  
  113. $(document).ready( function(){
  114. makeSignature();
  115. $('.b-comment__wrapper').mouseover( function(e) {
  116. var $parentId;
  117. var id;
  118. if(!($('div').is(".b-illuminate"))) {
  119. $parentId = $(this).find('.icon-star').attr('data-objectid');
  120. illuminate($parentId);
  121. }
  122. });
  123. $('.b-comment__wrapper').mouseleave( function(e) {
  124. hide();
  125. });
  126. });
  127.  
  128.  
  129. // ==/UserScript==
  130. // (C) Paul Potseluev, Stepan Kiryushkin, helldotcat