Hummingbird User Compare

Adds a button that compares the anime list of a hummingbird user against yours

Verze ze dne 27. 04. 2015. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Hummingbird User Compare
// @version      2.3
// @description  Adds a button that compares the anime list of a hummingbird user against yours
// @author       fuzetsu
// @match        https://hummingbird.me/*
// @match        https://forums.hummingbird.me/*
// @grant        none
// @require      https://greasyfork.org/scripts/5679-wait-for-elements/code/Wait%20For%20Elements.js?version=46106
// @noframes
// @namespace https://greasyfork.org/users/649
// ==/UserScript==
var SCRIPT_NAME = 'Hummingbird User Compare';
var BTN_CLASS = 'us-compare-button';
var USERNAME_SELECTOR = 'h2.username,h1.username';

var Util = {
  log: function() {
    var args = [].slice.call(arguments);
    args.unshift('%c' + SCRIPT_NAME + ':', 'font-weight: bold');
    console.log.apply(console, args);
  },
  q: function(query, context) {
    return (context || document).querySelector(query);
  },
  qq: function(query, context) {
    return [].slice.call((context || document).querySelectorAll(query));
  },
  shallowTextContent: function(elem) {
    var child = elem.firstChild,
        texts = [];

    while (child) {
      if (child.nodeType == 3) {
        texts.push(child.data);
      }
      child = child.nextSibling;
    }

    return texts.join("");
  }
};

var hb = {
  getCompareUrl: function() {
    var profileUrl = Util.q('.dropdown-menu > li > a').href;
    var you = profileUrl.slice(profileUrl.lastIndexOf('/') + 1);
    var them = Util.shallowTextContent(Util.q(USERNAME_SELECTOR)).trim();
    return {
      you: you,
      them: them,
      url: 'http://fuzetsu.github.io/hummingbird-user-compare/?user1=' + you + '&user2=' + them
    }
  }
};

var lastUser;

Util.log('Started, waiting for user page...');

waitForUrl(/https:\/\/(forums\.)?hummingbird\.me\/users\/.+/, function() {
  Util.log('Found user page, waiting for button area...');
  waitForElems('.user-cover-options .follow-button:not(.' + BTN_CLASS + ')', function(btnFollow) {
    var forumButton = Util.q('.account-info .inline-list a');
    var btn = Util.q('.' + BTN_CLASS);
    var compare = hb.getCompareUrl();
    // exit early if you're on your own profile
    if(compare.them === compare.you) return;
    Util.log('Found button area, inserting compare button');
    if(forumButton) {
      forumButton.title = '';
      forumButton.target = '_blank';
      forumButton.href = compare.url;
    } else {
      if(btn) {
        btn.remove();
      }
      btn = document.createElement('a');
      btn.className = btnFollow.className + ' ' + BTN_CLASS;
      btn.textContent = 'Compare';
      btn.target = '_blank';
      btn.setAttribute('style', 'right: ' + (btnFollow.clientWidth + 10) + 'px; background: rgb(236, 134, 97); color: white;');
      if(compare.them === lastUser && location.href.indexOf(lastUser) === -1) {
        Util.q(USERNAME_SELECTOR).addEventListener('DOMSubtreeModified', function(e) {
          this.removeEventListener('DOMSubtreeModified', arguments.callee);
          compare = hb.getCompareUrl();
          btn.href = compare.url;
          btnFollow.parentNode.appendChild(btn);
        });
      } else {
        btn.href = compare.url;
        btnFollow.parentNode.appendChild(btn);
      }
    }
    lastUser = compare.them;
  }, true);
});