Automatically syncs your steam profile with SteamGifts and removes entries for giveaways of owned games, on a custom interval and when marking your winning(s) as received.
当前为
// ==UserScript==
// @name SteamGifts - Clever Sync
// @version 1.6
// @description Automatically syncs your steam profile with SteamGifts and removes entries for giveaways of owned games, on a custom interval and when marking your winning(s) as received.
// @author Royalgamer06
// @include *steamgifts.com*
// @grant GM_xmlhttpRequest
// @grant GM_setValue
// @grant GM_getValue
// @namespace https://greasyfork.org/users/13642
// ==/UserScript==
//If you want to set your/another SteamID64 manually, state it here between brackets. (For example, to check owned games from someone else)
var manual_steamID = "";
//Set your steam sync interval in hours. (Set to 0 if you want to force a sync)
var sync_interval = 0;
//Enable (true) or disable (false) sync when marking winning(s) as received.
var syncOnReceived = true;
//Do not touch below :)
var steamID = "";
$(document).ready(function() {
if (manual_steamID.length == 17) {
steamID = manual_steamID;
syncHandler();
} else if (GM_getValue("cs_steamID") !== undefined) {
steamID = GM_getValue("cs_steamID");
syncHandler();
} else {
$.get($(".nav__avatar-outer-wrap").attr("href"), function(data) {
steamID = $(".sidebar__shortcut-inner-wrap a", data).attr("href").split("profiles/")[1];
if (steamID.length == 17) {
GM_setValue("cs_steamID", steamID);
syncHandler();
} else {
alert("[Clever Sync] ERROR: Could not fetch steamID automatically. Refresh the page to try again, or set manual steamID");
}
});
}
});
function syncHandler() {
var now = new Date().valueOf();
var last = GM_getValue("cs_lastsync");
if (last === undefined) {
GM_setValue("cs_lastsync", now);
syncHandler();
} else if (location.href.indexOf("/giveaways/won") > -1 && syncOnReceived) {
$(".table__gift-feedback-received").on("click", doSync);
} else if ((now - last) / 3600000 > sync_interval) {
doSync();
}
}
function doSync() {
if ($("[name=xsrf_token]").length > 0) {
var data = "xsrf_token=" + $("[name=xsrf_token]").val() + "&do=sync";
$.ajax({
url: "/ajax.php",
type: "POST",
dataType: "json",
data: data,
success: function() {
GM_xmlhttpRequest({
method: "GET",
url: "http://steamcommunity.com/profiles/" + steamID + "/games/?xml=1",
onload: function(gdata) {
var xml = $.parseXML(gdata.responseText);
var ownedGames = [];
$("appid", xml).each(function() {
ownedSteamGames.push($(this).text());
});
var p = 1;
$.ajax({
url : "/giveaways/entered/search?page=" + p,
type : "GET",
success: function(data) {
var entered = $(".table__column__secondary-link");
$(entered).each(function() {
var appid = $(this).parent().parent().parent().parent().parent().find(".global__image-inner-wrap").css("background-image").split("/")[5];
if ($.inArray(appid, ownedGames) > -1) {
var fdata = $(this).parent().parent().parent().serialize();
$.ajax({
url: "/ajax.php",
type: "POST",
dataType: "json",
data: fdata
});
}
});
if (entered.length == 50) {
p++;
this.url = "/giveaways/entered/search?page=" + p;
$.ajax(this);
} else {
GM_setValue("cs_lastsync", new Date().valueOf());
console.log("[Clever Sync] Done!");
}
}
});
}
});
}
});
}
}