-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgamedeals-table-highlighter.user.js
86 lines (70 loc) · 2.37 KB
/
gamedeals-table-highlighter.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// ==UserScript==
// @name GameDeals table highlighter
// @namespace mikemanger
// @grant GM_xmlhttpRequest
// @include https://www.reddit.com/r/GameDeals/comments/*
// @require https://code.jquery.com/jquery-3.3.1.slim.min.js
// @updateURL https://raw.githubusercontent.com/mikemanger/userscripts/master/gamedeals-table-highlighter.user.js
// @downloadURL https://raw.githubusercontent.com/mikemanger/userscripts/master/gamedeals-table-highlighter.user.js
// @version 1.3.0
// @run-at document.idle
// ==/UserScript==
this.$ = this.jQuery = jQuery.noConflict(true);
var users = [
'.author.id-t2_bukfv', // /u/dEnissay
'.author.id-t2_b1jfp', // /u/Ignarius
'.author.id-t2_dau7q', // /u/NCPereira
'.author.id-t2_hxn27', // /u/granitosaurus
'.author.id-t2_in61j', // /u/ABOOD-THE-PLAYER
'.author.id-t2_qfmsqom', // /u/lillje
'.author.id-t2_1pry1', // /u/pantsu
'.author.id-t2_2uod1', // /u/Custard
'.author.id-t2_4rd82', // /u/incontrollable
'.author.id-t2_7e6j6', // /u/alms_
];
$( users.join(',') ).each( function() {
var table = $( this ).parent().parent().find( '.usertext-body table' );
table.after( '<button class="gdth-get-status">Get Steam status</button>' );
});
$(document).ready(function(){
main();
});
async function main() {
var user_apps = await get_steam_apps();
$( '.sitetable' ).on( 'click', 'button.gdth-get-status', function( event ) {
event.preventDefault();
var table_rows = $( this ).siblings( 'table' ).find( 'tbody tr' );
table_rows.each( function() {
var tr = $(this),
app_url = tr.html().match( /http(s)?:\/\/store\.steampowered\.com\/app\/(\d*)\//i );
// Skip if no steam URL found
if ( app_url === null ) {
return 'continue';
}
var app_id = parseInt( app_url[2] );
var in_library = user_apps.rgOwnedApps.indexOf( app_id ) > -1;
if ( in_library ) {
tr.css( 'background', 'lightgreen' );
} else {
var in_wishlist = user_apps.rgWishlist.indexOf( app_id ) > -1;
if ( in_wishlist ) {
tr.css( 'background', '#5DADE2' );
} else {
tr.css( 'background', '' );
}
}
});
});
}
function get_steam_apps() {
return new Promise(resolve => {
GM_xmlhttpRequest({
method: 'GET',
url: 'https://store.steampowered.com/dynamicstore/userdata/',
responseType: 'json',
onload: function(response) {
resolve( JSON.parse( response.responseText ) );
}
});
});
}