Ebay - Add links to similar and suggested items

Adds links to similar/suggested items pages for all item pages

// ==UserScript==
// @name           Ebay - Add links to similar and suggested items
// @description    Adds links to similar/suggested items pages for all item pages
// @author         James Skinner <spiralx@gmail.com> (http://github.com/spiralx)
// @namespace      http://spiralx.org/
// @version        1.2.1
// @icon           data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuNWWFMmUAAABxSURBVDhPY8AB1IF4OxB/hmIQGyRGFFAB4ldAnAnEPFAMYoPEQHIEwTogzoEwUUA+EIPkCAKQk0G2ogMJIAbJYYD/FGKsgsTjp0YW/5ExQ8olFPx1PRMKbtshjoJHDRgUBmDEK+kYqyApGKsgkZjhPwD2u2Q5hCnUtQAAAABJRU5ErkJggg==
// @icon64         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAIAAAAlC+aJAAAG6UlEQVRo3u2aa2xT5xnH/+diHx8njp00OMHOYne5rGUQkgDhmtKuZAyJaF1LOrb2AxPSuEgbFGiLNhXRbf3QiiEWrQvbGsZ60aAq2kpXsa2wZCSkpVAITZsuES4JxHbimPhuH/vc9uGcOE7sgDRt2rKd99PR+z7nPc/vub7n2IQsy5jLg8QcHxqABqABaAAagAagAWgAGoAGoAFoABrAf2rQ/8Q9x7tv/7YnCGDHQ0WPLyucewBDt/nOwRiA5lqTFkIawP9iEgsC1/tx6tN+ye+HIBAsS9/rZJY30NZ5ObeIJcX3Po1cuclNxASDjqwu0W9cXGCz6LMlxfBnor9LjrsgREDqCX0RYaqhSpp4yPHUhCJTYJhPkbrZ1A3EbyoXJqaEppgcANG3/xht+5Xo82W5imQ3rDfv3UVZLJnT7V0T+095/VFxmlXe8H5njeVQy/wCVt1fjAymerdL/s5snQidJerYesxzQpJTANbf/+ISx5ac2l/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3NbpHxhNAchjyEcWJNOFIMe2w7+Rk2PTqgWpa6zcny5HXddfUs1fuY8kqTudhUw7txF6PYD4798OvvhTMRROL3FXeyf2PgtZBsA2b4wQUzGw/62x5/7gDSfUgIly4gvvju0+oWbRTx4psTrWqsk1/Irg78mwPZ/6/Cjftztbp4W25pKCxQCCiaFbgQ8AWE2LFtqac4bDtE4c7zwf/OEBOcEBIPQ6uqqSYFnJOyq4PYqAvr72ntbDe04Hfnb2NoAnllve7YsE46JBR9w33wDg716O49UNn2oqPtRiI6VEvPshOfCh2jks9SRbJosJOXhVTo0TjJUoflByvwlA33BKZ//GZIvsPPnRN9OKPVp7/L7SDTkBqIMHD061FafDsL5JikQlj1dOcNK4X/R4pUgEAF1dZfru1sKn9xAM03M9Hk6IpWb6qaZ7nmu2BhNivyd1a4IfDQmCBAANTvblJ2y71s0jCIDUUfbNkCU50gcpCc4rRwfkmAuQqS88ySz7HUGxcsxFGEpJ6zrKVK1oUpTndI3/NZL0Kub/6oLnAeLuHsg8kPIjbnHcL8fjpNlMOx2UxXyHtOZ48RN30hfmTQaqwqrPeRSFxIuhPjnpkwmSZKyU6X5kNNQZI5EKtnU1cHwIQEv9G1XWdbNJEv+dvxN3DLzw/o1WADZz/ZaVZ+bYC02EG7t8s32y9u+be29k3a4jvBgDYDcvrbQ+/K//KvFvHRwfDsRd5YWrADxQ9exd5QntvxIagAagAWgAGoAGoAFoABqABqABaAAawP8pwD8AMGz36P6ZROQAAAAASUVORK5CYII=
// @match          *://www.ebay.tld/itm/*
// @grant          GM_addStyle
// @grant          GM_getResourceURL
// @resource       icon_similar data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAw1JREFUeNqUkm1ollUYx3/3fe77edmz2m7Xi8s1UXS5WCIYFKTysFFCRIz11dBMcFN50iAjcnO2fSnJSGgaFCgEBa4gjLmZlmkQkn0o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L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PqQt0TAAAALESURBVHjanFJrSFNhGH7OZdNN59TpVkgXXWamU9MCqcChSSlYIkHhn6CowB/dJAjM6CJlKFRIEEVY/chKYS6l/lgmotUUohRCzbAluraxNi9zZ2fnfJ2ZZouo6IH3e9/v9nzv97wvhQVUGmP0FIsebZxC5+MIXC7ui4wWt9R1ukfxB9CLAS/AvCknTpeVlYSU1CTIFFE6j4c34S9gF4MwBZUml0eAkceCldOg4IB3ZtbwzwR+LgDr+BT0ETIkZyTDpdBDlafDRZomRAxIJygwLFtz6mRl9W+ZDm6UE+IzEXGkgVy9VkdaTG3kV7S2tpKaS5dtP99jFgNDrJBSWpZvePLyKxhVMvbs3oWKm89Qfb8XtzreYcDqwPHyIjjttkhDZjbb+byjM0TEvkDieUvfGF4NBVBWsh1H7vaiQBK0paocNYfK4A+PxYl7vdhZvAM87z8dUoXtDWNNWy+8ee/VGsHNcQhXKjDkEpGlX4EPnjlMiiIS09dgWFpjw5UQAvySiMbat/a9G5TxualqrHRzMPM8iJ+DOlqDIYcXwQ/T0QpoowCVWiPVm5MyEJb6YJmKic9IUKJpwAdPQgmUYQxsdjuyEzXotvpgmxEgCCImJjlkrtbA5nDMV+QHgdvjw6iTkzpvClc63DDm5aG9vR0H0gBttArOmSgMDrOI8NPYn07B9PgpItQxuNH4MG3+Cw73DD67eHgkIhfxoVFcB53VAqrlAcoKC6FapZp/yT09i+bmF7BOOFF75jD6rxcNBlOhtPvMZFvuWmiiIyGVWlpiIFAyyMe7EGl/DYh+iIQGL/VcgApDqYFHnsYM5N+B5XYVWO/H7mNtXm+9IHzvShIcKFryDAi1WTKK5z/1HCWWektwy3iuoF8gc2C6KsCL2nk11JLpQ5QJRZBzRLLphXnOo7PF/YRQWL/c00Xh/5Cz4N3fBBgAJ4IpvJlfMQcAAAAASUVORK5CYII=
// @require        https://unpkg.com/jquery@3/dist/jquery.min.js
// ==/UserScript==

/* jshint asi: true, esnext: true, laxbreak: true */
/* global jQuery, MutationSummary */

/**

==== 1.2.1 (13.07.2018) ====
* Update linting options and globals
* Update jQuery to v3 hosted on unpkg.com

*/

(function($) {
  'use strict';

  function social_icon(href, title, icon) {
    return $(`<a rel="nofollow" title="${title}" href="${href}" class="sw_talk spx-icon">`)
      .css('background', `url(${GM_getResourceURL(icon)})`)
  }

  // --------------------------------------------------------------------

  var m = location.pathname.match(/\/(\d+)$/),
      item_id = m ? m[1] : $('[data-itemid]').data('itemid')

  // console.info('item_id:', item_id);

  if (item_id) {
    let $beforeElem = $('#RightSummaryPanel td:first, #RightSummaryPanel .share').last()
    
    let $links = $('<div class="spx-icons"></div>')
      // .prepend(social_icon(`/rcm/?itm=${item_id}`, 'Suggested items', 'icon_recommend'))
      .prepend(social_icon(`/rcm/v1/?itm=${item_id}`, 'View suggested items', 'icon_recommend'))
      .prepend(social_icon(`/itm/like/${item_id}`, 'View similar items', 'icon_similar'))
      .insertBefore($beforeElem)
    
    if ($beforeElem.is('td')) {
      $links
        .append('<span class="watchPipe">|</span>')
        .wrap('<td>')
    }

    GM_addStyle(`
      .spx-icons {
        display: inline-block;
        vertical-align: middle;
        height: 25px;
      }

      .spx-icon {
        display: inline-block;
        float: left;
        margin: 1px 3px;
        width: 16px;
        height: 16px;
        text-decoration: none;
      }
    `)
  }

})(jQuery)

jQuery.noConflict()