goodgame.ru stats buttons

add stats buttons to user profile pages on goodgame.ru

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name     goodgame.ru stats buttons
// @description add stats buttons to user profile pages on goodgame.ru
// @description:en add stats buttons to user profile pages on goodgame.ru
// @version  1.4.2
// @include  https://goodgame.ru/*
// @grant    unsafeWindow
// @run-at   document-idle
// @namespace https://greasyfork.org/users/72530
// ==/UserScript==

var url = window.location.href;

if (isProfilePage(url)) { AddButtonToProfile(); };


setInterval(function () {
  if (window.location.href != url)
  {
    url = window.location.href;
    if (isProfilePage(url)) { AddButtonToProfile(); };
  }
}, 1000);

function isProfilePage(currentUrl) {
  return currentUrl.indexOf("goodgame.ru/user/") !== -1;
}

function AddButtonToProfile() {
  let count = 0;
  var checkExist = setInterval(function() {
      count += 1;
      if (count > 100) {clearInterval(checkExist); return;};
      let elems = document.getElementsByClassName("user-profile__buttons");
      let elem_subcount = 0;
      if (elems.length > 0) {
          elem_subcount = elems[0].childElementCount;
      }
      if ((elem_subcount >= 2) && (elem_subcount < 5)) {
          clearInterval(checkExist);
          // action
          var userId = window.location.href.split("/user/")[1].replace("/","");
          var statsHref = "https://ggstats.strayge.com/user/" + userId;
          var buttons = document.getElementsByClassName("user-profile__buttons")[0];

          var btn = document.createElement("a");
          btn.href = statsHref;
          btn.setAttribute('target', '_blank');
          btn.className = "btn btn-blue transparent";
          btn.setAttribute('onmouseover', 'this.style.backgroundColor="rgba(68,83,126,.75)"');
          btn.setAttribute('onmouseout', 'this.style.backgroundColor="rgba(68,83,126,.5)"');
          btn.setAttribute('style', 'background-color: rgba(68,83,126,.5);');
          btn.innerHTML = '<span class="icon icon-charts2" style="margin-right: 8px;"></span><span class="user-profile__text_desktop">Стата</span>';
          buttons.appendChild(btn);
      }
  }, 100);
}