// ==UserScript== // @name Kongregate played // @description Caches recently played games. // @include http://www.kongregate.com/* // @version 0.0.1.20160306133707 // @namespace https://greasyfork.org/users/32649 // @downloadURL https://update.greasyfork.icu/scripts/17755/Kongregate%20played.user.js // @updateURL https://update.greasyfork.icu/scripts/17755/Kongregate%20played.meta.js // ==/UserScript== if(typeof GM_setValue == "undefined") { function GM_setValue(name, value) { localStorage.setItem(name, value); } function GM_getValue(name, defaultValue) { var value = localStorage.getItem(name); if(value) return value; else return defaultValue; } function GM_deleteValue(name) { localStorage.removeItem(name); } } if(location.toString().split("?")[0].split("#")[0] == "http://www.kongregate.com/accounts/"+unsafeWindow.active_user.username()) setTimeout(show, 0); if(/^http:\/\/www\.kongregate.com\/games\/[a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+$/.test(location.toString())) setTimeout(save, 5000); function show() { var games = GM_getValue("kongregateRecentlyPlayedList", "null"); var preferences = JSON.parse(GM_getValue("kongregateRecentlyPlayedPreferences", "{\"maxGames\":18,\"minRating\":2.75,\"registerUnrated\":false,\"autoLoad\":true}")); if(games == "null") return; var gamesList = games.split("|"); var currentGame, firstOfPage; var pages = Math.floor((gamesList.length-1)/6)+1, settings, clearButton; var pagesList = [], currentSelectedPage = -1, currentPagePlaceHolder; var globalGamesHolder = document.getElementById("secondary"); var insertBeforePoint = document.getElementById("cards"); var mainGamesHolder = document.createElement("div"); var gamesHolder = document.createElement("div"); var recentlyPlayedTitle = document.createElement("h2"); var recentlyPlayedPages = document.createElement("h3"); function addGameToProfileList(name, target, imageURL, first) { var container_L0 = document.createElement("dl"); container_L0.setAttribute("class", "favgame"+(first?" first":"")); var container_L1 = document.createElement("dt"); container_L0.appendChild(container_L1); var imageLink = document.createElement("a"); imageLink.setAttribute("href", "http://www.kongregate.com/games/"+target); container_L1.appendChild(imageLink); var image = document.createElement("img"); image.setAttribute("src", "http://cdn"+imageURL.charAt(0)+".kongregate.com/game_icons/"+imageURL.substring(1)); image.setAttribute("alt", "Play "+name); image.setAttribute("width", 93); image.setAttribute("height", 74); imageLink.appendChild(image); var container_link = document.createElement("dd"); container_L0.appendChild(container_link); var textLink = document.createElement("a"); textLink.innerHTML = name; textLink.setAttribute("href", "http://www.kongregate.com/games/"+target); container_link.appendChild(textLink); gamesHolder.appendChild(container_L0); } function loadPage(pageIndex) { while(gamesHolder.childNodes.length) gamesHolder.removeChild(gamesHolder.childNodes[0]); flagSelectedPage(pageIndex, (pageIndex+1).toString()); firstOfPage = true; for(var i=pageIndex*6;i\W*([^\n\r]*)/)[1]; var rating = document.getElementById("game_ratings_size").innerHTML.toString().match(/[1-5]\.[0-9]{2}/) || "0.00"; var preferences = JSON.parse(GM_getValue("kongregateRecentlyPlayedPreferences", "{\"maxGames\":18,\"minRating\":2.75,\"registerUnrated\":false,\"autoLoad\":true}")); if(parseFloat(rating) >= preferences.minRating || (rating == "0.00" && preferences.registerUnrated)) { var games = GM_getValue("kongregateRecentlyPlayedList", "null"); var games_list = games.split("|"); var results = urlPart+";"+iconPart+";"+gameTitle; for(i=0;ipreferences.maxGames) games_list.splice(0,games_list.length-preferences.maxGames); GM_setValue("kongregateRecentlyPlayedList", games_list.join("|")); } }