Merlin-R / Torn Menu Extension

// ==UserScript==
// @namespace    https://openuserjs.org/users/Merlin-R
// @name         Torn Menu Extension
// @description  Extend Torn Sidebar Menu
// @copyright    2018, Merlin-R (https://openuserjs.org/users/Merlin-R)
// @license      MIT
// @version      0.1.1
// @author       Merlin-R
// @match        *.torn.com/*
// @include      *.torn.com/*
// @grant        none
// ==/UserScript==

// ==OpenUserJS==
// @author Merlin-R
// ==/OpenUserJS==

(function () {
  'use strict';

  function SidebarEntry(props) {
    this.props = $.extend({}, SidebarEntry.defaults, props);
    if (this.props.copyIcon)
      this.copyIcon();
  }

  SidebarEntry.prototype.render = function () {
    var $root = $('<div />');
    var $container = $('<div />');
    var $link = $('<a />');
    var $name = $('<span>' + this.props.name + '</span>');
    var $icon = $('<i />');

    $link.attr('href', this.props.link);
    $icon.attr('class', this.props.iconClass);
    $container.attr('class', this.props.containerClass);
    $root.attr('class', this.props.entryClass);
    $root.attr('id', this.props.id || 'nav-' + this.props.name.toLowerCase().replace(/\s/g, '-'));

    $root.append($container);
    $container.append($link);
    $link.append($icon);
    $link.append($name);

    this.$entry = $root;

    return $root;
  };

  SidebarEntry.prototype.copyIcon = function () {
    this.props.iconClass = $('#nav-' + this.props.copyIcon).find('i').attr('class');
  };

  SidebarEntry.prototype.add = function (index) {
    if (!index)
      SidebarEntry.$sidebar.prepend(this.render());
    else if (index > 0)
      SidebarEntry.$sidebar.children(':nth-child(' + index + ')').after(this.render());
    else
      this.add(SidebarEntry.$sidebar.children().length + 1 + index);
  };

  var $navItems = $('#nav-items');

  SidebarEntry.defaults = {
    entryClass: $navItems.attr('class'),
    containerClass: $navItems.children().attr('class'),
    iconClass: $navItems.find('i').attr("class")
  };

  SidebarEntry.$sidebar = $navItems.parent();

  /* ENTRIES START HERE */
  new SidebarEntry({
    name: 'Market',
    link: '/imarket.php'
  }).add(1);
  new SidebarEntry({
    name: 'Faction Armory',
    link: '/factions.php?step=your#/tab=armoury',
    copyIcon: 'factions'
  }).add(-2);

})();