-
Notifications
You must be signed in to change notification settings - Fork 3
/
fateOfAllFools.user.js
321 lines (285 loc) · 11.8 KB
/
fateOfAllFools.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
// ==UserScript==
// @author Robert Slifka (github @rslifka)
// @connect docs.google.com
// @connect unpkg.com
// @connect rslifka.github.io
// @description Customizations on top of the Destiny Item Manager
// @grant GM_addStyle
// @grant GM_log
// @grant GM_getResourceText
// @grant GM_xmlhttpRequest
// @homepage https://github.com/rslifka/fate_of_all_fools
// @match https://*.destinyitemmanager.com/*
// @name FateOfAllFools - DIM Customization
// @require http://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
// @require https://unpkg.com/tippy.js@1.4.0/dist/tippy.js
// @run-at document-start
// @supportURL https://github.com/rslifka/fate_of_all_fools/issues
// ==/UserScript==
(function() {
'use strict';
/*
**************************************************************
C H A N G E O N L Y T H E S E U R L S \/ \/ \/ \/ \/
**************************************************************
*/
var ITEM_DATA_TSVS = [
'https://docs.google.com/spreadsheets/d/e/2PACX-1vQ06pCDSdvu2nQzgHMXl22ci-6pO9rTTmvZmlKXaiBrIHVhl1X1awIaHEOagZcs4ME4X9ZMEghBP9NE/pub?gid=0&single=true&output=tsv',
'https://docs.google.com/spreadsheets/d/e/2PACX-1vQ06pCDSdvu2nQzgHMXl22ci-6pO9rTTmvZmlKXaiBrIHVhl1X1awIaHEOagZcs4ME4X9ZMEghBP9NE/pub?gid=945724952&single=true&output=tsv',
'https://docs.google.com/spreadsheets/d/e/2PACX-1vQ06pCDSdvu2nQzgHMXl22ci-6pO9rTTmvZmlKXaiBrIHVhl1X1awIaHEOagZcs4ME4X9ZMEghBP9NE/pub?gid=1848980798&single=true&output=tsv'
];
/*
**************************************************************
C H A N G E O N L Y T H E S E U R L S ^^^^^^^^^^^^^^
**************************************************************
*/
var ALL_WEAPON_STATUS = new Map();
var ALL_WEAPON_COMMENTS = new Map();
var PVE_WEAPON_STATUS = new Map();
var PVP_WEAPON_STATUS = new Map();
var STATUS_CLASSES = {
'Y': 'foaf-yes',
'N': 'foaf-no',
'?': 'foaf-unknown'
};
function log(message) {
GM_log('[FOAF] ' + message);
}
// We're replacing DIM's tags with our own
function clearDIMTags() {
["Kinetic","Energy","Power"].forEach(function(dimWeaponType) {
$("div[drag-channel='"+dimWeaponType+"'] .fa").each(function(index,element) {
$(this).remove();
});
$("div[drag-channel='"+dimWeaponType+"'] .no-tag").each(function(index,element) {
$(this).remove();
});
});
}
/*
Instead of a yellow border to indicate a mod, we're going to add "+M" to the end of
the item's Power Level. In D1, yellow borders used to indicate that an item was fully
leveled up, and considering how eventually all items will have legendary mods in them,
it ends up being visual noise.
*/
function addLegendaryModInfo() {
$('.item-img.complete').siblings('.item-stat').text(function(index,oldText) {
return (oldText.endsWith('+M')) ? (oldText) : (oldText+'+M');
});
}
function iconifyWeapons() {
["Kinetic","Energy","Power"].forEach(function(dimWeaponType) {
$('div[title][drag-channel="'+dimWeaponType+'"]').each(function(index,element) {
var weaponName = $(this).attr('title');
var weaponMatched = false;
var $item_tag = $(this).children('.item-tag');
switch(ALL_WEAPON_STATUS.get(weaponName)) {
case 'Junk':
if ($item_tag.length === 0) {
$(this).append($("<div>", {"class": "item-tag foaf-thumbs-down"}));
}
break;
case 'Keep':
case 'Favourite':
if ($item_tag.length === 0) {
var tagClass = STATUS_CLASSES[PVE_WEAPON_STATUS.get(weaponName)];
$(this).append($("<div>", {"class": "item-tag foaf-pve " + tagClass}));
tagClass = STATUS_CLASSES[PVP_WEAPON_STATUS.get(weaponName)];
$(this).append($("<div>", {"class": "item-tag foaf-pvp " + tagClass}));
}
break;
default:
if ($item_tag.length === 0) {
$(this).append($("<div>", {"class": "item-tag foaf-question-mark"}));
}
}
});
});
}
var tippyInitialized = false;
function populateTooltips() {
var PVE_STATUS_DESC = {
'Y': 'CRUSH the Red Legion!',
'N': 'Nope :(',
'?': 'Uncertain!'
};
var PVP_STATUS_DESC = {
'Y': 'FIGHT FOREVER GUARDIANN!',
'N': 'Nope :(',
'?': 'Uncertain!'
};
// TODO - For every one of these that doesn't already have the class, add it and call tippy directly?
["Kinetic","Energy","Power"].forEach(function(dimWeaponType) {
$('div[title][drag-channel="'+dimWeaponType+'"]').each(function(index,element) {
$(this).addClass('tippy-tip');
});
});
if (tippyInitialized) {
return;
}
tippyInitialized = true;
tippy('.tippy-tip', {
html: targetElement => {
var weaponName = $(targetElement).attr('title');
var knownWeapon = ALL_WEAPON_STATUS.get(weaponName) !== undefined;
var isCommented = ALL_WEAPON_COMMENTS.get(weaponName) !== '';
var comments = isCommented ? ALL_WEAPON_COMMENTS.get(weaponName) : '(no comments entered)';
var status = ALL_WEAPON_STATUS.get(weaponName);
var statusClass;
var displayDetails = false;
switch(status) {
case 'Junk':
statusClass = 'foaf-thumbs-down foaf-no';
break;
case 'Keep':
case 'Favourite':
statusClass = 'foaf-thumbs-up foaf-yes';
displayDetails = true;
break;
default:
statusClass = 'foaf-question-mark foaf-unknown';
status = 'Unknown';
comments = 'This weapon has not been rated';
}
return $(`
<table style="min-width:350px;max-width:500px;">
<tr>
<td colspan="3">
<table style="width:100%">
<tr>
<td style="text-align:left;font-weight:bold;font-size:1.2em">
${weaponName}
</td>
<td style="text-align:right;">
<span style="font-weight:bold;font-size:1.2em">${status}</span>
<div class="${statusClass}" style="font-size:1.2em;display:inline-block"/>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:left;word-wrap:break-word;">
<span>${comments}</span>
</td>
</tr>
</table>
</td>
</tr>
<tr style="${displayDetails ? '' : 'display:none'}">
<td class="foaf-pve ${STATUS_CLASSES[PVE_WEAPON_STATUS.get(weaponName)]}" style="text-align:center;font-size:1.5em">
</td>
<td style="text-align:left;white-space:nowrap;">
Good for PvE?
</td>
<td class="${STATUS_CLASSES[PVE_WEAPON_STATUS.get(weaponName)]}" style="text-align:left;font-weight:bold;width:100%;">
${PVE_STATUS_DESC[PVE_WEAPON_STATUS.get(weaponName)]}
</td>
</tr>
<tr style="${displayDetails ? '' : 'display:none'}">
<td class="foaf-pvp ${STATUS_CLASSES[PVP_WEAPON_STATUS.get(weaponName)]}" style="text-align:center;font-size:1.2em">
</td>
<td style="text-align:left;white-space:nowrap;">
Good for PvP?
</td>
<td class="${STATUS_CLASSES[PVP_WEAPON_STATUS.get(weaponName)]}" style="text-align:left;font-weight:bold;width:100%;">
${PVP_STATUS_DESC[PVP_WEAPON_STATUS.get(weaponName)]}
</td>
</tr>
</table>
`).get(0);
}
});
}
function refresh() {
log('Refreshing...');
log('Clearing DIM weapon item tags...');
clearDIMTags();
log('Adding mod indicator...');
addLegendaryModInfo();
log('Adding icons to weapons...');
iconifyWeapons();
log('Resetting tooltips...');
populateTooltips();
log('Done! Scheduling next refresh.');
setTimeout(refresh, 5000);
}
function itemsAreLoaded() {
var deferredReady = $.Deferred();
setInterval(function() {
if ($('.item-img').length > 0) {
deferredReady.resolve();
}
}, 1000);
return deferredReady.promise();
}
function rankingsDownloaded(tsvUrl) {
var deferredReady = $.Deferred();
GM_xmlhttpRequest({
method: 'GET',
url: tsvUrl,
context: deferredReady,
onload: function(response) {
log('Processing collection: "'+tsvUrl+'"');
var dataLines = response.responseText.split(/[\r\n]+/);
log('Found ('+(dataLines.length-1)+') weapons');
// Skip the column headers line
// Name,Type,Archetype,Status,PvE,PvP,Comments
for (var i = 1; i < dataLines.length; i++) {
// We've split by TAB because no weapon names have tabs in them
var data = dataLines[i].split('\t');
// log('Examining ' + data);
ALL_WEAPON_STATUS.set(data[0], data[3]);
// log('Weapon registered: '+data[0]+'; status='+data[3]);
PVE_WEAPON_STATUS.set(data[0], data[4]);
// log('PvE weapon registered: '+data[0]+'; status='+data[4]);
PVP_WEAPON_STATUS.set(data[0], data[5]);
// log('PvP weapon registered: '+data[0]+'; status='+data[5]);
ALL_WEAPON_COMMENTS.set(data[0], data[6]);
// log('Comments: '+data[0]+'; status='+data[6]);
}
deferredReady.resolve();
}
});
return deferredReady.promise();
}
log('Applying CSS...');
[
'https://rslifka.github.io/fate_of_all_fools/css/fateofallfools.css',
'https://rslifka.github.io/fate_of_all_fools/css/overrides.css',
'https://unpkg.com/tippy.js@1.4.0/dist/tippy.css'
].forEach(function(cssPath) {
log('Downloading style: '+cssPath);
GM_xmlhttpRequest({
method: 'GET',
url: cssPath,
onload: function(response) {
log('Done! Installing...');
GM_addStyle(response.responseText);
}
});
});
/*
Pull down new weapon data at a separate interval than the refresh timer.
The idea is that you're updating this sheet on a much longer interval
than you're dragging items around (which requires a periodic refresh to
re-apply our styles).
That being said, chances are when you do make an update, you'd like to
see the change sooner than later, so we'll use a time conducive to
interactivity.
*/
log('Initializing data refresh timer...');
setInterval(function() {
$.when(
rankingsDownloaded(ITEM_DATA_TSVS[0]),
rankingsDownloaded(ITEM_DATA_TSVS[1]),
rankingsDownloaded(ITEM_DATA_TSVS[2])
).then(function() {
log('Data refresh complete!');
});
}, 15000);
log('Initialized, waiting for items to appear...');
$.when(
itemsAreLoaded(),
rankingsDownloaded(ITEM_DATA_TSVS[0]),
rankingsDownloaded(ITEM_DATA_TSVS[1]),
rankingsDownloaded(ITEM_DATA_TSVS[2])
).then(refresh);
})();