/* The MIT License (MIT) Copyright (c) 2014 RePod Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ //The license information above is also available in PSDLE's GitHub repository located here: https://github.com/RePod/psdle var repod = {}; repod.psdle = { gamelist: [], gamelist_cur: [], autocomplete_cache: [], lang: {}, id_cache: {}, type_cache: {}, sys_cache: {}, pid_cache:{}, lang_cache: { "en": { "def": "us", "us":{"local":"English","startup":{"apis":"Select which APIs you would like to use, hover for more details.
Certain APIs may not be disabled.","wait":"Please wait.","start":"Start"},"columns":{"icon":"Icon","name":"Name","platform":"Platform","size":"Size","date":"Date"},"labels":{"export_view":"Export View","page":"Page"},"categories":{"downloadable_game":"Games","demo":"Demos","add_on":"Add-ons","unlock":"Unlocks","unlock_key":"Unlock Keys","avatar":"Avatars","theme":"Themes","other":"other","other_game_related":"other_game_related","game_content":"game_content","tumbler_index":"tumbler_index","home":"home","ungrouped_game":"ungrouped_game","promo_content":"promo_content","beta":"Betas","application":"Applications","extras":"Extras","unknown":"Unknown"},"strings":{"delimiter":"Enter delimiter:","stringify_error":"Error: Browser does not have JSON.stringify.","yes":"Yes","no":"No","search":"Search by game title","dlQueue":"Queue","dlList":"List","plus":"Toggle visibility of PS+ titles.","queue_all":"All","queue_to":"Download to $SYS$"},"apis":[{"internal_id":"api_entitle","name":"Entitlements","desc":"Cannot be disabled. Accesses purchase information used to create the download list, determine PS+ status, and other things."},{"internal_id":"api_game","name":"Catalog","desc":"Accesses additional game information to determine proper console, fix broken images, and more."},{"internal_id":"api_queue","name":"Download Queue","desc":"Allows adding and removing items from the download queue. Reads download queue information and the amount of activated consoles on the account."},{"internal_id":"api_pstv","name":"PS TV","desc":"Detect PS TV compatible titles. Only supported on \"en-us\" web store (not PSDLE language).","disabled":true}]} }, "es": { "def": "mx", "mx":{"local":"Español","startup":{"wait":"Esperando en la página se cargue."},"columns":{"icon":"Icono","name":"Nombre","platform":"Plataforma","size":"Tamaño","date":"Fecha"},"labels":{"export_view":"Exportar vista","page":"Paje"},"categories":{"downloadable_game":"Juegos","demo":"Población","avatar":"avatares","add_on":"Complementos","unlock":"Descubrir","theme":"Temas","application":"Aplicaciones","unknown":"Desconocido",},"strings":{"delimiter":"Ingrese delimitador:","stringify_error":"Error: Navegador no tiene JSON.stringify.","yes":"Sí","no":"No","search":"Búsqueda por título del juego"}} // Caaz, somebody. }, "de": { "def": "de", "de":{"local":"Deutsch","startup":{"wait":"Seite wird geladen, bitte warten."},"columns":{"icon":"Symbol","name":"Name","platform":"Plattform","size":"Größe","date":"Datum"},"labels":{"export_view":"Exportiere Ansicht","page":"Seite"},"categories":{"downloadable_game":"Spiele","demo":"Demos","add_on":"Erweiterungen","unlock":"Freischaltbares","avatar":"Spielerbilder","theme":"Themen","application":"Anwendungen","unknown":"Unbekannt",},"strings":{"delimiter":"Geben sie ein Trennzeichen ein","stringify_error":"Fehler: Browser fehlt \"JSON.stringify\".","yes":"Ja","no":"Nein","search":"Spiele titel eingeben für direkte suche"}} // Provided by /u/_MrBubbles }, "fr": { "def": "fr", "fr":{"local":"Français","startup":{"apis":"Sélectionner l'API à utiliser; Survoler pour plus de détails.
Certaines APIs ne peuvent pas être désactivées.","wait":"Merci de patienter.","start":"Commencer"},"columns":{"icon":"Icône","name":"Nom","platform":"Plate-forme","size":"Taille","date":"Date"},"labels":{"export_view":"Exporter la vue","page":"Page"},"categories":{"downloadable_game":"Jeux","demo":"Démos","add_on":"DLCs","unlock":"Codes de déverouillage","avatar":"Avatars","theme":"Thèmes","application":"Applications","unknown":"Inconnu"},"strings":{"delimiter":"Entrer le délimiteur:","stringify_error":"Erreur: votre navigateur ne supporte pas JSON.stringify.","yes":"Oui","no":"Non","search":"Rechercher par titre de jeu","dlQueue":"Queue","dlList":"Liste","plus":"Afficher/cacher les titres PS+.","queue_all":"Tous","queue_to":"Télécharger sur $SYS$"},"apis":[{"internal_id":"api_entitle","name":"Droits","desc":"Ne peut pas être désactivée. Accède aux informations d'achat afin de créer la liste de téléchargement, et déterminer le statut PS+, ainsi que d'autres choses."},{"internal_id":"api_game","name":"Catalogue","desc":"Accède aux informations supplémentaires des jeux pour déterminer la plate-forme, corriger les liens d'images cassés, et plus."},{"internal_id":"api_queue","name":"Liste de téléchargement","desc":"Permet d'ajouter ou de retirer des articles de la liste de téléchargement. Lit les informations de la liste de téléchargement et le nombre de consoles activées sur le compte."},{"internal_id":"api_pstv","name":"PS TV","desc":"Détecte les titres compatibles PS TV. Ne marche que sur le store \"en-us\" (différent de la langue choisie pour PSDLE).","disabled":true}]} // Provided by @cramoisan }, "ru": { "def":"ru", "ru":{"local":"Русский","startup":{"wait":"Ожидание загрузки страниц..."},"columns":{"icon":"Иконка","name":"Название","platform":"Платформа","size":"Размер","date":"Дата"},"labels":{"export_view":"Export View","page":"Страница"},"categories":{"downloadable_game":"Игры","demo":"Демо-версии","add_on":"Дополенния","unlock":"Разблокировки","avatar":"Аватары","theme":"Темы","application":"Приложения","unknown":"Неизвестно"},"strings":{"delimiter":"Введите разделитель:","stringify_error":"Ошибка: в браузере отсутствует JSON.stringify.","yes":"Да","no":"Нет","search":"Поиск по названию игры"}} //Provided by MorbertDou (issue #2) }, "ps": { "def": "ha", "ha":{"local":"H4ker","startup":{"apis":"import.APIs (hover: man)","wait":"...","start":"make"},"columns":{"icon":"1con","name":"H4ndle","platform":"P|a+f0rm","size":"S1z3","date":"D4t3"},"labels":{"export_view":"D0x","page":"P4g3"},"categories":{"downloadable_game":"W4rez","demo":"Freeware","add_on":"Add-0ns","unlock":"Cracks","avatar":"4va+ar","theme":"Themes","other":"other","beta":"Betas","application":"S0f+w4r3","unknown":"?"},"strings":{"delimiter":"5pli+ by:","yes":"Y","no":"N","search":"grep","queue_all":"wget all","queue_to":"wget $SYS$"}} //Caaz } }, determineLanguage: function(e,f) { e = (e) ? e.split("-") : this.config.language.split("-"); if (f === true) { this.lang = {}; this.lang = this.lang_cache.en.us; } if (e[0] in this.lang_cache) { if (e[1] in this.lang_cache[e[0]]) { if (f === true) { $.extend(true,this.lang,this.lang_cache[e[0]][e[1]]); this.sanitizeLanguage(); } e = e[0]+"-"+e[1]; } else { if (f === true) { $.extend(true,this.lang,this.lang_cache[e[0]][this.lang_cache[e[0]].def]); this.sanitizeLanguage(); } e = e[0]+"-"+this.lang_cache[e[0]].def; } } else { e = "en-us"; } return e; }, sanitizeLanguage: function() { //Send help. var a = JSON.stringify(this.lang, function(key, value) { if(typeof value === "string") { return value.replace(/'/g, "'"); } return value; }); this.lang = JSON.parse(a); }, generateLangBox: function(e) { var temp = ""; return temp; }, init: function() { console.log("PSDLE | Init."); var that = this; this.config = { logoBase64: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFQAAAAfCAYAAAEO89r4AAABaUlEQVRoge2XS27CQAyGPSVSUVErdqzpMqveiRvALnu67Gl6D+gFuAKIPgQrs0o1TJSJJ7aJBvnbRXE8f357XoCIGyTiEBFf33+BwgMpyg/eVRNSsENEpAQWMa27agL1e7JWcmCSVSG+tF6jp1D4o/qkqN8un+Bl7JpJUxP5vH38XT2T655CtEf6olKoaFLq3ElK2heRlgq//U/KKVj4rcrvs+Y+h7Z1ow2Vv9eg6A5p53MxhnI2an0vWSmW0HI2EhUTI5vSN4T2Xem0ycZRh4h7AJgOLaQLlf1ega2br3/IQlMW6TA2dYEPc2XToyZUGtbOdMs1lyX0lqeubEpvQqVp9GhsghxPOpvY8yPA1yo+MRtCh7iWfJ/j49rOpEE2QnM55h1U7/Wcox0nb+y9lqY6dzYtmgtmqDBmqDBmqDCDGcq5Ew5xCqViHSqMGSqMGSqMGSpMp6H3unloYR0qjBkqjBkqjBkqzAUtBKxj5lT3GAAAAABJRU5ErkJggg==", game_page: chihiro.getBaseUrl()+"#!/"+chihiro.getCultureCode()+"/cid=", game_api: SonyChi_SessionManagerSingleton.getBaseCatalogURL()+"/", lastsort: "", lastsort_r: false, language: chihiro.getCultureCode(), deep_search: false, deep_waiting: 0, deep_current: 0, last_search: "", dlQueue: { base: SonyChi_SessionManagerSingleton.getDLQueueBaseURL(), status: SonyChi_SessionManagerSingleton.getDLQueueStatusURL(), status2: SonyChi_SessionManagerSingleton.getDLQueueStatusURL2() }, use_queue: 0, active_consoles: {}, tag_line: "
Website - Repository - Submit Bug/Translation", switch_align: "center", switch_color: "#85C107", has_plus: false, check_tv: false, tv_url: atob("aHR0cHM6Ly9zdG9yZS5zb255ZW50ZXJ0YWlubWVudG5ldHdvcmsuY29tL3N0b3JlL2FwaS9jaGloaXJvLzAwXzA5XzAwMC9jb250YWluZXIvVVMvZW4vMTkvU1RPUkUtTVNGNzcwMDgtUFNUVlZJVEFHQU1FUz9zaXplPTMw") }; try { if (GM_info) this.config.tag_line += " - Userscript: "+GM_info.script.version+""; } catch (e) { }; this.determineLanguage(this.config.language,true); this.injectCSS(); SonyChi_SessionManagerSingleton.getUserDevices() $(document).on('change', "#sub_container > select#lang_select", function() { that.config.language = $(this).val(); that.determineLanguage($(this).val(),true); that.genDisplay(); }); this.genStartup(); }, genStartup: function() { if ($("#psdle_start").length == 0) { var that = this, startup = $("
",{id:"psdle_start"}).css({"z-index":"9001","width":"84px","height":"31px","position":"fixed","bottom":"10px","left":"10px","cursor":"pointer","box-shadow":"0px 0px 10px #FFF","background-image":"url('"+repod.psdle.config.logoBase64+"')"}).appendTo("body"); $(document).one("click","#psdle_start",function() { $(this).remove(); that.genDisplay(); }); } }, genDisplay:function(mode,fake_list) { var that = this; if (!$("#muh_games_container").length) { $("body").append("
"); } $(document).off("click",".psdle_btn"); $(document).off("click", "#inject_lang"); $(document).off("click", "#gen_fake"); $(document).off('click',"#psdle_go"); $("#muh_games_container").slideUp('slow', function() { var a = "
psdle"; if (mode == "progress") { if (that.config.use_queue) { var sys = {}, c = SonyChi_SessionManagerSingleton.getUserObject(); if (c.hasActiveVita()) { sys.vita = 1; } if (c.hasActivePS3()) { sys.ps3 = 1; } if (c.hasActivePS4()) { sys.ps4 = 1; } that.config.active_consoles = sys; } a += "
 

"+that.lang.startup.wait+""; } else { a += "

"+that.lang.startup.apis+"

"; $.each(that.lang.apis, function(key,con) { if (con.internal_id == "api_pstv") { a += (chihiro.getCultureCode() == "en-us")?""+con.name+"":""; } else { a += ""+con.name.replace(/'/g, "'")+""; } }); a += "

"+that.lang.startup.start+"
"+that.generateLangBox()+that.config.tag_line; a += "
Inject Language - Language Template - Generate Fake List"; a +="
"; $(document).on('click','[id^=api_]',function() { if ($(this).attr("id") !== "api_entitle") { $(this).toggleClass('toggled_off'); } }); $(document).on('click',"#inject_lang",function() { that.debug.inject_lang(); }); $(document).one('click',"#psdle_go, #gen_fake",function () { that.config.deep_search = !$("#api_game").hasClass("toggled_off"); that.config.use_queue = !$("#api_queue").hasClass("toggled_off"); that.config.check_tv = ($("#api_pstv").length) ? !$("#api_pstv").hasClass("toggled_off") : false; that.genDisplay("progress",($(this).attr("id") == "gen_fake")?true:false); }); } $("#muh_games_container").html(a).slideDown('slow',function() { if (mode == "progress") { if (fake_list) { that.debug.fake_list() } else { that.generateList(); } } else { $("[id^=api_]").promise().done(function() { $("[id^=api_]").tooltip({position: {my: "center top", at: "center bottom"}}) }); } }); }); }, generateList: function() { console.log("PSDLE | Generating download list."); var entitlements = gEntitlementManager.getAllEntitlements(), that = this; $.each(entitlements, function(index,obj) { if (that.isValidContent(obj)) { /* Determine if game content. */ var temp = {}; //Constants/pre-determined. temp.deep_type = "unknown"; temp.pid = obj.product_id; if (!that.pid_cache[temp.pid]) { that.pid_cache[temp.pid] = 1; } else { that.pid_cache[temp.pid]++; } temp.id = obj.id; if (obj.entitlement_attributes) { /* PS4 */ if (obj.game_meta) { temp.name = obj.game_meta.name; temp.api_icon = obj.game_meta.icon_url; //temp.id //temp.icon = obj.game_meta.icon_url; } temp.size = obj.entitlement_attributes[0].package_file_size; temp.platform = ["PS4"]; } else if (obj.drm_def) { /* PS3, PSP, or Vita */ temp.name = obj.drm_def.contentName; temp.api_icon = obj.drm_def.image_url; temp.size = obj.drm_def.drmContents[0].contentSize; temp.platform = []; $.each({"1":KamajiPlatformFlags.PS3,"3": KamajiPlatformFlags.PSP,"8":KamajiPlatformFlags.VITA}, function (t,u) { 0 !== (obj.drm_def.drmContents[0].platformIds >>> 1 & u >>> 1) && temp.platform.push(KamajiPlatforms[Number(t)]); }); } //Post-processing. temp.size_f = formatFileSizeDisplayStr(temp.size); temp.icon = SonyChi_SessionManagerSingleton.buildBaseImageURLForProductId(temp.pid)+"&w=31&h=31"; temp.api_icon = temp.api_icon+"&w=31&h=31"; temp.date = obj.active_date; temp.pdate = convertToNumericDateSlashes(convertStrToDateObj(temp.date)); temp.url = repod.psdle.config.game_page+temp.pid; temp.platform_og = temp.platform.slice(0); //Get Plus status if (!obj.drm_def && !!obj.inactive_date) { temp.plus = true; } //PS4, Vita, PSP if (obj.license && obj.license.expiration) { temp.plus = true; } //PS3 if (temp.plus) { repod.psdle.config.has_plus = true; } that.gamelist.push(temp); } }); this.gamelist.sort(function(a,b) { return (a.date > b.date)?-1:(a.date < b.date)?1:0 }); $.each(this.pid_cache, function(i,v) { if (v > 1) { that.game_api.queue("pid_cache",i) }}); $.each(this.gamelist,function(a,b) { that.gamelist[a].index = a+1; if (that.config.deep_search) { that.game_api.queue(a+1,((that.pid_cache[b.pid] > 1)?b.id:b.pid)); } }); console.log("PSDLE | Finished generating download list."); this.postList(); }, postList: function() { var safe = !0; if (repod.psdle.config.check_tv) { safe = !1; repod.psdle.tv.init(); } if (repod.psdle.config.deep_search) { safe = !1; this.game_api.run(); } if (safe) { this.table.gen(); } }, isValidContent: function(obj) { if (obj.VUData) { return !1; } else if (obj.drm_def && obj.drm_def.contentType == "TV") { return !1; } else if (obj.drm_def || obj.entitlement_attributes) { return !0; } else { return !1; } }, genSysCache: function() { var that = this; $.each(this.gamelist,function (i,v) { var name = that.safeGuessSystem(v.platform), key = name.toLowerCase().replace("ps ",""); that.sys_cache[key] = name; }); }, table: { bindSearch: function() { //Unbind for safety. $(document).off("click","#muh_table > tbody > tr, span[id^=system_], span[id^=filter_], span[id^=dl_], th[id^=sort_], #export_view, #export_csv").off("blur","#psdle_search_text"); //Bind. $(document).keypress(function(e) { if (e.which == 13 && $("#psdle_search_text").is(":focus")) { repod.psdle.table.regen(); } }); $("span[id^=system_], span[id^=filter_]").off("click").on("click", function() { $(this).toggleClass("toggled_off"); repod.psdle.table.regen(); }); $("th[id^=sort_]").off("click").on("click", function() { repod.psdle.sortGamelist($(this)); }); $("#export_view").off("click").on("click", function() { repod.psdle.exportTable.display(); }); $("#export_csv").off("click").on("click", function() { repod.psdle.exportTable.csv_handle(); }); $("#psdle_search_text").off("blur").on("blur", function() { repod.psdle.table.regen(); }); $("#dl_queue").one("click", function() { repod.psdle.dlQueue.generate.display(); }); $(document).off("click", "[id^=psdle_index_]").on("click", "[id^=psdle_index_]", function(e) { e.preventDefault(); repod.psdle.dlQueue.batch.add.ask(this); }); }, gen: function() { repod.psdle.genSysCache(); repod.psdle.config.lastsort = ""; repod.psdle.config.lastsort_r = false; var that = this; $("#muh_games_container").css({"position":"absolute"}); $("#sub_container").html(repod.psdle.genSearchOptions()).append("
"+repod.psdle.lang.columns.icon+""+repod.psdle.lang.columns.name+""+repod.psdle.lang.columns.platform+""+repod.psdle.lang.columns.size+""+repod.psdle.lang.columns.date+"

"+repod.psdle.config.tag_line); this.regen(); this.bindSearch(); console.log("PSDLE | Table generated."); repod.psdle.sortGamelist("#sort_date"); $("#muh_games_container").slideDown('slow').promise().done(function() { that.margin(); }); }, regen: function(a) { if (a !== true) { repod.psdle.determineGames(); } repod.psdle.autocomplete.bind(); var that = this, temp = "", plus = 0, count = 0; $.each(repod.psdle.gamelist_cur,function (a,val) { var valid = 1; switch (repod.psdle.config.switch_align) { case "left": if (val.plus) { valid = 0; } break; case "center": default: if (val.plus) { plus++; } break; case "right": if (!val.plus) { valid = 0; } else { plus++; } break; } if (valid) { count++; temp += repod.psdle.table_utils.gen.row(val); } }); temp += repod.psdle.table_utils.gen.totals(); var psswitch = (repod.psdle.config.has_plus) ? " (
"+plus+")" : ""; $("#table_stats").html(count+psswitch+" / "+repod.psdle.gamelist.length); if ($("#slider").length > 0) { $("#slider").tooltip().one("click",function() { that.plus_switch(); }); } if (chihiro.isMobile()) { $("#psdleplus").html(''); } else { $("#psdleplus").css($(".headerUserInfo.cart").css(["background-image","background-repeat"])).css({"height":"14px","width":"14px","background-position":"left -5px"}); } $("#muh_table > tbody").html(temp); this.icons.select(); }, plus_switch: function() { var a, b; switch ($(".handle_container").css("text-align")) { case "left": default: a = "center"; b = "#85C107"; break; case "center": a = "right"; b = "#2185f4"; break; case "right": a = "left"; b = "#F6573A"; break; } repod.psdle.config.switch_align = a; repod.psdle.config.switch_color = b; $("#slider").tooltip(); this.regen(); }, margin: function() { $("#muh_table").animate({"margin-top":$("#search_options").outerHeight() - $("#sub_container").css("padding-top").replace("px","")+"px"}); }, icons: { select: function(type) { type = (type) ? type : "smart"; var that = this; if (type == "smart") $(document).off("scroll").on("scroll",function() { that.smartScroll(); }); this.smartScroll(); if (type == "batch") this.batch(0,true); }, validate: function(source) { var that = this, index = source.split("_").pop(), temp = repod.psdle.gamelist[index], url = SonyChi_SessionManagerSingleton.buildBaseImageURLForProductId(temp.id)+"&w=31&h=31" if (!temp.safe_icon) { $.get(url) .success(function() { that.setIcon(index,url) }) .fail(function() { url = url.replace(temp.id,temp.pid); $.get(url) .success(function() { that.setIcon(index,url) }) .fail(function() { that.setIcon(index,temp.api_icon); }) }) } }, setIcon: function(index,url) { /* Hnnng. */ $("#psdle_index_"+index+" .psdle_game_icon").attr("src",url); $.extend(repod.psdle.gamelist[index],{safe_icon: true, icon: url}); }, smartScroll: function() { /* Get icons currently in view, and a few nearby. TO-DO: Probably slowly work through other icons when using this. */ var padding = 5, low = window.scrollY, high = low+window.innerHeight, that = this, t = $("[id^=psdle_index_]").filter(function(a) { var pos = $(this).offset().top; if (pos >= low && pos <= high) { return 1; } }).filter(":first, :last"), first = ($(t[0]).index()-padding <= 0) ? 0 : $(t[0]).index()-padding, last = $(t[1]).index()+padding; $("[id^=psdle_index_]").slice(first,last).not(".go_icon").each(function(a) { $(this).addClass("go_icon"); var b = this; setTimeout(function() { that.validate($(b).attr("id")); },a*50); }); }, batch: function(start,all) { start = (start) ? start : 0; var batch = (all) ? repod.psdle.gamelist.length : (chihiro.isMobile()) ? 50 : 24; if ($(".psdle_game_icon").filter(function() { return !$(this).attr("src"); }).length > 0) { this.runBatch(start,(start+batch)); } }, runBatch: function(start,end) { // Batches icon requests to avoid flooding the server at once. Batch size is determined in this.batch(). var that = this; $(".psdle_game_icon").slice(start,end).each(function(a) { var me = $(this).parent().parent().parent().attr("id"), index = me.split("_").pop(); setTimeout(function() { $.get(repod.psdle.gamelist[index].icon) .done(function() { if (a == end-start-1) { setTimeout(that.batch(end),200); } repod.psdle.gamelist[index].safe_icon = true; $("#"+me+" .psdle_game_icon").attr("src", repod.psdle.gamelist[index].icon); }) .fail(function() { if (a == end-start-1) { setTimeout(that.batch(end),200); } repod.psdle.gamelist[index].safe_icon = true; repod.psdle.gamelist[index].icon = repod.psdle.gamelist[index].api_icon; $("#"+me+" .psdle_game_icon").attr("src", repod.psdle.gamelist[index].icon); }); },(a*20)); }); } } }, determineGames: function() { this.exportTable.destroy(); this.gamelist_cur = []; this.autocomplete_cache = []; var that = this, temp = "", safesys = this.safeSystemCheck(); var search = (!!$("#psdle_search_text")) ? $("#psdle_search_text").val() : this.config.last_search; //$("[id^=filter_]").filter(function() { return !$(this).hasClass("toggled_off"); }) /* Determine filters. */ var filters = {}; $.each($("[id^=filter_]"), function() {var n = $(this).attr("id").split("_").splice(1).join("_");filters[n] = $(this).hasClass("toggled_off");}); $("#psdle_search_text").removeClass("negate_regex"); $.each(this.gamelist,function(index,val) { var sys = that.safeGuessSystem(val.platform), a = true, t = val.name; if ($.inArray(sys,safesys) > -1) { if (that.config.deep_search) { if (filters[val.deep_type]) { a = false; } } if (a == true && search !== "") { var regex = search.match(/^\/(.+?)\/([imgd]+)?$/i); a = (!!regex && !!regex[2] && regex[2].toLowerCase().indexOf("d") >= 0) ? true : false; if (a) { $("#3").addClass("negate_regex"); regex[2] = regex[2].replace("d",""); } if (!!regex) { if (RegExp((regex[1])?regex[1]:search,(regex[2])?regex[2]:"").test(t)) { a = !a; } } else if (t.toLowerCase().indexOf(search.toLowerCase()) >= 0) { a = !a; } } if (a == true) { that.gamelist_cur.push(val); that.autocomplete_cache.push({"label":t,"value":t}); } } }); that.config.last_search = search; }, genSearchOptions: function(dlQueue) { //TO-DO: Not this. Make scalable. var that = this; //Search options. var temp = '
'; if (!dlQueue) { temp += ''+this.lang.labels.export_view+'CSV '; } temp += ''; var order = ["ps1","ps2","ps3","ps4","psp","vita"], out = []; out[order.length +1] = ""; $.each(this.sys_cache, function(i,v) { if ($.inArray(i,order) >= 0) { out[$.inArray(i,order)] = ''+v+''; }}); temp += out.join("")+''; if (this.config.use_queue) { if (!dlQueue) { temp += ' '+this.lang.strings.dlQueue+''; } else { temp += ' '+this.lang.strings.dlList+''; } } temp += "
"; if (this.config.deep_search && !dlQueue) { temp += ''; var order = ["downloadable_game","demo","add_on","avatar","application","theme","unknown"], out = []; out[order.length +1] = ""; $.each(this.type_cache, function(key) { var line = ''+((that.lang.categories[key]) ? that.lang.categories[key] : key)+''; if ($.inArray(key,order) >= 0) { out[$.inArray(key,order)] = line} else { out.push(line); } }); temp += out.join("")+'
'; } if (!dlQueue) { temp += ""; } temp += "
"; temp += '
'; return temp; }, sortGamelist: function(sort_method) { this.determineGames(); var that = this; sort_method = $(sort_method).attr("id"); switch (sort_method) { default: case "sort_date": this.gamelist_cur.sort(function (a, b) { return (a.date > b.date)?-1:(a.date < b.date)?1:0 }); break; case "sort_name": this.gamelist_cur.sort(function (a, b) { return (a.name.toLocaleLowerCase() > b.name.toLocaleLowerCase())?1:(a.name.toLocaleLowerCase() < b.name.toLocaleLowerCase())?-1:0 }); break; case "sort_size": this.gamelist_cur.sort(function (a, b) { return (a.size > b.size)?1:(a.size < b.size)?-1:0 }); break; } if (sort_method == this.config.lastsort) { if (!this.config.lastsort_r) { this.gamelist_cur.reverse(); } this.config.lastsort_r = !this.config.lastsort_r; } else { this.config.lastsort_r = false; } $("#psdle_sort_display").remove(); $("#"+sort_method).append(""); this.config.lastsort = sort_method; this.table.regen(true); }, safeSystemCheck: function() { var temp = []; $("span[id^=system_]:not('.toggled_off')").each(function() { temp.push($(this).text()); }); return temp; }, safeGuessSystem: function(sys_in) { //Quick, dirty, and easy. Rewrite. var sys = (typeof(sys_in) == "object") ? sys_in.join(" ") : sys_in; sys = sys.replace(/[^\w\d ]/g,""); if (sys == "PS3 PSP PS Vita" || sys == "PS3 PSP" || sys == "PS Vita PSP" || sys.indexOf("PSP") > -1) { sys = "PSP"; } if (sys == "PS3 PS Vita" || sys.indexOf("PS Vita") > -1) { sys = "PS Vita"; } return sys; }, injectCSS: function() { var temp = /* Startup */ "#muh_games_container { display:none;position:fixed;top:0px;right:0px;left:0px;color:#000;z-index:9001;text-align:center } #sub_container { padding:20px;background-color:#fff; } #psdle_progressbar { overflow:hidden;display:inline-block;width:400px;height:16px;border:1px solid #999;margin:10px;border-radius:10px; } #psdle_bar { background-color:#2185f4;width:0%;height:100%;border-radius:10px; } .psdle_btn { cursor:pointer;border-radius:13px;background-color:#2185f4;color:#fff;padding:1px 15px;display:inline-block;margin:5px auto; } .psdle_tiny_link { line-height:0px;cursor:pointer;color:#7F6D75 !important; font-size:x-small; } .psdle_tiny_link:hover { color:#000 !important; text-decoration:underline; } " + /* Search options */ "#search_options { position:fixed;left:0px;top:0px;width:100%;padding:15px 0px;background-color:rgba(255,255,255,0.8);z-index:9001; }" + /* Table */ "th[id^=sort] { cursor:pointer; } table {} th {padding:5px;background-color:#2185F4;color:#fff;} tr:hover { background-color:rgba(33,133,244,0.7) !important; } td a.psdle_game_link {display:block;width:100%;height:100%;color:#000 !important;padding:8px;} .is_plus{background-color:#FFD10D;} tr:nth-child(2n) {background-color:#EEE;} th:nth-child(n+3):nth-child(-n+7), td:nth-child(n+3):nth-child(-n+7) {text-align:center;padding:0px 5px;position:relative;} td:first-child { text-align:center;position:relative; }" + /* Search buttons */ "#psdle_search_text { margin:5px auto;padding:5px 10px;font-size:large;max-width:600px;width:100%;border-style:solid;border-color:#F0F0F0;border-radius:90px; } .negate_regex { background-color:#FF8080;color:#fff; } span[id^=system_], span[id^=filter_], span#export_view, span[id^=dl_], .psdle_fancy_bar > span { font-weight:bold; text-transform:uppercase;font-size:small;color:#fff;background-color:#2185f4;display:inline-block;margin-right:2px;margin-bottom:5px;padding:1px 15px;cursor:pointer; } .psdle_fancy_but { border-radius:12px; } .psdle_fancy_bar > span:first-of-type { border-top-left-radius:12px; border-bottom-left-radius:12px; } .psdle_fancy_bar span:last-of-type { border-top-right-radius:12px; border-bottom-right-radius:12px; } .toggled_off { opacity:0.4; }" + /* Content icons */ ".psdle_game_icon { max-width:100%;vertical-align:middle;padding:3px;min-width:42px;min-height:42px; }" + /* Sorting */ ".psdle_sort_asc { float:right; width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-bottom:5px solid #fff; } .psdle_sort_desc { float:right; width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 5px solid #fff; }" + /* Newbox */ "#dlQueueAsk { box-shadow: 0px 0px 30px #000;display:inline-block;width:400px;height:400px;background-color:#FFF;border-radius:20px;overflow:hidden;position:relative;background-size:cover; } #dlQAN { cursor:move;background-color:rgba(33,133,244,0.8);padding:7px 15px;color:#fff;overflow:hidden;white-space:nowrap;text-overflow:ellipsis; } #dlQASys { position:absolute;bottom:0px;padding:7px 0px;color:#FFF;display:table;width:100%;table-layout:fixed; } #dlQASys > div { display:table-cell; } #dlQASys > div > div { cursor:pointer;background-color:rgba(33,133,244,0.8);border-radius:10px;padding:2px;margin:0px 10px; } #dlQAStat { color:#fff;background-color:rgba(33,133,244,0.8);border-bottom-left-radius:20px;padding:0px 10px 0px 15px;font-size:small;float:right; } #dlQARating { color:#fff;background-color:rgba(33,133,244,0.8);border-bottom-right-radius:20px;padding:0px 15px 0px 10px;font-size:small;float:left; } " + /* Newbox Container */ "#dlQueue_newbox { z-index:9001;position:fixed;top:0px;left:0px;width:100%;height:100%;display:table;background-color:rgba(0,0,0,0.25);background-size:cover;background-position:center; } #dlQueue_newbox > div { display:table-cell;vertical-align:middle;height:inherit;text-align:center; }" + /* Newbox Extended */ "#dlQueueExt { overflow: hidden; position: absolute; left: 10px; right: 10px; bottom: 40px; font-size: 0.8em; background-color: rgba(33, 133, 244, 0.8); padding: 10px; border-radius: 9px; top: 66px; text-align: left; }" + /* PS+ switch */ "#slider { vertical-align: bottom;display:inline-block;cursor:pointer;border-radius:100%;width:30px;height:12px;border-radius:10px;border:2px solid #F0F0F0; } .handle_container { text-align:center;width:100%;height:100%; } .handle { width:10px;height:10px;border-radius:100%;margin:0px 2px 6px;border:1px solid #FFF;display:inline-block;background-color:#85C107; }" + /* Tooltips */ ".tooltip-inner { background-color:#2185F4 !important; border: 5px solid #2185F4 !important; } .tooltip-arrow { border-top-color:#2185F4 !important; } .tooltip.in { opacity:1 !important; }" + /* Tooltips 2 */ ".ui-tooltip { background-color:#2185F4; max-width: 234px; z-index: 9002; background-color: #2185F4; font-size: 11px; text-align: center; line-height: 1.4em; padding: 12px; border-radius: 4px; }" + /* Autocomplete */ ".ui-autocomplete { z-index: 9002; max-width:590px; max-height:200px; overflow-y:auto; overflow-x:hidden; } .ui-menu { position:fixed; border:2px solid #F0F0F0; border-top: none; background-color:#fff; } .ui-menu > .ui-menu-item * { color:#000; text-decoration:none; white-space: nowrap; text-overflow: ellipsis; cursor:pointer; } .ui-menu > .ui-menu-item:nth-child(even) { background-color:#e6e6e6; } .ui-menu-item .ui-state-focus { display:inline-block; width:100%; color:#000; background-color: rgba(33, 133, 244, 0.7); }" + /* PS TV */ ".psdletv { font-style: italic;font-weight: bold;font-size: 0.6em;vertical-align: text-top;position: absolute;top: 4px; }"; $("head").append(""); }, exportTable: { display: function() { this.destroy(); var w = 600; $("#search_options").append(""); $("#sotextarea > textarea").css({"width":w,"max-width":w}).text(this.delimited(prompt(repod.psdle.lang.strings.delimiter," "))).select().parent().delay(500).slideDown(); repod.psdle.table.margin(); }, destroy: function() { $("#sotextarea").remove(); repod.psdle.table.margin(); }, json: function() { return (!!JSON.stringify) ? JSON.stringify(repod.psdle.gamelist_cur) : repod.psdle.lang.strings.stringify_error; }, delimited: function(e) { var that = this, sep = (e) ? e : " ", t = this.formatRow(sep); $(repod.psdle.gamelist_cur).each(function(i) { t += that.formatRow(sep,i); }); t += this.formatRow(sep,-1); return t; }, csv: function(sep) { var sep = (sep)?sep:",", csv = this.formatRow(sep), that = this; $.each(repod.psdle.gamelist_cur,function(i) { csv += that.formatRow(sep,i); }); csv += this.formatRow(sep,-1); return csv; }, csv_handle: function() { $("",{ "download":"psdle_"+(new Date().toISOString())+".csv", "href":"data:text/csv;charset=utf-8,"+encodeURIComponent(repod.psdle.exportTable.csv()) })[0].dispatchEvent(new MouseEvent("click")); }, formatRow: function(sep,index) { if (index >= 0) { var b = repod.psdle.gamelist_cur[index]; return b.name+sep+repod.psdle.safeGuessSystem(b.platform)+sep+b.size_f+sep+b.pdate+"\n"; } else if (index == -1) { return sep+sep+$("#psdle_totals").children().eq(3).text()+sep+"\n"; } else { return repod.psdle.lang.columns.name+sep+repod.psdle.lang.columns.platform+sep+repod.psdle.lang.columns.size+sep+repod.psdle.lang.columns.date+"\n"; } } }, game_api: { batch: [], queue: function(index,pid) { var that = this, a = {pid:pid,index:index}; /* Do some queue/delay magic here. */ if (index == "pid_cache") { this.batch.push(a) } else { this.batch.unshift(a); } }, run: function() { var that = this; if (this.batch.length > 0) { var a = this.batch.pop(); $.getJSON(repod.psdle.config.game_api+a.pid) .success(function(data) { that.process(a.index,data); }) .fail(function() { if (a.index !== "pid_cache") { if (repod.psdle.gamelist[a.index]) { var pid = repod.psdle.gamelist[a.index].pid; if (repod.psdle.pid_cache[pid] && pid !== a.pid) { var temp = $.extend({}, repod.psdle.pid_cache[pid]); $.extend(temp, repod.psdle.gamelist[a.index]); repod.psdle.gamelist[a.index] = temp; } else { repod.psdle.type_cache.unknown = true; } repod.psdle.type_cache.unknown = true; } } that.run(); }); } else { repod.psdle.table.gen(); } }, process: function(index,data) { var l = Math.abs(repod.psdle.gamelist.length - this.batch.length), r = repod.psdle.gamelist.length, w = $('#psdle_bar').width(), pW = $('#psdle_bar').parent().width(), p = Math.round(100*w/pW), q = Math.round(100*l/r); if (q > p) { $("#psdle_progressbar > #psdle_bar").stop().animate({"width":q+"%"}); } $("#psdle_status").text(l+" / "+r); this.parse(index,data); }, parse: function(index,data) { var extend = {}; if (index !== "pid_cache") { index--;} if (data.default_sku && data.default_sku.entitlements.length == 1) { var sys, type = "unknown", r = /^(PS(?:1|2)).+Classic$/i; if (data.metadata) { if (!!data.metadata.secondary_classification.values[0].match(r)) { sys = data.metadata.secondary_classification.values[0].match(r).pop(); } //else if (!!data.metadata.game_subtype.values[0].match(r)) { sys = data.metadata.game_subtype.values[0].match(r).pop(); } else if (!!data.metadata.primary_classification.values[0].match(r)) { sys = data.metadata.secondary_classification.values[0].match(r).pop(); } else if (!!data.metadata.playable_platform) { sys = []; $.each(data.metadata.playable_platform.values,function(i,val) { sys.push(val.replace(/[^\w\d ]/g,"")) }); } } if (index !== "pid_cache" && sys) { extend.platform = sys; } } if (data.top_category == "tumbler_index") { //We must go deeper. if (data.metadata.secondary_classification.values[0] == "ADD-ON") { type = "add_on"; } } else { type = (data.top_category) ? data.top_category : "unknown"; } extend.deep_type = type; if (data.star_rating && data.star_rating.score) { extend.rating = data.star_rating.score } if (data.promomedia && data.promomedia[0]) { extend.images = [], extend.videos = []; $.each(data.promomedia[0].materials, function(i,v) { if (v.urls && v.urls[0]) { var a = v.urls[0].url; if (/\.(png|jpg)$/ig.test(a)) { extend.images.push(a); } else if (/\.mp4$/ig.test(a.split("?")[0])) { extend.videos.push(a); } } }); } if (data.metadata) { extend.metadata = data.metadata; } if (data.long_desc) { extend.long_desc = data.long_desc; } repod.psdle.type_cache[type] = true; if (index == "pid_cache") { repod.psdle.pid_cache[data.id] = extend; } else { $.extend(repod.psdle.gamelist[index],extend); } this.run() } }, dlQueue: { batch: { cache: {}, get: function(prev_sys) { if (!prev_sys) { this.cache = {"ps3":[], "ps4":[], "vita":[]} } var that = this, base_url = repod.psdle.config.dlQueue.status+"/?status=notstarted&status=stopped&status=waitfordownload&platformString=$$1&size=100", consoles = []; for (var i in repod.psdle.config.active_consoles) { consoles.push(i) } var index = $.inArray(prev_sys,consoles) + 1, n = consoles[index]; if (n) { $.getJSON(base_url.replace("$$1",n)) .fail(function() { console.error("PSDLE | DL Queue parse error for \""+n+"\". Is it activated on the account?"); }) .success(function(data) { that.cache[n] = data.data.notifications; }) .complete(function() { that.get(n); }); } else { repod.psdle.dlQueue.generate.table(); } }, send: function(sys,id,cancel,completeCb,errorCb) { var dat = {"platformString":sys,"contentId":id}, base_url = (cancel) ? repod.psdle.config.dlQueue.status : repod.psdle.config.dlQueue.base; if (cancel) { dat.status = "usercancelled"; } $.ajax({ type:'POST', url: base_url, contentType: 'application/json; charset=utf-8', dataType: 'json', data: JSON.stringify([dat]), complete: completeCb, error: function(d) { alert("PSDLE | Download Queue | Error\n"+d.responseJSON.header.status_code+" - "+d.responseJSON.header.message_key+" ("+sys+" / "+id+")"); console.error("PSDLE | Download Queue | "+d.responseJSON.header.status_code+" "+d.responseJSON.header.message_key+" ("+sys+" / "+id+")"); errorCb(d); } }); }, add: { parse: function(index,sys) { var game = repod.psdle.gamelist[index], that = this; switch (sys) { case "ps4": case "ps3": case "vita": this.go(sys,game.id); break; case "all": var temp = game.platform_og.slice(0), i = $.inArray("PSP", temp); if(i != -1) { temp.splice(i, 1); } /* Make sure we don't have PSP */ $.each(temp,function(a,b) { that.go(b.replace(/ps /i,"").toLowerCase(),game.id); }); break; } }, ask: function(e) { //Ask which system to queue for. (cannot validate outside of this.go() response, if we care) //See notes for determining active consoles, probably the way to go. $("body").append(repod.psdle.newbox.generate(e)).promise().done(function() { repod.psdle.newbox.bind(); }); }, go: function(sys,id) { //Add game to batch. repod.psdle.dlQueue.batch.send(sys,id,false,function() { $("div[id^=dla_"+sys+"]").animate({"background-color":"green"}); },function(a) { $("div[id^=dla_"+sys+"]").stop().animate({"background-color":"red"}); }); }, }, remove: { parse: function(e) { repod.psdle.dlQueue.batch.remove.go($(e).children("td:eq(3)").text().replace("PS ","").toLowerCase(),repod.psdle.gamelist[Number($(e).attr("id").split("_").pop())].id); }, go: function(sys,id) { //Remove game from batch. repod.psdle.dlQueue.batch.send(sys,id,true,repod.psdle.dlQueue.batch.get()) } } }, generate: { bindings: function () { repod.psdle.newbox.bind("off"); //$(document).on("click","span[id^=system_], span[id^=filter_]", function() { $(this).toggleClass("toggled_off"); repod.psdle.table.regen(); }); //$(document).on("click","th[id^=sort_]", function() { repod.psdle.sortGamelist($(this)); }); $(document).one("click","#dl_list", function() { repod.psdle.table.gen(); }); $(document).off("click","[id^=psdle_index_]").on("click","[id^=psdle_index_]", function(e) { e.preventDefault(); repod.psdle.dlQueue.batch.remove.parse(this); }); }, table: function() { $("#muh_table").remove(); $("#sub_container").append("
"+repod.psdle.lang.columns.icon+""+repod.psdle.lang.columns.name+""+repod.psdle.lang.columns.platform+" > "+repod.psdle.lang.columns.size+""+repod.psdle.lang.columns.date+"
"); var temp = ""; $.each(repod.psdle.dlQueue.batch.cache, function(key,value) { if (value.length) { $.each(value, function(index,val) { $.each(repod.psdle.gamelist, function(a,b) { if (b.id == val.contentId) { var c = val; c.to_sys = key; temp += repod.psdle.table_utils.gen.row(b,c); } }); }); } }); $("#muh_table > tbody").html(temp); repod.psdle.table.margin(); }, display: function() { this.bindings(); $("#sub_container").html("").append(repod.psdle.genSearchOptions(true)); repod.psdle.dlQueue.batch.get(); }, destroy: function() { $("#sub_container").html(""); } } }, table_utils: { gen: { row: function(val,dlQueue) { var u = repod.psdle.config.game_page+val.id, pg = (chihiro.isMobile()) ? 50 : 24, icon = (val.safe_icon) ? val.icon : "", is_plus = (val.plus) ? "is_plus" : "", sys = repod.psdle.safeGuessSystem(val.platform), //style='background-image:url(\""+bg+"\")' bg = (val.images && val.images.length > 0) ? val.images[0] : "", temp = "
"+""+val.name+""; if (dlQueue) { temp += ""+sys+""+dlQueue.to_sys.toUpperCase().replace("VITA","PS Vita")+""+val.size_f+""+convertToNumericDateSlashes(convertStrToDateObj(dlQueue.createdTime))+"" } else { temp += ""+sys+((repod.psdle.config.check_tv && repod.psdle.id_cache[val.pid].tvcompat && sys == "PS Vita")?"TV":"")+""+val.size_f+""+val.pdate+""; } temp += ""; return temp; }, totals: function() { var a = 0; $.each(repod.psdle.gamelist_cur, function(b,c) { a += c.size; }); return ""+formatFileSizeDisplayStr(a)+""; } } }, newbox: { generate: function(e) { var plus = "", i = (isNaN(e)) ? Number($(e).attr("id").split("_").pop()) : Number(e), game = repod.psdle.gamelist[i], id = (game.index -1); var dialog = $("
"); try { if (game.plus) { plus = $("#psdleplus").clone()[0].outerHTML+" "; } } catch(e) {} dialog.append("
"+plus+game.name+"
"); if (repod.psdle.config.use_queue) { var t = "
"+repod.psdle.lang.strings.queue_all+"
"; var temp = game.platform_og.slice(0), i = $.inArray("PSP", temp); if(i != -1) { temp.splice(i, 1); } /* Make sure we don't have PSP */ if (temp.length > 1) { $.each(temp,function(a,b) { var c = b.replace(/ps /i,"").toLowerCase(), d = (repod.psdle.config.active_consoles.hasOwnProperty(c)) ? "" : "toggled_off"; t += "
"+b+"
"; }); } else { var c = temp[0].slice(0).replace(/ps /i,"").toLowerCase(), d = (repod.psdle.config.active_consoles.hasOwnProperty(c)) ? "" : "toggled_off"; t = "
"+repod.psdle.lang.strings.queue_to.replace("$SYS$",game.platform_og[0].slice(0))+"
"; } dialog.append("
"+t+"
"); } var star = ''; try { if (!isNaN(game.rating)) { dialog.append("
"+star+" "+game.rating+" / 5
"); } } catch (e) { } dialog.append("
"+repod.psdle.safeGuessSystem(game.platform)+" | "+game.size_f+" | "+game.pdate+"
"); dialog = $("
"+dialog[0].outerHTML+"
"); if (game.images && game.images.length > 0) { $(dialog).css("background-image","url('"+game.images[Math.floor(Math.random() * game.images.length)]+"')"); } /*else if (!chihiro.isMobile() && game.videos && game.videos.length > 0) { $(dialog).prepend('
'); }*/ return dialog[0].outerHTML; }, bind: function(e) { switch (e) { case "on": default: $("#dlQueueAsk").draggable({handle:"#dlQAN",containment:"parent"}); $("#dlQueue_newbox").one("click", function() { $(this).remove(); repod.psdle.newbox.bind("off"); }); $("#dlQueueAsk").on("click", function(event) { event.stopPropagation(); }); $("div[id^=dla_]:not('.toggled_off')").on("click", function() { repod.psdle.dlQueue.batch.add.parse($(this).attr("id").split("_")[2],$(this).attr("id").split("_")[1]); }); break; case "off": $("div[id^=dla_]").off("click"); $("#dlQueueAsk").off("click"); break; } } }, autocomplete: { bind: function() { if ($(".ui-autocomplete-input").length) { $("#psdle_search_text").autocomplete("close"); $('#psdle_search_text').autocomplete("option", { source: repod.psdle.autocomplete_cache }); } else { $("#psdle_search_text").autocomplete({ source:repod.psdle.autocomplete_cache, position: { my : "center top", at: "center bottom" }, messages: { noResults: '', results: function() {} }, select: function(e,u) { console.log(u); repod.psdle.config.last_search = u.item.value; repod.psdle.table.regen(true); } }) } } }, tv: { url_cache: [], init: function() { $.each(repod.psdle.gamelist, function(index,val) { repod.psdle.id_cache[val.pid] = {"tvcompat": false}; }); this.fetchList(); }, fetchList: function() { var that = this; $.getJSON(repod.psdle.config.tv_url,function(a) { $.each(a.links,function(c,b) { that.url_cache.push(b.url+"?size=30&start=0"); if (c = a.links.length) { that.run(); } }); }); }, run: function() { var that = this, url = this.url_cache.pop(); if (url) { $.getJSON(url) .success(function(a) { that.parse(url,a); }) .fail(function() { that.run(); }); } else { if (!repod.psdle.config.deep_search) { repod.psdle.table.gen(); } } }, parse: function(url,a) { var next = url.replace(/start=\d+/,"start="+(Number(url.match(/start=(\d+)/).pop()) + Number(url.match(/size=(\d+)/).pop()))) if (a.total_results && a.start + a.size < a.total_results) { this.url_cache.push(next); } $.each(a.links, function(index,val) { if (repod.psdle.id_cache[val.id]) { repod.psdle.id_cache[val.id].tvcompat = true; } }); this.run(); } }, debug: { die: function() { /* Obviously. */ $("#muh_games_container").remove(); /* CSS */ $("#psdle_css").remove(); /* Just 'psdle' */ delete repod.psdle; // Kappa }, inject_lang: function() { var lang = prompt("Insert JSON formatted language: (current below)",JSON.stringify(repod.psdle.lang)); try { lang = JSON.parse(lang); repod.psdle.lang = {}; repod.psdle.lang = repod.psdle.lang_cache.en.us; $.extend(true,repod.psdle.lang,lang); repod.psdle.genDisplay(); } catch (e) { alert(e); } }, fake_list: function() { //Generate a fake download list based on currently viewable items. //Dates are generated randomly. //Best used on a page showing only game content. if ($(".cellGridGameStandard").length > 0) { $.each($(".cellGridGameStandard"), function(index) { var temp = {}; temp.deep_type = "unknown"; temp.pid = $(this).find(".permalink").attr("href").split("cid=").pop(); temp.id = temp.pid; temp.index = repod.psdle.gamelist.length + 1; temp.name = $(this).find(".cellTitle").text(); temp.platform = [ $(this).find(".pforms").text().split("|").pop() ]; /* Random values */ temp.size = Math.floor(Math.random() * (20000000000 - 6000)); //Size, in bytes. temp.plus = (Math.random() < 0.5); if (temp.plus) { repod.psdle.config.has_plus = true; } //PS+ min = new Date(); min.setDate(min.getDate() - 365*4); min = min.getTime(); temp.date = new Date(min + Math.random() * (Date.now() - min)).toISOString(); //Date temp.icon = SonyChi_SessionManagerSingleton.buildBaseImageURLForProductId(temp.pid)+"&w=31&h=31"; temp.size_f = formatFileSizeDisplayStr(temp.size); temp.url = repod.psdle.config.game_page+temp.pid temp.platform_og = temp.platform.slice(0); temp.pdate = convertToNumericDateSlashes(convertStrToDateObj(temp.date)); repod.psdle.gamelist.push(temp); if (repod.psdle.config.deep_search) { repod.psdle.game_api.queue(temp.index,temp.pid); } }); repod.psdle.postList(); } else { alert("Not on a valid page."); } } } }; var a = setInterval(function(a){ if (chihiro.appReady === true) { clearInterval(repod.psdle.config.timerID); repod.psdle.init(); } },500); repod.psdle.config = {"timerID":a}; console.log("PSDLE | Ready.");