MatchResult-Review Script

View match result in advance

当前为 2018-07-25 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         MatchResult-Review Script
// @namespace    https://greasyfork.org/users/198348
// @version      0.0.1
// @description  View match result in advance
// @author       TM
// @include	     http://trophymanager.com/matches/*
// @include	     https://trophymanager.com/matches/*
// ==/UserScript==

function insertBefore(el, referenceNode) {
  referenceNode.parentNode.insertBefore(el, referenceNode);
}

function insertAfter(el, referenceNode) {
  referenceNode.parentNode.insertBefore(el, referenceNode.nextSibling);
}

function showMatchResult() {
  var resultDiv = document.createElement('div');
  var matchID = location.href.match(/([^\/]*)\/*$/)[1];
  var xhr = new XMLHttpRequest();
  var url = 'https://trophymanager.com/ajax/match.ajax.php?id=' + matchID;
  resultDiv.className = 'main_center';

  xhr.open('GET', url, true);
  xhr.send();
  xhr.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
	  var data = JSON.parse(this.responseText);
      var homeClub = data.club.home.club_name;
	  var awayClub = data.club.away.club_name;
      var report = data.report;
      var scoreData = report[Object.keys(report).sort().pop()];
      var finalText = scoreData[0].chance.text[0];
      var finalScore = 'vs';
      if (report) {
        var finalTxtArray = finalText.toString().split(' ');
        finalTxtArray.forEach(function (str) {
	      if (str.indexOf('-') > -1) {
		    finalScore = str;
		  }
	    });
	  }
	  var htmlTxt = '<div style="width:100%;text-align:center;margin-top:10px;padding:10px;background-color:#000000;font-family:arial;font-size:15px;font-weight:bold;">';
	  htmlTxt += homeClub + '<span style="padding-left:10px;padding-right:10px;color:#CF0;">' + finalScore + '</span>' + awayClub + '</div>'
      resultDiv.innerHTML = htmlTxt;
      var mainCenters = document.getElementsByClassName('main_center');
	  var lastMainDiv = mainCenters[mainCenters.length - 1];
        if (lastMainDiv) {
		  insertBefore(resultDiv, lastMainDiv);
        }
    }
  };
}

(function() {
  'use strict';
  showMatchResult();
})();