-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgiantbomb.user.js
More file actions
188 lines (174 loc) · 6.64 KB
/
giantbomb.user.js
File metadata and controls
188 lines (174 loc) · 6.64 KB
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
// ==UserScript==
// @name GazelleGames Giantbomb Uploady
// @namespace https://gazellegames.net/
// @version 1.0.8
// @description Uploady for giantbomb
// @author FinalDoom
// @match https://gazellegames.net/upload.php*
// @match https://gazellegames.net/torrents.php?action=editgroup*
// @match https://www.giantbomb.com/*
// @match http://www.giantbomb.com/*
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// @require https://code.jquery.com/jquery-3.6.0.min.js
// @require https://raw.githubusercontent.com/tengattack/html2bbcode.js/master/lib/html2bbcode.js
// @require https://raw.githubusercontent.com/FinalDoom/gazelle-uploady/master/common.js
// ==/UserScript==
'use strict';
//
// #region Giantbomb functions
//
async function getGameInfo(resolve) {
const giantbomb = new GameInfo();
const gameId = window.location.pathname.split('/')[2];
// #region Fetch wiki info
giantbomb.giantbomb = window.location.toString();
giantbomb.title = $('a.wiki-title').text().trim();
giantbomb.description = $('section .wiki-item-display.js-toc-content').absoluteLinks().html();
giantbomb.addTag(
...$.map($(`#wiki-${gameId}-genres a`), (elem) =>
$(elem)
.text()
.trim()
.toLowerCase()
.replace(/[ -]/g, '.')
.replace(/'em/, 'em')
.replace(/,\./g, ', ')
.replace(/,.,/g, ','),
),
);
giantbomb.addAlias($('.wiki-item-display .aliases').text());
giantbomb.year = $(`#wiki-${gameId}-release_date`).text();
// #endregion Fetch wiki info
// #region Fetch images
giantbomb.cover = $('.wiki-boxart img').attr('src');
const galleryUrl = await $.ajax({
url: window.location.pathname + 'images/',
})
.then((data) => {
if (data.html) data = data.html;
const galleryMarker = $(data).find('#galleryMarker');
const galleryId = galleryMarker.attr('data-gallery-id');
const objectId = galleryMarker.attr('data-object-id');
return `/js/image-data.json?images=${galleryId}&start=0&count=16&object=${objectId}`;
})
.catch((error) => {
console.error(error);
throw 'Encountered an error getting images page. Check console';
});
await $.ajax({
url: galleryUrl,
})
.then((data) => data.images.forEach(({original}) => giantbomb.addScreenshot(original)))
.catch((error) => {
console.error(error);
throw 'Encountered an error getting images url json. Check console';
});
// #endregion Fetch images
// #region Fetch release info
await $.ajax({
url: window.location.pathname + 'releases/',
})
.then((data) => {
// Here pull the TOC and display it for selection
const TOC = $(data).find('.aside-toc').parent();
if (!TOC.length) {
// If there is no TOC fall back to below for just selecting platform, nothing else
$(`#wiki-${gameId}-platforms`)
.css({border: '2px solid yellow'})
.children('a')
.click(function (event) {
event.preventDefault();
giantbomb.platform = $(this).text();
$(this).css({border: ''});
resolve(giantbomb);
return;
});
window.alert('Please choose a platform from the highlighed options');
return;
}
// Display TOC to choose appropriate specific release
$('body').before(
$('<div class="toc-overlay">')
.css({
background: 'rgba(0,0,0,.8)',
position: 'fixed',
top: 0,
left: 0,
height: '100%',
width: '100%',
display: 'flex',
flexDirection: 'column',
alignContent: 'center',
zIndex: 5000,
})
.append(TOC.css({width: '443px', maxHeight: '100%', margin: 'auto', overflowY: 'auto'})),
);
TOC.find('h3').text('Please choose a release').css({color: 'yellow'});
TOC.find('a').click(function (event) {
event.preventDefault();
if ($(this).attr('href').startsWith('#toc-release-platform')) return;
const releaseId = $(this)
.attr('href')
.replace(/#toc-release-(\d+)/, '$1');
$(data)
.find(`td[data-field='name']:not([data-id$='-${releaseId}'])`)
.each(function () {
giantbomb.addAlias($(this).text().trim().replace(/,/, ''));
});
const releaseBlock = $(data).find(`[name='toc-release-${releaseId}']`).next('.release');
const releaseTitle = releaseBlock.find('[data-field="name"]').text().trim();
if (releaseTitle && giantbomb.title !== releaseTitle) {
giantbomb.title = releaseTitle;
}
giantbomb.rating = releaseBlock.find('[data-field="rating"]').text().trim().replace(/^$/, 'N/A');
giantbomb.platform = releaseBlock.find('[data-field="platform"]').text();
giantbomb.year = releaseBlock.find('[data-field="releaseDate"]').text();
// Grab extra info
const singlePlayerFeatures = releaseBlock.find('[data-field="singlePlayerFeatures"]').text().trim();
const multiPlayerFeatures = releaseBlock.find('[data-field="multiPlayerFeatures"]').text().trim();
const notes = releaseBlock.find('[data-field="description"]').text().trim();
giantbomb.extraInfo = {
region: releaseBlock.find('[data-field="region"]').text().trim(),
// TODO developers and publishers could have multiple entries, but I don't have an example
developers: releaseBlock
.find('[data-field="developers"]')
.map(function () {
return $(this).text().trim();
})
.toArray()
.join(', '),
publishers: releaseBlock
.find('[data-field="publishers"]')
.map(function () {
return $(this).text().trim();
})
.toArray()
.join(', '),
...(singlePlayerFeatures && singlePlayerFeatures !== 'N/A'
? {singlePlayerFeatures: singlePlayerFeatures}
: {}),
...(multiPlayerFeatures && multiPlayerFeatures !== 'N/A' ? {multiPlayerFeatures: multiPlayerFeatures} : {}),
...(notes && notes !== 'N/A' ? {notes: notes} : {}),
};
resolve(giantbomb);
});
})
.catch((error) => {
console.error(error);
throw 'Encountered an error getting releases. Check console';
});
// #endregion Fetch release info
}
//
// #endregion Giantbomb functions
//
(function () {
('use strict');
new UploadyFactory().build(
'Search Giantbomb',
(title) => `https://www.giantbomb.com/search/?header=1&i=game&q=${title}`,
getGameInfo,
);
})();