MatchResult-Review Script

View match result in advance

目前為 2018-07-25 提交的版本,檢視 最新版本

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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();
})();