Dzejkobini

esim.profilehoverextension

Jan 3rd, 2016
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name ProfileHoverExtension
  3. // @description  Add bacis icons when you mouse over player name.
  4. // @include http://*.e-sim.org/*
  5. // @grant none
  6. // ==/UserScript==
  7. var m_nPlayerId;
  8.  
  9. $(document).ready(function() {
  10.     m_nPlayerId = $("[class='button foundation-style'][href*='profile']").attr('href').replace(/[^0-9]/g, '');
  11.     var aTimer;
  12.     $('[href*="profile.html?id="], [href*="stockCompany.html?id="]').mouseenter(function() {
  13.         var that = this;
  14.         if ($(this).attr('href').indexOf(m_nPlayerId) == -1)
  15.             aTimer = setTimeout(function() {
  16.                 showIcons(that);
  17.             }, 1000);
  18.     }).mouseleave(function() {
  19.         clearTimeout(aTimer);
  20.         hideIcons();
  21.     });
  22. });
  23.  
  24. /**
  25.  * show extra icons.
  26.  */
  27. function showIcons(that) {
  28.     var bIsStock = false;
  29.     if ($(that).attr('href').indexOf("stockCompany") != -1)
  30.         bIsStock = true;
  31.  
  32.     var aOffset = $(that).offset();
  33.     var nId = $(that).attr("href").replace(/^\D+/g, '');
  34.     var aDiv = $('<div class="testDivblue" id="extTooltip"></div>').css({
  35.         "position": "absolute",
  36.         "top": aOffset.top - 37,
  37.         "left": aOffset.left,
  38.         "background-image": 'url("http://cdn.e-sim.org/img/bg4.png")',
  39.         "border-style": "solid",
  40.         "border-width": 1,
  41.         "border-color": "#777",
  42.         "border-radius": 3
  43.     });
  44.  
  45.     if (!bIsStock) {
  46.         aDiv.append('<a href="donateEquipment.html?id=' + nId + '"><div class="citizenAction" style="display: flex; align-items: center;"><img style="margin: auto;" src="//cdn.e-sim.org//img/equipment.png" title="Donate equipment" /></div></a>');
  47.         aDiv.append('<a href="donateProducts.html?id=' + nId + '"><div class="citizenAction" style="display: flex; align-items: center;"><img style="margin: auto;" src="//cdn.e-sim.org//img/package.png" class="help" title="Donate items" /></div></a>  ');
  48.         aDiv.append('<a href="donateMoney.html?id=' + nId + '"><div class="citizenAction" style="display: flex; align-items: center;"><img style="margin: auto;" src="//cdn.e-sim.org//img/dollar.png" class="help" title="Donate money" /></div></a>');
  49.         aDiv.append('<a href="composeMessage.html?id=' + nId + '"><div class="citizenAction" style="display: flex; align-items: center;"><img style="margin: auto;" src="//cdn.e-sim.org//img/mail.png" class="help" title="Send an ingame message" /></div></a>');
  50.     } else {
  51.         aDiv.append('<a href="stockCompanyDonateMoney.html?id=' + nId + '"><div class="citizenAction" style="display: flex; align-items: center;"><img style="margin: auto;" src="//cdn.e-sim.org//img/dollar.png" class="help" title="Donate money" /></div></a>');
  52.         aDiv.append('<a href="stockCompanyDonateCompany.html?id=' + nId + '"><div class="citizenAction" style="display: flex; align-items: center;"><img style="margin: auto;" src="//cdn.e-sim.org//img/newCompany.png" class="help" title="Send an ingame message" /></div></a>');
  53.     }
  54.     aDiv.mouseleave(function() {
  55.         this.remove();
  56.     });
  57.     $("body").append(aDiv);
  58. }
  59.  
  60. /**
  61.  * hide extra icons.
  62.  */
  63. function hideIcons() {
  64.     if (typeof $("#extTooltip")[0] != 'undefined') {
  65.         var bIsHovered = $('#extTooltip').is(":hover");
  66.         if (!bIsHovered)
  67.             $("#extTooltip").remove();
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment