Kongregate Mouseover API Checker

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

  1. // ==UserScript==
  2. // @name Kongregate Mouseover API Checker
  3. // @namespace tag://kongregate
  4. // @description When mouseovering a game in the game browser, this script checks if that game has API.
  5. // @include http://www.kongregate.com/games
  6. // @include http://www.kongregate.com/games/
  7. // @include http://www.kongregate.com/games?*
  8. // @include http://www.kongregate.com/top-rated-games*
  9. // @include http://www.kongregate.com/strategy-defense-games*
  10. // @include http://www.kongregate.com/adventure-rpg-games*
  11. // @include http://www.kongregate.com/shooter-games*
  12. // @include http://www.kongregate.com/puzzle-games*
  13. // @include http://www.kongregate.com/action-games*
  14. // @include http://www.kongregate.com/sports-racing-games*
  15. // @include http://www.kongregate.com/multiplayer-games*
  16. // @include http://www.kongregate.com/more-games*
  17. // @include http://www.kongregate.com/game_groups/*
  18. // @include http://www.kongregate.com/top-rated-games*
  19. // @include http://www.kongregate.com/my_favorites*
  20. // @include http://www.kongregate.com/accounts/*/favorites
  21. // @include http://www.kongregate.com/recommended-games
  22. // @exclude http://www.kongregate.com/games/*/*
  23. // @author Ventero
  24. // @version 1.2
  25. // @date 03.11.2012
  26. // ==/UserScript==
  27.  
  28. // Written by Ventero (http://www.kongregate.com/accounts/Ventero), 02/17/10
  29. // Copyright (c) 2010-2012 Ventero, licensed under MIT/X11 license
  30. // http://www.opensource.org/licenses/mit-license.php
  31. // Thanks to musicdemon for the idea of writing this
  32.  
  33. var cache = {};
  34.  
  35. function checkAPI(gameNode){
  36. var URL = gameNode.querySelector("a").href;
  37. if(cache[URL]) return;
  38. cache[URL] = 1
  39.  
  40. var target = gameNode.querySelector(".thumb dd");
  41. var apiNode = document.createElement("div");
  42.  
  43. apiNode.style.cssFloat = "left";
  44. apiNode.style.backgroundColor = "#f0f0f0";
  45. apiNode.style.border = "1px solid rgb(51,51,51)";
  46. apiNode.style.marginLeft = "2px";
  47. apiNode.style.marginRight = "2px";
  48. apiNode.style.marginTop = "-27px";
  49. apiNode.style.minWidth = "70px";
  50. apiNode.innerHTML = "Checking..."
  51. target.appendChild(apiNode);
  52.  
  53. var xhr = new XMLHttpRequest();
  54. xhr.onload = function(){
  55. if(xhr.readyState == 4 && xhr.status < 400){
  56. var matchValues = xhr.responseText.match(/new\s+Holodeck\(([^\)]+)\)/);
  57. if(matchValues){
  58. if(/"statistics":\[[^\]]+/.test(matchValues[1])){
  59. if(/accomplishment_tasks":\[[^\]]/.test(matchValues[1])){
  60. apiNode.innerHTML = "Badges";
  61. apiNode.style.color = "#0000ff";
  62. } else {
  63. apiNode.innerHTML = "API";
  64. apiNode.style.color = "#00ff00";
  65. }
  66. } else {
  67. apiNode.innerHTML = "No API";
  68. apiNode.style.color = "#ff0000";
  69. }
  70. if(/shared_content_type_names":\[[^\]]/.test(matchValues[1])){
  71. apiNode.style.marginTop = "-40px";
  72. apiNode.innerHTML += "<br/>(User content)";
  73. }
  74. }
  75. }
  76. }
  77.  
  78. xhr.open("GET", URL, true);
  79. xhr.send("");
  80. }
  81.  
  82. var games = document.getElementsByClassName("game media");
  83.  
  84. for(i = 0; i < games.length; i++){
  85. games[i].addEventListener("mouseover", function(){checkAPI(this)}, false);
  86. //checkAPI(games[i]);
  87. }