-
-
Save nikop/214811ec3ad47d09dfd263c2ca81cf06 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Barter AppIDs fill | |
// @namespace Madjoki | |
// @include https://barter.vg/u/*/l* | |
// @include https://barter.vg/u/*/b* | |
// @include https://barter.vg/u/*/w* | |
// @version 8 | |
// @grant GM_xmlhttpRequest | |
// @require http://code.jquery.com/jquery-3.3.1.min.js | |
// @run-at document-start | |
// @updateURL https://gist.github.com/nikop/214811ec3ad47d09dfd263c2ca81cf06/raw/barter.user.js | |
// @downloadURL https://gist.github.com/nikop/214811ec3ad47d09dfd263c2ca81cf06/raw/barter.user.js | |
// ==/UserScript== | |
this.$ = this.jQuery = jQuery.noConflict(true); | |
const go = function () { | |
function getApps(callback) | |
{ | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url: "https://store.steampowered.com/dynamicstore/userdata/?t=" + (new Date().getTime()), | |
timeout: 5000, | |
onload: function(response) { | |
callback(JSON.parse(response.responseText)); | |
}, | |
}); | |
} | |
let form = $('ul.actions'); | |
let syncer = $('<div>'); | |
// Owned | |
if (window.location.pathname.indexOf('/l/') > -1) | |
{ | |
let btnAppID = $('<button>', {'text': 'Sync Apps with Userscript'}); | |
let btnAll = $('<button>', {'text': 'Sync Apps and Packages with Userscript'}); | |
syncer.append(btnAppID); | |
syncer.append(btnAll); | |
btnAppID.click(function () { | |
console.log("btnAppID clicked"); | |
btnAppID.attr('disabled', true); | |
stop(); | |
getApps(function (jsonFile) { | |
let appidsOwned = jsonFile.rgOwnedApps.join(","); | |
let form = $('<form>', { | |
'action': 'https://barter.vg/u/my/l/e/#modified', | |
'method': 'POST', | |
}); | |
form.append($('<input>', {'type': 'hidden', 'name': 'action', 'value': 'Edit'})); | |
form.append($('<input>', {'type': 'hidden', 'name': 'change_attempted', 'value': '1'})); | |
form.append($('<input>', {'type': 'hidden', 'name': 'add_from', 'value': 'AppIDs'})); | |
form.append($('<input>', {'type': 'hidden', 'name': 'bulk_IDs', 'value': appidsOwned})); | |
form.append($('<input>', {'type': 'hidden', 'name': 'userdata', 'value': 'on'})); | |
$('body').append(form); | |
form.submit(); | |
}); | |
}); | |
btnAll.click(function () { | |
console.log("btnAll clicked"); | |
btnAll.attr('disabled', true); | |
stop(); | |
getApps(function (jsonFile) { | |
let allOwned = "app/" + jsonFile.rgOwnedApps.join(",app/") + ",sub/" + jsonFile.rgOwnedPackages.join(",sub/"); | |
let form = $('<form>', { | |
'action': 'https://barter.vg/u/my/l/e/#modified', | |
'method': 'POST', | |
}); | |
form.append($('<input>', {'type': 'hidden', 'name': 'action', 'value': 'Edit'})); | |
form.append($('<input>', {'type': 'hidden', 'name': 'change_attempted', 'value': '1'})); | |
form.append($('<input>', {'type': 'hidden', 'name': 'add_from', 'value': 'IDs'})); | |
form.append($('<input>', {'type': 'hidden', 'name': 'bulk_IDs', 'value': allOwned})); | |
form.append($('<input>', {'type': 'hidden', 'name': 'userdata', 'value': 'on'})); | |
$('body').append(form); | |
form.submit(); | |
}); | |
}); | |
} | |
// Blacklist | |
if (window.location.pathname.indexOf('/b/') > -1) | |
{ | |
let btnAddIgnored = $('<button>', {'text': 'Add Ignored Apps'}); | |
syncer.append(btnAddIgnored); | |
btnAddIgnored.click(function () { | |
btnAddIgnored.attr('disabled', true); | |
stop(); | |
getApps(function (jsonFile) { | |
let appidsOwned = Object.keys(jsonFile.rgIgnoredApps).map(a => parseInt(a, 10)); | |
let form = $('<form>', { | |
'action': 'https://barter.vg/u/my/b/e/#modified', | |
'method': 'POST', | |
}); | |
form.append($('<input>', {'type': 'hidden', 'name': 'action', 'value': 'Edit'})); | |
form.append($('<input>', {'type': 'hidden', 'name': 'change_attempted', 'value': '1'})); | |
form.append($('<input>', {'type': 'hidden', 'name': 'add_from', 'value': 'AppIDs'})); | |
form.append($('<input>', {'type': 'hidden', 'name': 'bulk_IDs', 'value': appidsOwned})); | |
form.append($('<input>', {'type': 'hidden', 'name': 'userdata', 'value': 'on'})); | |
$('body').append(form); | |
form.submit(); | |
}); | |
}); | |
} | |
// Wishlist | |
if (window.location.pathname.indexOf('/w/') > -1) | |
{ | |
let btnAddWishlisted = $('<button>', {'text': 'Add Wishlisted Apps'}); | |
syncer.append(btnAddWishlisted); | |
btnAddWishlisted.click(function () { | |
btnAddWishlisted.attr('disabled', true); | |
stop(); | |
getApps(function (jsonFile) { | |
let appidsOwned = jsonFile.rgWishlist.join(","); | |
let form = $('<form>', { | |
'action': 'https://barter.vg/u/my/w/e/#modified', | |
'method': 'POST', | |
}); | |
form.append($('<input>', {'type': 'hidden', 'name': 'action', 'value': 'Edit'})); | |
form.append($('<input>', {'type': 'hidden', 'name': 'change_attempted', 'value': '1'})); | |
form.append($('<input>', {'type': 'hidden', 'name': 'add_from', 'value': 'AppIDs'})); | |
form.append($('<input>', {'type': 'hidden', 'name': 'bulk_IDs', 'value': appidsOwned})); | |
form.append($('<input>', {'type': 'hidden', 'name': 'userdata', 'value': 'on'})); | |
$('body').append(form); | |
form.submit(); | |
}); | |
}); | |
} | |
form.after(syncer); | |
}; | |
let varCounter = 0; | |
let intervalId = setInterval(function() { | |
if(varCounter <= 10) { | |
varCounter++; | |
if ($('ul.actions').length > 0) { | |
//console.log("waited times 50ms: " + varCounter); | |
clearInterval(intervalId); | |
go(); | |
} | |
} else { | |
clearInterval(intervalId); | |
} | |
}, 50); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment