取得出来る場合に限り、全製品でスクリーンショット/動画を表示、PS4の製品でサイズ情報/評価情報/関連製品のリンクを表示
当前为
// ==UserScript==
// @name PS Store fix
// @namespace http://tampermonkey.net/
// @version 0.5
// @description 取得出来る場合に限り、全製品でスクリーンショット/動画を表示、PS4の製品でサイズ情報/評価情報/関連製品のリンクを表示
// @author kood
// @match https://store.playstation.com/*
// @require http://code.jquery.com/jquery-latest.js
// @require https://greasyfork.org/scripts/2199-waitforkeyelements/code/waitForKeyElements.js?version=6349
// ==/UserScript==
$(function(){
/*
by TropicalSalad
https://www.resetera.com/threads/a-look-at-the-new-playstation-store-website.309355/page-13#post-49319173
*/
waitForKeyElements('div.pdp-background-image', addScreenshots);
function addScreenshots(jNode) {
var json = JSON.parse(jNode.find("script").html());
var medias = json['cache']['Product:'+json['args']['productId']]['media'];
var video = medias.filter(m => m.role === 'PREVIEW' && m.type === 'VIDEO');
if(medias)
addGameScreenshots(medias.filter(m => m.role === 'SCREENSHOT'), video);
}
function addGameScreenshots(medias, video) {
var screenshots = '';
medias.forEach(m => {
screenshots = screenshots + buildScreenshot(m);
});
if(video && video.length > 0)
screenshots = '<video controls style="width:100%"><source src="'+video[0].url+'"></video>' + screenshots;
$('.game-overview-container').append('<div style="width:100%">'+screenshots+'</div>');
}
function buildScreenshot(screenshot) {
return '<img style="flex: 1;width:50%; height:auto;" src="'+screenshot.url+'">';
}
/*
by kood
*/
waitForKeyElements("div.pdp-overview", addInfo);
var overview;
var prod_lc;
var chihiro_cl;
var chihiro_url;
function addInfo(){
(function(){
var def = $.Deferred();
getChihiroJson(def);
return def.promise();
}()).then(
function(data){
outInfo(data)
},function(){}
);
};
function getChihiroJson(def){
overview = $("div.pdp-overview").find(".psw-root" + ".psw-dark-theme").find(".psw-bg-0");
const url = location.href;
const tid_reg = /[a-zA-Z]{4}\d{5}/;
const cid_reg = /[a-zA-Z]{2}\d{4}-[a-zA-Z]{4}\d{5}_(\d{2}|[a-zA-Z]{2})-[a-zA-Z0-9]{16}/;
const cid = url.match(cid_reg)[0];
const tid = cid.match(tid_reg)[0];
if(overview.length==1 && tid.indexOf("CUSA")>-1){
const lc_reg = /\/[a-zA-Z]{2}-([a-zA-Z]{4}-)?[a-zA-Z]{2}\//;
prod_lc = url.match(lc_reg)[0];
prod_lc = prod_lc.replace(/\//g,"");
var lang = prod_lc.slice(0,prod_lc.match(/-[a-zA-Z]{2}$/)["index"]);
var country = prod_lc.match(/-[a-zA-Z]{2}$/)[0];
country = country.replace(/-/,"");
if(lang=="zh-hant"){
lang = "ch";
}else if(lang=="zh-hans"){
lang = "zh";
}
chihiro_cl = country + "/" + lang;
if(!chihiro_cl.match(/[a-zA-Z]{2}\/[a-zA-Z]{2}/)){
chihiro_cl = "us/en";
}
chihiro_url = "https://store.playstation.com/store/api/chihiro/00_09_000/container/";
chihiro_url = chihiro_url + chihiro_cl + "/999/" + cid;
chihiro_url += "?size=999";
getData(chihiro_url).then(
function(data){
def.resolve(data);
},function(){
def.reject();
}
);
}else{
def.reject();
}
}
function getData(ajax_url){
var def = $.Deferred();
$.ajax({
type: "GET",
dataType: "json",
url: ajax_url
}).done(function(data){
def.resolve(data);
}).fail(function(){
def.reject();
});
return def.promise();
}
function outInfo(data){
var elem_array = [];
// コンテンツのサイズを取得
var size_elem;
if(data.default_sku!=undefined){
const entitlements = data.default_sku.entitlements;
var size = 0;
try{
for(var i in entitlements){
if(entitlements[i].drms!=undefined && entitlements[i].drms.length>0){
size = size + entitlements[i].drms[0].size;
}
if(entitlements[i].packages!=undefined && entitlements[i].packages.length>0){
size = size + entitlements[i].packages[0].size;
}
}
}catch(e){}
if(size>0){
size = sizeCalc(size);
size_elem = "<div class='chihiro_size'>Size : " + size + "</div>";
elem_array.push(size_elem);
}
}
// 評価(星)の数を取得
const star = data.star_rating;
var total_elem, ave_elem, count_elem;
if(star.total!=null){
total_elem = "<div class='chihiro_star_total'>Star (Total) : " + star.total + "</div>"
elem_array.push(total_elem);
ave_elem = "<div class='chihiro_star_average'>Star (Average) : " + star.score + "</div>"
elem_array.push(ave_elem);
var count_array = [];
for(var x in star.count){
const star_n = 5 - x;
const star_c = 4 - x;
const count_str = "☆" + star_n + "(" + star.count[star_c].count + ")";
count_array.push(count_str)
}
if(count_array.length>0){
count_elem = "<div class='chihiro_star_count'>Star (Count) : " + count_array.join(", ") + "</div>"
elem_array.push(count_elem);
}
}
// 上で取得した情報の出力
if(elem_array.length>0){
overview.prepend(elem_array.join("") + "<br><br>");
}
// 関連製品のリンクと価格を出力
const links = data.links;
const relation_array = [];
$.each(links,function(i,item){
if(item.id!=undefined && item.id!=null && item.game_contentType!=undefined && item.game_contentType!=null
&& item.name!=undefined && item.name!=null && item.top_category!=undefined && item.top_category!=null){
var relation_url = "https://store.playstation.com/" + prod_lc + "/product/" + item.id;
if(item.top_category=="avatar" || item.top_category=="theme"){
// アバターとテーマの場合は旧ストアのリンクに
relation_url += "?smcid=psapp";
}
var relation_link = "<a href='"+ relation_url + "' target='_blank'>" + item.name + "</a>";
var price = "";
if(item.default_sku!=undefined){
price = item.default_sku.display_price;
relation_link += " (" + price + ")";
}
const relation_elem = "<li>" + relation_link + "</li>";
relation_array.push(relation_elem);
}
})
if(relation_array.length>0 && $(".game-overview-container").length==1){
const relation_elem = "<br><div class='chihiro_links'><ul>" + relation_array.join("") + "</ul></div>"
//$(".pdp-publisher-legal").append(relation_elem);
$(".game-overview-container").append(relation_elem);
$(".chihiro_links").find("a").css("color","green");
$(".chihiro_links").css("font-size","0.9rem");
$(".chihiro_links").find("a").css("font-size","0.9rem");
$(".ul_indent").css({"padding-left": "0", "margin-left": "1em"});
}
}
// バイト単位のサイズを変換 (旧ストアは1000バイト=1KBで計算しているのでここでは1000を設定)
function sizeCalc(size){
const unit_array = ["Byte","KB","MB","GB","TB"];
var unit_i = 0;
for(size; size>=1000; size=Math.floor((size/1000)*100)/100){
unit_i++;
}
return size.toString() + unit_array[unit_i];
}
});