Kongregate Mouseover API Checker

When mouseovering a game in the game browser, this script checks if that game has API.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name           Kongregate Mouseover API Checker
// @namespace      tag://kongregate
// @description    When mouseovering a game in the game browser, this script checks if that game has API.
// @include        http://www.kongregate.com/games
// @include        http://www.kongregate.com/games/
// @include        http://www.kongregate.com/games?*
// @include        http://www.kongregate.com/top-rated-games*
// @include        http://www.kongregate.com/strategy-defense-games*
// @include        http://www.kongregate.com/adventure-rpg-games*
// @include        http://www.kongregate.com/shooter-games*
// @include        http://www.kongregate.com/puzzle-games*
// @include        http://www.kongregate.com/action-games*
// @include        http://www.kongregate.com/sports-racing-games*
// @include        http://www.kongregate.com/multiplayer-games*
// @include        http://www.kongregate.com/more-games*
// @include        http://www.kongregate.com/game_groups/*
// @include        http://www.kongregate.com/top-rated-games*
// @include        http://www.kongregate.com/my_favorites*
// @include        http://www.kongregate.com/accounts/*/favorites
// @include        http://www.kongregate.com/recommended-games
// @exclude        http://www.kongregate.com/games/*/*
// @author         Ventero
// @version        1.2
// @date           03.11.2012
// ==/UserScript==

// Written by Ventero (http://www.kongregate.com/accounts/Ventero), 02/17/10
// Copyright (c) 2010-2012 Ventero, licensed under MIT/X11 license
// http://www.opensource.org/licenses/mit-license.php
// Thanks to musicdemon for the idea of writing this

var cache = {};

function checkAPI(gameNode){
	var URL = gameNode.querySelector("a").href;
	if(cache[URL]) return;
	cache[URL] = 1

	var target = gameNode.querySelector(".thumb dd");
	var apiNode = document.createElement("div");

	apiNode.style.cssFloat = "left";
	apiNode.style.backgroundColor = "#f0f0f0";
	apiNode.style.border = "1px solid rgb(51,51,51)";
	apiNode.style.marginLeft = "2px";
	apiNode.style.marginRight = "2px";
	apiNode.style.marginTop = "-27px";
	apiNode.style.minWidth = "70px";
	apiNode.innerHTML = "Checking..."
	target.appendChild(apiNode);

	var xhr = new XMLHttpRequest();
	xhr.onload = function(){
		if(xhr.readyState == 4 && xhr.status < 400){
			var matchValues = xhr.responseText.match(/new\s+Holodeck\(([^\)]+)\)/);
			if(matchValues){
				if(/"statistics":\[[^\]]+/.test(matchValues[1])){
					if(/accomplishment_tasks":\[[^\]]/.test(matchValues[1])){
						apiNode.innerHTML = "Badges";
						apiNode.style.color = "#0000ff";
					} else {
						apiNode.innerHTML = "API";
						apiNode.style.color = "#00ff00";
					}
				} else {
					apiNode.innerHTML = "No API";
					apiNode.style.color = "#ff0000";
				}
				if(/shared_content_type_names":\[[^\]]/.test(matchValues[1])){
					apiNode.style.marginTop = "-40px";
					apiNode.innerHTML += "<br/>(User content)";
				}
			}
		}
	}

	xhr.open("GET", URL, true);
	xhr.send("");
}

var games = document.getElementsByClassName("game media");

for(i = 0; i < games.length; i++){
	games[i].addEventListener("mouseover", function(){checkAPI(this)}, false);
	//checkAPI(games[i]);
}