-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsteamdb-better-free-packages.sed
executable file
·34 lines (27 loc) · 1.65 KB
/
steamdb-better-free-packages.sed
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
#!/bin/sed -f
# First line makes it a function and runs it *now*
1d
# de-indent the 'let freePackages = '
0,/\t\+let/s/^\t\+//
# Define the function and set some variables after freePackages has been set
0,/^$/s//\0\nlet total_count = [ ...freePackages ].length;\nlet loaded_count = 0;\n\nsteamdb_function = function() {/
# Don't run the function immediately
$s/());$/;\n/
# Add to the loaded_count when removing pre-owned licenses
/\(\t\+\)\(freePackages.delete(.*)\);/s//\1if ( \2 ) {\n\1\tconsole.info("Already owned " + match[ 1 ]);\n\1\tloaded_count++\n\1}/
# Make a new variable for the truncated list
/^\t\+freePackages/,$s/freePackages/fiftyFreePackages/
s/fiftyFreePackages = /let \0/
# Add a sucess action when claiming licenses
/^\(\t\+\)\().always( requestNext );\)$/s//\1).done( function( data ) {\n\1\tconsole.info("Successfully claimed code " + fiftyFreePackages[ index ]);\n\1\tfreePackages.delete(fiftyFreePackages[ index ]);\n\1\tloaded_count++;\n\1}\2/
# Cleanup the progress display
/{loaded}/s/fiftyFreePackages.length/total_count/
/{loaded}/s/loaded/loaded_count/
/Reloading…/s|^\(\t\+\)'Reloading…',|\1'Waiting…',\n\1`Loaded <b>${loaded_count}</b>/${total_count}.`,|
# Print the time instead of reloading the page
s/location.reload()/console.info("Finished at "+Date())/
# Run the function now, and every hour
$a steamdb_function();
$a setInterval(steamdb_function, 1000*60*60);
# NOTE: Use this to add to the freePackages list without restarting the whole thing:
# xclip -o | sed -n -E '/^\s+[[:digit:]]+, \/\// {s/^\s+/freePackages.add(/;s/, \/\/.*$/);/;p} ; $a total_count = [...freePackages].length+loaded_count' | xclip -i -selection clipboard