// ==UserScript==
// @name Steam Game show in NGA
// @namespace https://greasyfork.org/zh-CN/scripts/16390-steam-game-show-in-nga
// @version 1.07
// @require http://cdn.bootcss.com/jquery/1.10.2/jquery.min.js
// @description 在 NGA论坛 发帖中显示 Steam 游戏信息 移植自 Steamcn.com 同名插件
// @author 原作者 Deparsoul @ steamcn ,由 Lyragosa 移植到NGA
// @include /^http://(bbs\.ngacn\.cc|nga\.178\.com|bbs\.nga\.cn)/(read\.php|thread\.php\?fid=414|nuke\.php\?func=steamsync)/
// @grant GM_xmlhttpRequest
// @license MIT License
// @downloadURL https://update.greasyfork.icu/scripts/16390/Steam%20Game%20show%20in%20NGA.user.js
// @updateURL https://update.greasyfork.icu/scripts/16390/Steam%20Game%20show%20in%20NGA.meta.js
// ==/UserScript==
console.log("Lyragosa Steam App Show in NGA load success");
if (location.href.indexOf('/nuke.php?func=steamsync')>0) {
//var unixTimestamp = new Date(Unix timestamp * 1000)
var commonTime = getTimeNow();
var ownnum = 0;
var wishnum = 0;
if (localStorage.getItem("own") != null) {
ownnum = eval(localStorage.getItem("own")).length;
}
if (localStorage.getItem("wish") != null) {
wishnum = eval(localStorage.getItem("wish")).length;
}
jQuery("body").append("
已经重新尝试同步 Steam 愿望单和已购物品信息 于 "+ commonTime + ",如果读取失败,请检查你的浏览器是否已经登录你的 Steam 帐号。
你已购物品(含DLC)共计 "+ ownnum +" 个,愿望单中物品共计 " + wishnum + " 个。
");
jQuery("body").append("此信息仅供在NGA直接显示链接颜色使用,已购物品将用绿色背景表示,愿望单中物品将用蓝色背景表示。
鼠标提示框中的信息需要在提示框中的同步区进行同步。
之所以需要两次同步,是因为此脚本并没有整合在NGA,而是由第三方制作。
如果你喜欢本插件,请向二哥提议在论坛内置此功能。");
sync();
console.log("sync success");
}
if (location.href.indexOf('/thread.php?fid=414')>0) {
//console.log(jQuery("#m_pbtntop div div").html());
jQuery("#m_pbtntop div div.right_ table tbody tr").prepend('同步我的 Steam 信息 | ');
}
/* SYNC END */
var currentScript = "0";
function setScriptVersion(a) {
currentScript = a;
jQuery("#noScript").hide();
jQuery("#withScript").show();
jQuery("#progress").show();
flag_desura = false;
flag_userdata = false;
flag_wish = true;
}
function checkLast() {
if (localStorage.last) {
jQuery("#reset").fadeIn();
jQuery("#lastTime").text(localStorage.last);
var c = JSON.parse(localStorage.own);
var e = JSON.parse(localStorage.wish);
jQuery("#lastOwn").text(c.length);
jQuery("#lastWish").text(e.length);
if (localStorage.sub) {
var d = JSON.parse(localStorage.sub);
jQuery("#lastSub").html(" | 订阅(SUB):" + d.length + "")
} else {
jQuery("#lastSub").html("")
}
if (localStorage.desura) {
var b = JSON.parse(localStorage.desura);
jQuery("#lastDesura").html(" | Desura:" + b.length + "")
} else {
jQuery("#lastDesura").html("")
}
var a = jQuery("#lastSync");
if (a.hasClass("alert-info")) {
a.removeClass("alert-info").addClass("alert-success")
} else {
a.addClass("alert-info")
}
if (localStorage.avatar) {
jQuery("#avatar img").attr("src", localStorage.avatar);
jQuery("#avatar a").attr("href", localStorage.profileurl);
jQuery("#avatar span").text(localStorage.personaname);
jQuery("#avatar").show()
} else {
jQuery("#avatar").hide()
}
a.fadeIn()
}
}
var flag_own = false;
var flag_wish = false;
var flag_userdata = true;
var flag_desura = true;
function checkFinish() {
if (flag_own && flag_wish && flag_desura && flag_userdata) {
localStorage.last = getTimeNow();
checkLast();
syncAnywhere();
//ga("send", "event", "sync", "finish");
//ga("set", "dimension2", "Finish Sync");
//ga("set", "metric1", 1)
}
}
function syncAnywhere() {
if (sa) {
if (localStorage.steamid != su) {
need_login()
} else {
var a = {id: localStorage.steamid, avatar: localStorage.avatar, personaname: localStorage.personaname, profileurl: localStorage.profileurl};
if (localStorage.own) {
a.own = JSON.parse(localStorage.own)
}
if (localStorage.wish) {
a.wish = JSON.parse(localStorage.wish)
}
if (localStorage.sub) {
a.sub = JSON.parse(localStorage.sub)
}
if (localStorage.desura) {
a.desura = JSON.parse(localStorage.desura)
}
jQuery("#sa").slideDown();
$.post("sync_anywhere", {d: JSON.stringify(a), csrf: csrf}).done(function (b) {
if (b != "1") {
jQuery("#sa_after strong").html(b)
}
jQuery("#sa_before").slideUp();
jQuery("#sa_after").slideDown()
})
}
}
}
function checkBrowser() {
var a = {explorer: {ie: /msie ([\d.]+).*\.net clr (\d\.){1,2}\d+\)$/, firefox: /firefox\/([\d.]+)/, chrome: /chrome\/([\d.]+)/, opera: /opera.([\d.]+)/, safari: /version\/([\d.]+).*safari/, se: /msie ([\d.]+).*\.net clr (\d\.){1,2}\d+; 360se\)$/, sougou: /msie ([\d.]+).*\.net clr (\d\.){1,2}\d+; .*metasr.*\d\)$/, maxthon: /maxthon\/([\d.]+)/}};
var c = navigator.userAgent.toLowerCase();
var b = null;
(b = c.match(a.explorer.ie)) ? a.ie = b[1] : (b = c.match(a.explorer.firefox)) ? a.firefox = b[1] : (b = c.match(a.explorer.chrome)) ? a.chrome = b[1] : (b = c.match(a.explorer.opera)) ? a.opera = b[1] : (b = c.match(a.explorer.safari)) ? a.safari = b[1] : (b = c.match(a.explorer.se)) ? a.se = b[1] : (b = c.match(a.explorer.sougou)) ? a.sougou = b[1] : (b = c.match(a.explorer.maxthon)) ? a.maxthon = b[1] : false;
if (a.firefox || a.chrome) {
return true
} else {
return false
}
}
function noScriptSync() {
jQuery("#noScriptSync").unbind("click").text("正在进行免脚本同步,请确认已将用户资料设为公开");
if (localStorage.steamid && localStorage.profileurl) {
jQuery("#progress").slideDown();
jQuery("#nav-desura").fadeIn();
var a = localStorage.steamid;
$.getJSON("syncProxy.php?type=own&id=" + a, function (d) {
if (d.response.game_count) {
var f = d.response.games;
var b = new Array();
for (var c = 0; c < f.length; ++c) {
b.push(parseInt(f[c].appid))
}
localStorage.own = JSON.stringify(b);
show_status("#own", b.length);
flag_own = true;
var e = localStorage.profileurl;
$.getJSON("syncProxy.php?type=wish&id=" + e, function (h) {
var j = new Array();
for (var g = 0; g < h.length; ++g) {
j.push(parseInt(h[g]))
}
localStorage.wish = JSON.stringify(j);
show_status("#wish", j.length);
flag_wish = true;
//ga("send", "event", "sync", "noScriptSync");
checkFinish()
})
} else {
need_public()
}
})
} else {
need_login()
}
}
function checkScript() {
if (jQuery("#noScript").is(":visible")) {
//ga("send", "event", "script", "not installed");
//ga("set", "dimension1", "No Script");
if (checkBrowser()) {
jQuery("#installScript").fadeIn()
}
jQuery("#noScriptSync").fadeIn();
if (localStorage.noScriptSync) {
noScriptSync()
} else {
jQuery("#noScriptSync").click(function () {
localStorage.noScriptSync = true;
noScriptSync();
return false
})
}
} else {
if (currentScript < latestScript) {
jQuery("#oldScript").show()
}
//ga("send", "event", "script", "installed");
//ga("set", "dimension1", "With Script");
localStorage.removeItem("noScriptSync")
}
}
function getTimeNow() {
return new Date().toLocaleString()
}
function show_status(b, a) {
if (b == "#own") {
//ga("set", "metric2", a)
} else {
if (b == "#wish") {
//ga("set", "metric3", a)
}
}
if (a >= 0) {
jQuery(b + "_after strong").text("成功读取并记录了 " + a + " 个条目")
} else {
if (a == -1) {
jQuery(b + "_after strong").text("读取失败,未登录 Steam")
} else {
if (a == -2) {
jQuery(b + "_after strong").text("读取失败,无法访问 Steam")
}
}
}
jQuery(b + "_before").slideUp();
jQuery(b + "_after").slideDown();
//ga("send", "event", "game stat", localStorage.steamid + "-" + localStorage.personaname + b, a)
}
function proc_own(d) {
var c = d;
var a = c.match(/var rgGames = (.*);/);
if (a) {
var b = c.match(/g_steamID = "(\d+)";/);
if (b) {
localStorage.steamid = b[1]
}
var b = c.match(/personaName = (".*");/);
if (b) {
localStorage.personaname = JSON.parse(b[1])
}
var b = c.match(/var profileLink = "(.*)";/);
if (b) {
localStorage.profileurl = b[1] + "/"
}
var b = c.match(/