-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHLTB_DefaultValuePicker.user.js
223 lines (204 loc) · 10.1 KB
/
HLTB_DefaultValuePicker.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
// ==UserScript==
// @name HLTB DefaultValuePicker
// @version 0.5
// @description Picks some values while submitting time by default - check lines 20-25 in script.
// @author beridok
// @namespace [email protected]
// @include https://howlongtobeat.com/*
// @downloadURL https://github.com/Beridok/UserScript_Collection/raw/main/HLTB_DefaultValuePicker.user.js
// @updateURL https://github.com/Beridok/UserScript_Collection/raw/main/HLTB_DefaultValuePicker.user.js
// @run-at document-end
// @grant none
// @noframes
// ==/UserScript==
/* globals $ */
(function(){
"use strict";
var config = {
platform : "PC", //Write default platform with exact Uppercase.
field : "Completed", //Retired/Custom1/Custom2/Custom3/Playing/Backlog/Replays
storefront : "Steam", //Name your default Storefront
firstPlaythrough : true, //true/false/null => define if it should choose "Yes, first playthrough". Inputting 'false' will give "No, this is replay". Inputting 'none' will do nothing.
delayFactor : 1, //Delay factor - increase this, if default options does not seem to load, due to slower connection to site.
};
console.info && console.info('%c «%s» %c—— %c %s ',
'background:#000000; color:#7ebe45', GM_info.script.name,
'background:#000000; color:dimgray',
'background:#3c424d; color:#ffffff', GM_info.script.version);
var gameID = window.location.search.substring(4);
//Reason behind this approach is to simply change Div selectors, in case of something going wrong...
var quickAddDivPlatform = '#quick_add_plat_'+gameID;
var quickAddDivStorefront = '#quick_add_store_'+gameID;
var submitDivPlatform = "fieldset.in:nth-child(5) > div:nth-child(1) > select:nth-child(2)";
var submitDivStorefront = "fieldset.in:nth-child(5) > div:nth-child(2) > select:nth-child(2)";
if ( config.delayFactor <= 0 ) { config.delayFactor = 1; }
//Zabezpieczenie gdyby ktoś wpisał zero do konfiguracji. Potrzebne jest jakieś opóźnienie
//Security in case of someone entering 0 as value... we need some delay factor
//On game subpage, change value of quickadd buttons, according to defaults in script's config...
if ( window.location.pathname === "/game" )
{
setTimeout(() => {
//document.querySelector(quickAddDivPlatform).textContent = dc.platform;
document.querySelector(quickAddDivPlatform).value = config.platform;
document.querySelector(quickAddDivStorefront).value = config.storefront;
}, 100*config.delayFactor );
}
//During submission of playthrough...
if ( window.location.pathname === "/submit" ) {
setTimeout(() => {
//Depending on default value, click one of the checkboxes...
//Minor bug: Does not check if already checkbox is check - therefore resulting in unchecking during edit of HLTB submission
switch ( config.field ) {
case "Completed":
//Website behavior changed, so now it requires check if user clicked "Complete" on game's page
//One way is reading parameter from URL - other would be to read state of checkbox...
if ( window.location.search.indexOf('list_cp=1') === -1 ) {
document.querySelector('#list_cp').click();
}
break;
case "Retired":
document.querySelector('#list_rt').click();
break;
case "Custom1":
document.querySelector('#list_c').click();
break;
case "Custom2":
document.querySelector('#list_c2').click();
break;
case "Custom3":
document.querySelector('#list_c3').click();
break;
case "Playing":
document.querySelector('#list_p').click();
break;
case "Backlog":
document.querySelector('#list_b').click();
break;
case "Replays":
document.querySelector('#list_r').click();
break;
default:
console.log('You entered wrong "Add to List" field. Check line 20 in UserScript - uppercase and if there is no typographic error');
break;
}
//Select new values... but only if values are not existing in the URL
var urlParameterPlatform = window.location.search.split('platform=')[1].split('&store=')[0];
var urlParameterStorefront = window.location.search.split('&store=')[1];
if ( urlParameterPlatform === "" ) {
document.querySelector(submitDivPlatform).value = config.platform;
}
if ( urlParameterStorefront === "" ) {
document.querySelector(submitDivStorefront).value = config.storefront;
}
//Click "Steam icon" to pull current progress (time spent in the game so far);
if ( document.querySelector("fieldset.in:nth-child(8) > div:nth-child(1) > div:nth-child(1) > img:nth-child(1)") !== null )
{
document.querySelector("fieldset.in:nth-child(8) > div:nth-child(1) > div:nth-child(1) > img:nth-child(1)").click();
}
//Select by default that it was first playthrough...
var firstPlaythrough;
if ( config.firstPlaythrough === true ) { firstPlaythrough = 1; }
else if ( config.firstPlaythrough === false ) { firstPlaythrough = 2; }
else if ( config.firstPlaythrough === null ) { firstPlaythrough = 0; }
else { console.log('You entered wrong "First Playthrough" value. Check line 22 in UserScript. It can only be: true, false or null.'); }
document.querySelector('#play_num').value = firstPlaythrough;
}, 100*config.delayFactor );
}
//CODES below are saved for my own organizing purpose - to find them more easily in future needs...
//They are too complex for regular use case by "end user"
//---------------------------------------------------------------------
//Code for subpage: https://howlongtobeat.com/steam
//Default rules of importing Steam games - e.g. including "VR" would sign to my custom HLTB category named "VR". Similarly for "MMO" and "Multiplayer".
/*
var startTime = Date.now()
var limit = $('.steam_table > tbody:nth-child(2)').rows.length;
for ( let i = 1; i <= limit; i++)
{
var refDiv1 = $('tr.spreadsheet:nth-child('+i+') > td:nth-child(1)').textContent; //title
var refDiv2 = $('tr.spreadsheet:nth-child('+i+') > td:nth-child(2)').textContent; //time
var refDiv3 = $('tr.spreadsheet:nth-child('+i+') > td:nth-child(3) > select:nth-child(1)'); //list picker
//list_ playing / backlog / replay / custom / custom2 / custom3 / comp / retired
var refDiv2value = parseInt(refDiv2.substring(refDiv2.length-4, refDiv2.length-2));
if ( refDiv1.indexOf('VR') > -1 )
{
refDiv3.value = "list_custom2"
}
else if ( refDiv1.indexOf('Online') > -1 || refDiv1.indexOf('MMO') > -1 || refDiv1.indexOf('Multiplayer') > -1)
{
refDiv3.value = "list_custom2"
}
else if ( refDiv2 === "--" || ( refDiv2value < 5 && refDiv2.length < 6) )
{
refDiv3.value = "list_backlog";
}
else
{
refDiv3.value = "list_retired";
//refDiv3.value = "list_custom";
}
}
var EndTime = Date.now()
var DurTime = EndTime-startTime;
console.log("Completed! Duration: "+parseInt(1+DurTime/1000)+" seconds");
*/
//---------------------------------------------------------------------
//Code for saving form (answers to each game about adding to lists) of Steam import...
/*
var startTime = Date.now()
var limit = $('.steam_table > tbody:nth-child(2)').rows.length;
for ( let i = 1; i <= limit; i++)
{
var one = $('tr.spreadsheet:nth-child('+i+') > td:nth-child(1)').textContent;
var two = $('tr.spreadsheet:nth-child('+i+') > td:nth-child(3) > select:nth-child(1)').value;
console.log(one+"|"+two+'\n')
}
var EndTime = Date.now()
var DurTime = EndTime-startTime;
console.log("Completed! Duration: "+parseInt(1+DurTime/1000)+" seconds");
*/
//---------------------------------------------------------------------
//Code for including answers back to form of Steam import...
//put var gamesList above
/*
var startTime = Date.now()
var limit = $('.steam_table > tbody:nth-child(2)').rows.length;
for ( let i = 0; i < gamesList.length; i++)
{
var one = $('tr.spreadsheet:nth-child('+i+') > td:nth-child(1)').textContent;
var two = $('tr.spreadsheet:nth-child('+i+') > td:nth-child(3) > select:nth-child(1)').value;
var str = gamesList[i].split('|');
for ( let j = 1; j <= limit; j++)
{
var onej = $('tr.spreadsheet:nth-child('+j+') > td:nth-child(1)').textContent;
if ( onej === str[0] )
{
$('tr.spreadsheet:nth-child('+j+') > td:nth-child(3) > select:nth-child(1)').value = str[1];
}
}
//console.log(one+"|"+two+'\n')
}
var EndTime = Date.now()
var DurTime = EndTime-startTime;
console.log("Completed! Duration: "+parseInt(1+DurTime/1000)+" seconds");
*/
//---------------------------------------------------------------------
//Code for gathering list of links for lists like "Played"
/*
var startTime = Date.now()
var limit = $('.user_game_list').children.length;
var href = '', realhref = '';
for ( let i = 1; i < limit; i++)
{
var ajdi = $('.user_game_list').children[i].id;
href = $('#'+ajdi+' > tr:nth-child(1) > td:nth-child(4) > a:nth-child(3)').attributes.href.value
realhref += window.location.origin + '/' + href + '\n'
if ( i % 15 === 0 ){
console.log(realhref);
realhref = ''
}
}
var EndTime = Date.now()
var DurTime = EndTime-startTime;
console.log("Completed! Duration: "+parseInt(1+DurTime/1000)+" seconds");
*/
})();