Greasy Fork is available in English.
在 NGA论坛 发帖中显示 Steam 游戏信息
当前为
// ==UserScript==
// @name Steam Game show in NGA
// @namespace https://www.lyragosa.com/
// @version 1.0
// @description 在 NGA论坛 发帖中显示 Steam 游戏信息
// 由于二哥不整合脚本 需要在steamcn点一次同步之后再到NGA再点一次
// @author 原作者 Deparsoul @ steamcn ,由 Lyragosa 移植到NGA
// @match http://bbs.ngacn.cc/*
// @grant none
// ==/UserScript==
var script=document.createElement("script");
script.type="text/javascript";
script.src="http://code.jquery.com/jquery.js";
document.getElementsByTagName('head')[0].appendChild(script);
var __NGA_STEAM_INFO = setInterval(function(){
if (jQuery) {
(function (c) {
var o = 300;
var f = 1;
var e = ("ontouchstart" in window) || window.DocumentTouch && document instanceof DocumentTouch;
if (e) {
console.log("This is a device with touch support.")
}
function a(w) {
var v = jQuery(w);
var u = v.prev();
u.removeClass("touched");
v.stop().clearQueue().fadeOut(o)
}
function t(v) {
var w = v.height();
var D = v.prev();
var E = D.position().left + D.outerWidth();
var C = D.position().top - 5;
var z = D.offsetParent().offset();
var B = jQuery(window).scrollLeft() + jQuery(window).width() - z.left;
var A = jQuery(window).scrollTop() - z.top;
var u = A + jQuery(window).height();
if (B - E < 320) {
E = B - 320;
C = D.position().top + D.outerHeight()
}
if (u - C < w) {
C = u - w
}
C = C < A + 16 ? A + 16 : C;
v.css("left", E).css("top", C)
}
function m(w) {
var u = null;
var x;
if (x = w.match(/\/store\.steampowered\.com\/((sub|app)\/\d+)/)) {
u = x[1]
} else {
if (x = w.match(/\/steamcommunity\.com\/((sub|app)\/\d+)/)) {
u = x[1]
}
}
if (!u) {
var z = null;
if (x = w.match(/\/www\.steamgifts\.com\/giveaway\/\w{5}\/([a-z0-9-]+)/)) {
z = x[1]
} else {
if (x = w.match(/www\.gamersgate\.(?:com|co\.uk)\/[A-Z0-9-]+\/([a-z0-9-]+?)(-([2-4]|two|three|four)-pack-bundle)?(\/|$)/)) {
z = x[1]
} else {
if (x = w.match(/www\.greenmangaming\.com\/.*\/games\/.+?\/([a-z0-9-]+?)(-([2-4]|two|three|four)-pack)?(\/|$)/)) {
z = x[1]
} else {
if (x = w.match(/getgamesgo\.com\/product\/([a-z0-9-]+?)(-steam|-mac|-mac-steam)?(\/|$)/)) {
z = x[1]
} else {
if (x = w.match(/www\.macgamestore\.com\/product\/\d+\/([\-\w]+?)(\/|$)/)) {
z = x[1]
} else {
if (x = w.match(/www\.game\.co\.uk\/\w+\/([\-\w]+?)-\d+(\/|$)/)) {
z = x[1]
} else {
if (x = w.match(/store.indiegala.com\/.*\/([a-z0-9-]+?)(-([2-4]|two|three|four)-pack-bundle)?\.html/)) {
z = x[1]
}
}
}
}
}
}
}
if (z) {
u = "guess/" + z
}
}
if (!u) {
var v = /(www\.amazon\.com)\/(gp\/product|dp)\/([A-Z0-9]+)/;
var x = v.exec(w);
if (x != null) {
var y = x[1];
var A = x[3];
u = "amazon/" + y + "/dp/" + A
}
}
if (!u) {
var x = w.match(/(store\.sonkwo\.com\/node|www\.sonkwo\.com\/products)\/(\d+)/);
if (x != null) {
var A = x[2];
u = "sonkwo/" + A
}
}
return u
}
var i = 0;
function r(x) {
var B = jQuery(x);
if (B.data("_infoAdded")) {
return false
}
B.data("_infoAdded", true);
var v = B[0].href;
var E = m(v);
if (!E) {
return false
}
var z = false;
var C = E;
var D = "";
var u;
if (B.next().hasClass("steamInfoWrapper")) {
D = B.next().attr("id")
} else {
++i;
D = "steam_info_" + C.replace(/[\/.]/g, "_") + "_" + i;
u = jQuery('<div style="display:none" class="steamInfoWrapper"><div class="png_loading"></div><iframe frameBorder="0" allowtransparency="true">Loading</iframe></div>');
u.attr("id", D);
u.find("iframe").attr("src", c + "/tooltip#" + C + "#" + D);
B.after(u);
z = true
}
var A = "#" + D;
u = jQuery(A);
var w = null;
function y() {
jQuery(".steamInfoWrapper:not(" + A + ")").stop().clearQueue().hide().css("opacity", "1");
clearTimeout(w);
u.find("iframe")[0].contentWindow.postMessage("show", "*");
t(u);
u.fadeIn(o)
}
B.bind("mousemove", function () {
y()
});
B.bind("click", function () {
if (e) {
if (B.hasClass("touched")) {
return true
} else {
jQuery("a.touched").removeClass("touched");
B.addClass("touched");
return false
}
}
return true
});
B.mouseout(function () {
w = setTimeout(function () {
a(A)
}, 500)
});
u.hover(function () {
if (w) {
clearTimeout(w);
w = null
} else {
w = setTimeout(function () {
a(A)
}, 500)
}
});
return z
}
var l = 0;
function h() {
if (jQuery("#steamInfoGetOwnAndWish").length == 0) {
jQuery('<iframe style="display:none" id="steamInfoGetOwnAndWish" src="' + c + '/tooltip" />').appendTo("body")
}
}
var p = [];
var q = [];
var k = [];
var b = [];
p = eval(localStorage.getItem("own"))
q = eval(localStorage.getItem("wish"))
function s() {
jQuery("a").each(function () {
var x = jQuery(this);
var u = String(x.attr("href"));
var v;
if (v = u.match(/\/(store\.steampowered|steamcommunity)\.com\/(app|sub)\/(\d+)/)) {
//console.log(x);
//console.log(u);
var w = v[2];
//console.log(localStorage.valueOf())
// console.log(p)
var y = parseInt(v[3]);
if (w == "app") {
if (p.indexOf(y) !== -1) {
x.addClass("linkOwn")
} else {
if (q.indexOf(y) !== -1) {
x.addClass("linkWish")
}
}
} else {
if (w == "sub") {
if (k.indexOf(y) !== -1) {
x.addClass("linkOwn")
}
}
}
}
if (x.data("_hoverAdded")) {
return
}
x.data("_hoverAdded", true);
if (!m(u)) {
return
}
x.hover(function () {
r(this);
if (!x.hasClass("loaded")) {
n(f, x)
}
x.addClass("loaded")
})
});
l += 1000;
setTimeout(function () {
s()
}, l)
}
var d = 0;
function j(w) {
var v = jQuery(w);
if (v.data("_preChecked")) {
return
}
v.data("_preChecked", true);
var u = String(v.attr("href"));
if (!m(u)) {
return
}
if (r(w)) {
--d
}
}
function n(w, x) {
d = w;
var u = jQuery("a");
if (x) {
x = u.index(x);
for (var v = x; v < u.length; ++v) {
j(u[v]);
if (d <= 0) {
return false
}
}
}
u.each(function () {
j(this);
if (d <= 0) {
return false
}
})
}
jQuery("head").prepend('<link rel="stylesheet" href="' + c + '/assets/css/steam_info.css" type="text/css" />');
jQuery(function () {
s();
n(f);
if (d > 0) {
h()
}
});
function g(w) {
if (w.data.sub) {
k = JSON.parse(w.data.sub)
} else {
if (w.data.own || w.data.wish) {
p = JSON.parse(w.data.own);
q = JSON.parse(w.data.wish);
jQuery(".steam_info_trigger_text").each(function () {
var A = jQuery(this);
var y = String(A.data("href"));
var z;
if (z = y.match(/\/(store\.steampowered|steamcommunity)\.com\/app\/(\d+)/)) {
var B = parseInt(z[2]);
if (p.indexOf(B) !== -1) {
A.addClass("steam_info_own")
} else {
if (q.indexOf(B) !== -1) {
A.addClass("steam_info_wish")
}
}
}
})
} else {
if (w.data.desura) {
b = JSON.parse(w.data.desura);
jQuery('a[href^="http://www.desura.com/games/"]').each(function () {
var B = jQuery(this);
B.addClass("linkDesura");
var y = String(B.attr("href"));
var A;
if (A = y.match(/\/\/www\.desura\.com(\/[^\/]*\/[^\/#?]*)/)) {
var z = A[1];
z = z.toLowerCase();
if (b.indexOf(z) !== -1) {
B.addClass("linkOwn")
}
}
})
} else {
var u = w.data.height;
var x = w.data.src;
var v = jQuery('iframe[src="' + x + '"]').closest("div");
v.height(u + 1);
t(v)
}
}
}
}
window.addEventListener("message", g, false)
})("http://steamdb.sinaapp.com");
window.clearInterval(__NGA_STEAM_INFO);
}
},1000);
//Script Injection
function exec(fn) {
var script = document.createElement('script');
script.setAttribute("type", "application/javascript");
script.textContent = fn;
document.body.appendChild(script);
document.body.removeChild(script);
}
//Load url and call proc function
function load(url, id){
GM_xmlhttpRequest({
method: "GET",
url: url,
onload: function(response) {
exec('proc_'+id+'("'+addslashes(response.responseText)+'")');
}
});
}
function sync() {
load('http://steamcommunity.com/my/games?tab=all', 'own');
load('http://store.steampowered.com/dynamicstore/userdata/?'+nocache, 'userdata');
}
//Add slashes to string
function addslashes(string) {
return string.replace(/\\/g, '\\\\').
replace(/\u0008/g, '\\b').
replace(/\t/g, '\\t').
replace(/\n/g, '\\n').
replace(/\f/g, '\\f').
replace(/\r/g, '\\r').
replace(/'/g, '\\\'').
replace(/"/g, '\\"');
}
console.log("Lyragosa Steam App Show in NGA load success")