TJ

thread navigation helper for TJ club

目前為 2015-07-30 提交的版本,檢視 最新版本

// ==UserScript==
// (C) Paul Potseluev, Stepan Kiryushkin
// @name        TJ
// @namespace   TJ
// @include     https://tjournal.ru/*
// @version     1
// @grant       none
// @description thread navigation helper for TJ club
// @description:ru Расширение упращяет навигацию в обсуждениях в клубе TJ
TJComments = {
  d: $(document),
  b: $('html, body'),
  up_icon: 'https://maxcdn.icons8.com/windows8/PNG/26/Arrows/up_circular-26.png',
  down_icon: 'https://maxcdn.icons8.com/windows8/PNG/26/Arrows/down_circular-26.png',

  init: function() {
    this.createAnchors();

    $('.b-comment__up').click(function(e) {
      e.preventDefault();

      var $this     = $(this),
          $previous = $this.prev(),
          parent_id = $previous.data('parent-id'),
          $parent   = $('#commentBox' + parent_id),
          $children = $this.parents('.b-comment');

      TJComments.scrollTo($parent);
      TJComments.createBack($parent, $children);
    });

    TJComments.d.on('click', '.b-comment__down', function(e) {
      e.preventDefault();

      var $this       = $(this),
          children_id = $this.data('children-id'),
          $children   = $('#commentBox' + children_id);

      $this.remove();
      TJComments.scrollTo($children);
    });
  },

  scrollTo: function($element) {
    TJComments.b.animate({ scrollTop: $element.offset().top }, 500)
    $element.effect("highlight", { color: 'rgba(217,239,55,0.1)' }, 1500);
  },

  createAnchors: function() {
    var html =  '<a href="#" class="b-comment__up">' +
                  '&nbsp;&nbsp;<img src="' + this.up_icon + '" width="12px" style="top:3px;position:relative;">' +
                '</a>';

    $('.b-comment__datetime.highlightParent').after(html);
  },

  createBack: function($parent, $children) {
    var html =  '<a href="#" class="b-comment__down" data-children-id="' + $children.data('id') + '">' +
                  '&nbsp;&nbsp;<img src="' + this.down_icon + '" width="12px" style="top:3px;position:relative;">' +
                '</a>';

    $parent.find('.b-comment__datetime').after(html);
  }
}

TJComments.d.ready(function() {
  TJComments.init();
});
// ==/UserScript==
// (C) Paul Potseluev, Stepan Kiryushkin