Kongregate played

Caches recently played games.

  1. // ==UserScript==
  2. // @name Kongregate played
  3. // @description Caches recently played games.
  4. // @include http://www.kongregate.com/*
  5. // @version 0.0.1.20160306133707
  6. // @namespace https://gf.qytechs.cn/users/32649
  7. // ==/UserScript==
  8.  
  9. if(typeof GM_setValue == "undefined") {
  10.  
  11. function GM_setValue(name, value) {
  12. localStorage.setItem(name, value);
  13. }
  14.  
  15. function GM_getValue(name, defaultValue) {
  16. var value = localStorage.getItem(name);
  17. if(value) return value;
  18. else return defaultValue;
  19. }
  20.  
  21. function GM_deleteValue(name) {
  22. localStorage.removeItem(name);
  23. }
  24.  
  25. }
  26.  
  27. if(location.toString().split("?")[0].split("#")[0] == "http://www.kongregate.com/accounts/"+unsafeWindow.active_user.username())
  28. setTimeout(show, 0);
  29. if(/^http:\/\/www\.kongregate.com\/games\/[a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+$/.test(location.toString()))
  30. setTimeout(save, 5000);
  31.  
  32. function show() {
  33.  
  34. var games = GM_getValue("kongregateRecentlyPlayedList", "null");
  35. var preferences = JSON.parse(GM_getValue("kongregateRecentlyPlayedPreferences", "{\"maxGames\":18,\"minRating\":2.75,\"registerUnrated\":false,\"autoLoad\":true}"));
  36. if(games == "null") return;
  37. var gamesList = games.split("|");
  38. var currentGame, firstOfPage;
  39. var pages = Math.floor((gamesList.length-1)/6)+1, settings, clearButton;
  40. var pagesList = [], currentSelectedPage = -1, currentPagePlaceHolder;
  41. var globalGamesHolder = document.getElementById("secondary");
  42. var insertBeforePoint = document.getElementById("cards");
  43. var mainGamesHolder = document.createElement("div");
  44. var gamesHolder = document.createElement("div");
  45. var recentlyPlayedTitle = document.createElement("h2");
  46. var recentlyPlayedPages = document.createElement("h3");
  47.  
  48. function addGameToProfileList(name, target, imageURL, first) {
  49. var container_L0 = document.createElement("dl");
  50. container_L0.setAttribute("class", "favgame"+(first?" first":""));
  51. var container_L1 = document.createElement("dt");
  52. container_L0.appendChild(container_L1);
  53. var imageLink = document.createElement("a");
  54. imageLink.setAttribute("href", "http://www.kongregate.com/games/"+target);
  55. container_L1.appendChild(imageLink);
  56. var image = document.createElement("img");
  57. image.setAttribute("src", "http://cdn"+imageURL.charAt(0)+".kongregate.com/game_icons/"+imageURL.substring(1));
  58. image.setAttribute("alt", "Play "+name);
  59. image.setAttribute("width", 93);
  60. image.setAttribute("height", 74);
  61. imageLink.appendChild(image);
  62. var container_link = document.createElement("dd");
  63. container_L0.appendChild(container_link);
  64. var textLink = document.createElement("a");
  65. textLink.innerHTML = name;
  66. textLink.setAttribute("href", "http://www.kongregate.com/games/"+target);
  67. container_link.appendChild(textLink);
  68. gamesHolder.appendChild(container_L0);
  69. }
  70. function loadPage(pageIndex) {
  71.  
  72. while(gamesHolder.childNodes.length)
  73. gamesHolder.removeChild(gamesHolder.childNodes[0]);
  74.  
  75. flagSelectedPage(pageIndex, (pageIndex+1).toString());
  76.  
  77. firstOfPage = true;
  78. for(var i=pageIndex*6;i<pageIndex*6+6&&i<gamesList.length;i++) {
  79. currentGame = gamesList[gamesList.length-i-1].split(";");
  80. addGameToProfileList(currentGame[2], currentGame[0], currentGame[1], firstOfPage);
  81. firstOfPage = false;
  82. }
  83. }
  84. function flagSelectedPage(pageIndex, flagText) {
  85. if(currentSelectedPage != -1) {
  86. recentlyPlayedPages.insertBefore(pagesList[currentSelectedPage], currentPagePlaceHolder);
  87. recentlyPlayedPages.removeChild(currentPagePlaceHolder);
  88. }
  89. recentlyPlayedPages.insertBefore(currentPagePlaceHolder = document.createTextNode(flagText), pagesList[pageIndex]);
  90. recentlyPlayedPages.removeChild(pagesList[pageIndex]);
  91. currentSelectedPage = pageIndex;
  92. }
  93. function addItem(name) {
  94. var open_text = document.createTextNode(" (");
  95. var link = document.createElement("a");
  96. var close_text = document.createTextNode(")");
  97. link.innerHTML = name;
  98. link.setAttribute("href", "javascript:void(0);");
  99. recentlyPlayedPages.appendChild(open_text);
  100. recentlyPlayedPages.appendChild(link);
  101. recentlyPlayedPages.appendChild(close_text);
  102. pagesList.push(link);
  103. return link;
  104. }
  105.  
  106. function addPage(index) {
  107. var link = addItem((index+1).toString());
  108. link.addEventListener("click", function(event) {loadPage(index)}, false);
  109. }
  110.  
  111. function loadSettings(event) {
  112. var GM_preferences = GM_getValue("kongregateRecentlyPlayedPreferences", "{\"maxGames\":18,\"minRating\":2.75,\"registerUnrated\":false,\"autoLoad\":true}");
  113. var settings_input = unsafeWindow.prompt("This is a JSON reflection of the changeable variables:", GM_preferences);
  114. if(settings_input == null) return;
  115. settings_input.replace(/ /g, "");
  116. if(/^\{"maxGames":[0-9]+,"minRating":(([1-3](\.[0-9]{1,2})?)|(4(\.[0-4][0-9]?|\.50?))),"registerUnrated":(true|false),"autoLoad":(true|false)\}$/.test(settings_input)) {
  117. GM_setValue("kongregateRecentlyPlayedPreferences", settings_input);
  118. alert("Settings have been overwritten.");
  119. } else {
  120. alert("Invalid syntax.");
  121. }
  122. }
  123.  
  124. for(var i=0;i<pages;i++)
  125. addPage(i);
  126.  
  127. settings = addItem("Settings");
  128. settings.addEventListener("click", loadSettings, false);
  129.  
  130. clearButton = addItem("Clear");
  131. clearButton.addEventListener("click", function(event) {
  132. if(!window.confirm("Are you sure you want to clear your recently played games history?")) return;
  133. GM_deleteValue("kongregateRecentlyPlayedList");
  134. globalGamesHolder.removeChild(mainGamesHolder);
  135. if(window.confirm("Do you want to clear the settings too? Reset them to default?"))
  136. GM_deleteValue("kongregateRecentlyPlayedPreferences");
  137. }, false);
  138.  
  139. recentlyPlayedTitle.innerHTML = "Recently played";
  140. mainGamesHolder.appendChild(recentlyPlayedTitle);
  141. mainGamesHolder.appendChild(recentlyPlayedPages);
  142. gamesHolder.setAttribute("class", "games wrapper");
  143. mainGamesHolder.appendChild(gamesHolder);
  144. globalGamesHolder.insertBefore(mainGamesHolder, insertBeforePoint);
  145.  
  146. if(preferences.autoLoad) loadPage(0);
  147. }
  148.  
  149. function save() {
  150.  
  151. var url = location.toString();
  152. var urlPart = url.match(/^http:\/\/www\.kongregate\.com\/games\/([a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+)/)[1];
  153.  
  154. var metas = document.getElementsByTagName("meta"), icon;
  155. for(var i=0;i<metas.length;i++)
  156. if(metas[i].getAttribute("property") == "og:image") {
  157. icon = metas[i].getAttribute("content");
  158. break;
  159. }
  160. var iconPart = icon.match(/^http:\/\/cdn([0-9])\.kongregate\.com\/game_icons\/([0-9]{4}\/[0-9]{4}\/.+?\.(png|jpg|gif))/);
  161. iconPart = iconPart[1] + iconPart[2];
  162.  
  163. var gameTitle = document.getElementById("gamepage_header").innerHTML.match(/<\/span>\W*([^\n\r]*)/)[1];
  164.  
  165. var rating = document.getElementById("game_ratings_size").innerHTML.toString().match(/[1-5]\.[0-9]{2}/) || "0.00";
  166. var preferences = JSON.parse(GM_getValue("kongregateRecentlyPlayedPreferences", "{\"maxGames\":18,\"minRating\":2.75,\"registerUnrated\":false,\"autoLoad\":true}"));
  167. if(parseFloat(rating) >= preferences.minRating || (rating == "0.00" && preferences.registerUnrated)) {
  168. var games = GM_getValue("kongregateRecentlyPlayedList", "null");
  169. var games_list = games.split("|");
  170. var results = urlPart+";"+iconPart+";"+gameTitle;
  171. for(i=0;i<games_list.length;i++)
  172. if(games_list[i].match(urlPart) || games_list[i] == "null") {
  173. games_list.splice(i,1);
  174. break;
  175. }
  176. games_list.push(results);
  177. if(games_list.length>preferences.maxGames)
  178. games_list.splice(0,games_list.length-preferences.maxGames);
  179. GM_setValue("kongregateRecentlyPlayedList", games_list.join("|"));
  180. }
  181. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址