-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathptp-imdb-combined.js
1237 lines (1106 loc) · 53.1 KB
/
ptp-imdb-combined.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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==UserScript==
// @name PTP - iMDB Combined Script
// @namespace https://github.com/Audionut/add-trackers
// @version 1.0.8
// @description Add many iMDB functions into one script
// @author Audionut
// @match https://passthepopcorn.me/torrents.php?id=*
// @icon https://passthepopcorn.me/favicon.ico
// @downloadURL https://github.com/Audionut/add-trackers/raw/main/ptp-imdb-combined.js
// @updateURL https://github.com/Audionut/add-trackers/raw/main/ptp-imdb-combined.js
// @grant GM_xmlhttpRequest
// @grant GM.setValue
// @grant GM.getValue
// @connect api.graphql.imdb.com
// @require https://cdnjs.cloudflare.com/ajax/libs/lz-string/1.4.4/lz-string.min.js
// ==/UserScript==
(function () {
'use strict';
// Options to display each script type
const SHOW_SIMILAR_MOVIES = true; // Change to false to hide "Movies Like This"
const PLACE_UNDER_CAST = false; // Put more like this under the cast list, else in the side panel
const SHOW_TECHNICAL_SPECIFICATIONS = true; // Change to false to hide "Technical Specifications"
const SHOW_BOX_OFFICE = true; // Change to false to hide "Box Office" data
const SHOW_AWARDS = true; // Change to false to hide awards data
const SHOW_SOUNDTRACKS = true; // Change to false to hide soundtracks data
const CACHE_EXPIRY_DAYS = 7; // Default to 7 days of API cache
// order of the panels in the sidebar
const techspecsLocation = 1;
const boxofficeLocation = 2;
const awardsLocation = 3;
// move the existing tags html element
const existingIMDBtags = 5;
// only if displaying in sidebar
const similarmoviesLocation = 4;
// Function to format and move the IMDb panel
function formatIMDbText() {
// Find the entire IMDb panel container
var imdbPanel = document.querySelector('div.box_tags.panel');
var sidebar = document.querySelector('div.sidebar');
if (!sidebar) {
console.error("Sidebar not found");
return;
}
if (imdbPanel) {
// Find the panel heading inside the IMDb panel
var imdbElement = imdbPanel.querySelector('.panel__heading__title');
// Create the new formatted HTML for the heading
var formattedHTML = '<span class="panel__heading__title"><span style="color: rgb(242, 219, 131);">IMDb</span> tags</span>';
// Set the inner HTML of the element to the formatted HTML
if (imdbElement) {
imdbElement.innerHTML = formattedHTML;
}
// Move the entire IMDb panel to the new location within the sidebar
sidebar.insertBefore(imdbPanel, sidebar.childNodes[3 + existingIMDBtags]);
}
}
// Run the function when the DOM is fully loaded
window.addEventListener('load', formatIMDbText);
var link = document.querySelector("a#imdb-title-link.rating");
if (!link) {
console.error("IMDb link not found");
return;
}
var imdbUrl = link.getAttribute("href");
if (!imdbUrl) {
console.error("IMDb URL not found");
return;
}
let imdbId = imdbUrl.split("/")[4];
if (!imdbId) {
console.error("IMDb ID not found");
return;
}
// Cache duration (1 week in milliseconds)
const CACHE_DURATION = CACHE_EXPIRY_DAYS * 24 * 60 * 60 * 1000; // 1 week
// Compress and set cache with expiration
const setCache = async (key, data) => {
const cacheData = {
timestamp: Date.now(),
data: LZString.compress(JSON.stringify(data)) // Compress the data before storing
};
await GM.setValue(key, JSON.stringify(cacheData));
};
// Decompress and get cache with expiration check
const getCache = async (key) => {
const cached = await GM.getValue(key, null);
if (cached) {
try {
const cacheData = JSON.parse(cached);
const currentTime = Date.now();
// Check if the cache is expired
if (currentTime - cacheData.timestamp < CACHE_DURATION) {
const decompressedData = LZString.decompress(cacheData.data);
const parsedData = JSON.parse(decompressedData);
if (parsedData && typeof parsedData === 'object') {
//console.log("Cache hit for key:", key);
return parsedData; // Return the decompressed and parsed data
} else {
console.error("Decompressed data is invalid:", decompressedData);
}
} else {
console.log("Cache expired for key:", key);
}
} catch (error) {
console.error("Error parsing cache for key:", key, error);
}
}
return null; // No cache found or cache was invalid/expired
};
// Function to fetch names from IMDb API with caching
const fetchNames = async (uniqueIds) => {
const cacheKey = `names_data_${JSON.stringify(uniqueIds)}`;
// Try to get cached names
const cachedNames = await getCache(cacheKey);
if (cachedNames) {
console.log("Using cached compressed names");
return cachedNames;
}
const url = `https://api.graphql.imdb.com/`;
const query = {
query: `
query {
names(ids: ${JSON.stringify(uniqueIds)}) {
id
nameText {
text
}
}
}
`
};
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: "POST",
url: url,
headers: {
"Content-Type": "application/json"
},
data: JSON.stringify(query),
onload: async function (response) {
if (response.status >= 200 && response.status < 300) {
const data = JSON.parse(response.responseText);
//console.log("Name ID query output:", data.data.names); // Log the output
// Cache the names
setCache(cacheKey, data.data.names);
resolve(data.data.names);
} else {
reject("Failed to fetch names");
}
},
onerror: function (response) {
reject("Request error");
}
});
});
};
let processedSoundtracks = [];
let idToNameMap = {};
// Function to fetch data from IMDb API with caching and expiration
const fetchIMDBData = async (imdbId, afterCursor = null, allAwards = []) => {
const cacheKey = `iMDB_data_${imdbId}`;
// Try to get cached IMDb data with compression and expiration
const cachedData = await getCache(cacheKey);
if (cachedData) {
console.log("Using cached compressed IMDb data");
if (cachedData.titleData) {
return cachedData; // Return cached data if structure is valid
} else {
console.error("Cached data structure invalid. Fetching fresh data...");
}
}
const url = `https://api.graphql.imdb.com/`;
const query = {
query: `
query getTitleDetails($id: ID!, $first: Int!, $after: ID) {
title(id: $id) {
soundtrack(first: 30) {
edges {
node {
id
text
comments {
markdown
}
amazonMusicProducts {
amazonId {
asin
}
artists {
artistName {
text
}
}
format {
text
}
productTitle {
text
}
}
}
}
}
id
titleText {
text
}
releaseYear {
year
}
runtimes(first: 5) {
edges {
node {
id
seconds
displayableProperty {
value {
plainText
}
}
attributes {
text
}
}
}
}
technicalSpecifications {
aspectRatios {
items {
aspectRatio
attributes {
text
}
}
}
cameras {
items {
camera
attributes {
text
}
}
}
colorations {
items {
text
attributes {
text
}
}
}
laboratories {
items {
laboratory
attributes {
text
}
}
}
negativeFormats {
items {
negativeFormat
attributes {
text
}
}
}
printedFormats {
items {
printedFormat
attributes {
text
}
}
}
processes {
items {
process
attributes {
text
}
}
}
soundMixes {
items {
text
attributes {
text
}
}
}
filmLengths {
items {
filmLength
countries {
text
}
numReels
}
}
}
moreLikeThisTitles(first: 12) {
edges {
node {
titleText {
text
}
primaryImage {
url
}
id
}
}
}
worldwideGross: rankedLifetimeGross(boxOfficeArea: WORLDWIDE) {
total {
amount
}
rank
}
domesticGross: rankedLifetimeGross(boxOfficeArea: DOMESTIC) {
total {
amount
}
rank
}
internationalGross: rankedLifetimeGross(boxOfficeArea: INTERNATIONAL) {
total {
amount
}
rank
}
domesticOpeningWeekend: openingWeekendGross(boxOfficeArea: DOMESTIC) {
gross {
total {
amount
}
}
theaterCount
weekendEndDate
weekendStartDate
}
internationalOpeningWeekend: openingWeekendGross(boxOfficeArea: INTERNATIONAL) {
gross {
total {
amount
}
}
}
productionBudget {
budget {
amount
}
}
prestigiousAwardSummary {
wins
nominations
award {
year
category {
text
}
}
}
awardNominations(first: $first, after: $after) {
edges {
node {
id
award {
id
text
}
awardedEntities {
... on AwardedNames {
names {
id
nameText {
text
}
}
}
... on AwardedTitles {
titles {
id
titleText {
text
}
}
}
}
category {
text
}
forEpisodes {
id
titleText {
text
}
}
forSongTitles
isWinner
notes {
plainText
}
winAnnouncementDate {
date
}
winningRank
}
}
pageInfo {
endCursor
hasNextPage
}
}
}
}
`,
variables: {
id: imdbId,
first: 250,
after: afterCursor
}
};
return new Promise(async (resolve, reject) => {
GM_xmlhttpRequest({
method: "POST",
url: url,
headers: {
"Content-Type": "application/json"
},
data: JSON.stringify(query),
onload: async function (response) {
if (response.status >= 200 && response.status < 300) {
const data = JSON.parse(response.responseText);
if (data && data.data && data.data.title) {
const titleData = data.data.title;
const soundtracks = titleData.soundtrack.edges;
const awardNominations = titleData.awardNominations.edges.map(edge => edge.node);
allAwards.push(...awardNominations);
if (titleData.awardNominations.pageInfo.hasNextPage) {
fetchIMDBData(imdbId, titleData.awardNominations.pageInfo.endCursor, allAwards)
.then(resolve)
.catch(reject);
} else {
titleData.awardNominationsCombined = allAwards;
delete titleData.awardNominations;
// Extract unique IDs from comments
const uniqueIds = [];
soundtracks.forEach(edge => {
edge.node.comments.forEach(comment => {
const match = comment.markdown.match(/\[link=nm(\d+)\]/);
if (match) {
uniqueIds.push(`nm${match[1]}`);
}
});
});
// Fetch names for unique IDs
const uniqueIdSet = [...new Set(uniqueIds)];
const names = await fetchNames(uniqueIdSet);
// Map IDs to names
const idToNameMap = {};
names.forEach(name => {
idToNameMap[name.id] = name.nameText.text;
});
//console.log("ID to Name Map:", idToNameMap); // Log the ID to Name mapping
// Process the soundtrack data
const processedSoundtracks = soundtracks.map(edge => {
const soundtrack = edge.node;
let artistName = null;
let artistLink = null;
let artistId = null;
// Try to find "Performed by" first
soundtrack.comments.forEach(comment => {
const performedByMatch = comment.markdown.match(/Performed by \[link=nm(\d+)\]/);
if (performedByMatch && !artistName) {
artistId = `nm${performedByMatch[1]}`;
artistName = idToNameMap[artistId];
artistLink = `https://www.imdb.com/name/${artistId}/`;
//console.log(`Matched "Performed by" ID: ${artistId}, Artist Name: ${artistName}, Artist Link: ${artistLink}`);
}
});
// If no "Performed by" found, try to find other roles
if (!artistName) {
soundtrack.comments.forEach(comment => {
const match = comment.markdown.match(/\[link=nm(\d+)\]/);
if (match && !artistName) {
artistId = `nm${match[1]}`;
artistName = idToNameMap[artistId] || match[0];
artistLink = `https://www.imdb.com/name/${artistId}/`;
} else if (!match && !artistName) {
const performedByMatch = comment.markdown.match(/Performed by (.*)/);
if (performedByMatch) {
artistName = performedByMatch[1];
artistLink = `https://duckduckgo.com/?q=${encodeURIComponent(artistName)}`;
}
}
});
}
// Fallback to amazonMusicProducts if no artist name found
if (!artistName && soundtrack.amazonMusicProducts.length > 0) {
const product = soundtrack.amazonMusicProducts[0];
if (product.artists && product.artists.length > 0) {
artistName = product.artists[0].artistName.text;
artistLink = `https://duckduckgo.com/?q=${encodeURIComponent(artistName)}`;
} else {
artistName = product.productTitle.text;
artistLink = `https://duckduckgo.com/?q=${encodeURIComponent(artistName)}`;
}
}
// Final fallback to text
if (!artistName) {
artistName = soundtrack.text;
artistLink = `https://duckduckgo.com/?q=${encodeURIComponent(artistName)}`;
}
return {
title: soundtrack.text,
artist: artistName,
link: artistLink,
artistId: artistId
};
});
// Cache the data with compression
setCache(cacheKey, data);
// Resolve after processing soundtracks and other data
resolve({ titleData, processedSoundtracks, idToNameMap });
}
} else {
console.error("Invalid data structure", data);
reject(new Error("Invalid data structure"));
}
} else {
console.error("Failed to fetch data", response);
reject(new Error("Failed to fetch data"));
}
},
onerror: function (response) {
console.error("Request error", response);
reject(new Error("Request error"));
}
});
});
};
// Function to display similar movies
const displaySimilarMovies = (similarMovies) => {
let style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = `
.panel__heading__toggler {
margin-left: auto;
cursor: pointer;
}
`;
document.getElementsByTagName('head')[0].appendChild(style);
var newPanel = document.createElement('div');
newPanel.className = 'panel';
newPanel.id = 'similar_movies';
var panelHeading = document.createElement('div');
panelHeading.className = 'panel__heading';
var title = document.createElement('span');
title.className = 'panel__heading__title';
var imdb = document.createElement('span');
imdb.style.color = '#F2DB83';
imdb.textContent = 'IMDb';
title.appendChild(imdb);
title.appendChild(document.createTextNode(' More like this'));
var toggle = document.createElement('a');
toggle.href = 'javascript:void(0);';
toggle.style.float = "right";
toggle.textContent = '(Show all movies)';
panelHeading.appendChild(title);
panelHeading.appendChild(toggle);
newPanel.appendChild(panelHeading);
var panelBody = document.createElement('div');
panelBody.style.position = 'relative';
panelBody.style.display = 'block';
panelBody.style.paddingTop = "0px";
panelBody.style.width = "100%";
newPanel.appendChild(panelBody);
const insertAfterElement = (referenceNode, newNode) => {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
};
let displayMethod = '';
if (PLACE_UNDER_CAST) {
const targetTable = document.querySelector('.table.table--panel-like.table--bordered.table--striped');
if (targetTable) {
insertAfterElement(targetTable, newPanel);
displayMethod = 'table';
} else {
console.error("Target table not found");
return;
}
} else {
const parentGuidePanel = document.querySelector('div.panel#parents_guide');
if (parentGuidePanel) {
parentGuidePanel.parentNode.insertBefore(newPanel, parentGuidePanel.nextSibling);
displayMethod = 'flex';
toggle.textContent = 'Toggle';
toggle.className = 'panel__heading__toggler';
toggle.title = 'Toggle';
toggle.onclick = function () {
panelBody.style.display = (panelBody.style.display === 'none') ? 'block' : 'none';
return false;
};
} else {
const sidebar = document.querySelector('div.sidebar');
if (!sidebar) {
console.error("Sidebar not found");
return;
}
sidebar.insertBefore(newPanel, sidebar.childNodes[3 + similarmoviesLocation]);
displayMethod = 'flex';
toggle.textContent = 'Toggle';
toggle.className = 'panel__heading__toggler';
toggle.title = 'Toggle';
toggle.onclick = function () {
panelBody.style.display = (panelBody.style.display === 'none') ? 'block' : 'none';
return false;
};
}
}
var similarMoviesDiv = document.createElement('div');
if (displayMethod === 'table') {
similarMoviesDiv.style.textAlign = 'center';
similarMoviesDiv.style.display = 'table';
similarMoviesDiv.style.width = '100%';
similarMoviesDiv.style.borderCollapse = 'separate';
similarMoviesDiv.style.borderSpacing = '4px';
} else {
similarMoviesDiv.style.display = 'flex';
similarMoviesDiv.style.flexWrap = 'wrap';
similarMoviesDiv.style.justifyContent = 'center';
similarMoviesDiv.style.padding = '4px';
similarMoviesDiv.style.width = '100%';
}
let count = 0;
let rowDiv = document.createElement('div');
if (displayMethod === 'table') {
rowDiv.style.display = 'table-row';
} else {
rowDiv.style.display = 'flex';
rowDiv.style.justifyContent = 'center';
rowDiv.style.width = '100%';
rowDiv.style.marginBottom = '2px';
}
similarMoviesDiv.appendChild(rowDiv);
similarMovies.forEach((edge) => {
let movie = edge.node;
if (!movie.primaryImage) {
console.warn("No like this image found for movie:", movie.titleText.text);
return;
}
let title = movie.titleText.text;
let searchLink = `https://passthepopcorn.me/torrents.php?action=advanced&searchstr=${movie.id}`;
let image = movie.primaryImage.url;
var movieDiv = document.createElement('div');
if (displayMethod === 'table') {
movieDiv.style.width = '25%';
movieDiv.style.display = 'table-cell';
movieDiv.style.textAlign = 'center';
movieDiv.style.backgroundColor = '#2c2c2c';
movieDiv.style.borderRadius = '10px';
movieDiv.style.overflow = 'hidden';
movieDiv.style.fontSize = '1em';
} else {
movieDiv.style.width = '33%';
movieDiv.style.textAlign = 'center';
movieDiv.style.backgroundColor = '#2c2c2c';
movieDiv.style.borderRadius = '10px';
movieDiv.style.overflow = 'hidden';
movieDiv.style.fontSize = '1em';
movieDiv.style.margin = '3px 3px 1px 1px';
}
movieDiv.innerHTML = `<a href="${searchLink}" target="_blank"><img style="max-width:100%; display:block; margin:auto;" src="${image}" alt="${title}" /></a><span>${title}</span>`;
rowDiv.appendChild(movieDiv);
count++;
if (displayMethod === 'table' && count % 4 === 0) {
rowDiv = document.createElement('div');
rowDiv.style.display = 'table-row';
similarMoviesDiv.appendChild(rowDiv);
} else if (displayMethod === 'flex' && count % 3 === 0) {
rowDiv = document.createElement('div');
rowDiv.style.display = 'flex';
rowDiv.style.justifyContent = 'center';
rowDiv.style.width = '100%';
rowDiv.style.marginBottom = '2px';
similarMoviesDiv.appendChild(rowDiv);
}
});
if (displayMethod === 'table' && similarMoviesDiv.children.length > 2) {
Array.from(similarMoviesDiv.children).slice(2).forEach(child => child.style.display = 'none');
} else if (displayMethod === 'flex' && similarMoviesDiv.children.length > 3) {
Array.from(similarMoviesDiv.children).slice(3).forEach(child => child.style.display = 'none');
}
if (displayMethod === 'table') {
toggle.addEventListener('click', function () {
const rows = Array.from(similarMoviesDiv.children);
const isHidden = rows.slice(2).some(row => row.style.display === 'none');
rows.slice(2).forEach(row => {
row.style.display = isHidden ? 'table-row' : 'none';
});
toggle.textContent = isHidden ? '(Hide extra movies)' : '(Show all movies)';
});
}
panelBody.appendChild(similarMoviesDiv);
};
// Function to display technical specifications
const displayTechnicalSpecifications = (data) => {
var newPanel = document.createElement('div');
newPanel.className = 'panel';
newPanel.id = 'technical_specifications';
var panelHeading = document.createElement('div');
panelHeading.className = 'panel__heading';
var title = document.createElement('span');
title.className = 'panel__heading__title';
var imdb = document.createElement('span');
imdb.style.color = '#F2DB83';
imdb.textContent = 'IMDb';
title.appendChild(imdb);
title.appendChild(document.createTextNode(' Technical Specifications'));
var imdbLink = document.createElement('a');
imdbLink.href = `https://www.imdb.com/title/${imdbId}/technical`;
imdbLink.title = 'IMDB Url';
imdbLink.textContent = 'IMDb Url';
imdbLink.target = '_blank';
imdbLink.style.marginLeft = '5px';
var toggle = document.createElement('a');
toggle.className = 'panel__heading__toggler';
toggle.title = 'Toggle';
toggle.href = '#';
toggle.textContent = 'Toggle';
toggle.onclick = function () {
var panelBody = document.querySelector('#technical_specifications .panel__body');
panelBody.style.display = (panelBody.style.display === 'none') ? 'block' : 'none';
return false;
};
panelHeading.appendChild(title);
panelHeading.appendChild(imdbLink);
panelHeading.appendChild(toggle);
newPanel.appendChild(panelHeading);
var panelBody = document.createElement('div');
panelBody.className = 'panel__body';
newPanel.appendChild(panelBody);
var sidebar = document.querySelector('div.sidebar');
if (!sidebar) {
console.error("Sidebar not found");
return;
}
sidebar.insertBefore(newPanel, sidebar.childNodes[3 + techspecsLocation]);
const specs = data.data.title.technicalSpecifications || {};
const runtimes = data.data.title.runtimes?.edges || [];
const panelBodyElement = document.getElementById('technical_specifications').querySelector('.panel__body');
const specContainer = document.createElement('div');
specContainer.className = 'technicalSpecification';
specContainer.style.color = "#fff";
specContainer.style.fontSize = "1em";
const formatSpec = (title, items, key, attributesKey) => {
if (items && items.length > 0) {
let values = items.map(item => {
let value = item[key];
if (item[attributesKey] && item[attributesKey].length > 0) {
value += ` (${item[attributesKey].map(attr => attr.text).join(", ")})`;
}
return value;
}).filter(value => value).join(", ");
return `<strong>${title}:</strong> ${values}<br>`;
}
return "";
};
const formatFilmLengths = (items) => {
if (items && items.length > 0) {
let values = items.map(item => {
let value = `${item.filmLength} m`;
if (item.countries && item.countries.length > 0) {
value += ` (${item.countries.map(country => country.text).join(", ")})`;
}
if (item.numReels) {
value += ` (${item.numReels} reels)`;
}
return value;
}).filter(value => value).join(", ");
return `<strong>Film Length:</strong> ${values}<br>`;
}
return "";
};
const formatRuntimes = (runtimes) => {
if (runtimes && runtimes.length > 0) {
let values = runtimes.map(runtime => {
let value = `${runtime.node.displayableProperty.value.plainText}`;
if (runtime.node.attributes && runtime.node.attributes.length > 0) {
value += ` (${runtime.node.attributes.map(attr => attr.text).join(", ")})`;
}
return value;
}).join(", ");
return `<strong>Runtime:</strong> ${values}<br>`;
}
return "";
};
specContainer.innerHTML += formatRuntimes(runtimes);
specContainer.innerHTML += formatSpec("Sound mix", specs.soundMixes?.items || [], "text", "attributes");
specContainer.innerHTML += formatSpec("Color", specs.colorations?.items || [], "text", "attributes");
specContainer.innerHTML += formatSpec("Aspect ratio", specs.aspectRatios?.items || [], "aspectRatio", "attributes");
specContainer.innerHTML += formatSpec("Camera", specs.cameras?.items || [], "camera", "attributes");
specContainer.innerHTML += formatSpec("Laboratory", specs.laboratories?.items || [], "laboratory", "attributes");
specContainer.innerHTML += formatFilmLengths(specs.filmLengths?.items || []);
specContainer.innerHTML += formatSpec("Negative Format", specs.negativeFormats?.items || [], "negativeFormat", "attributes");
specContainer.innerHTML += formatSpec("Cinematographic Process", specs.processes?.items || [], "process", "attributes");
specContainer.innerHTML += formatSpec("Printed Film Format", specs.printedFormats?.items || [], "printedFormat", "attributes");
panelBodyElement.appendChild(specContainer);
};
// Function to display box office details
const displayBoxOffice = (data) => {
var newPanel = document.createElement('div');
newPanel.className = 'panel';
newPanel.id = 'box_office';
var panelHeading = document.createElement('div');
panelHeading.className = 'panel__heading';
var title = document.createElement('span');
title.className = 'panel__heading__title';
var imdb = document.createElement('span');
imdb.style.color = '#F2DB83';
imdb.textContent = 'IMDb';
title.appendChild(imdb);
title.appendChild(document.createTextNode(' Box Office'));
var toggle = document.createElement('a');
toggle.className = 'panel__heading__toggler';
toggle.title = 'Toggle';
toggle.href = '#';
toggle.textContent = 'Toggle';
toggle.onclick = function () {
var panelBody = document.querySelector('#box_office .panel__body');
panelBody.style.display = (panelBody.style.display === 'none') ? 'block' : 'none';
return false;
};
panelHeading.appendChild(title);
panelHeading.appendChild(toggle);
newPanel.appendChild(panelHeading);
var panelBody = document.createElement('div');
panelBody.className = 'panel__body';
newPanel.appendChild(panelBody);
var sidebar = document.querySelector('div.sidebar');
if (!sidebar) {
console.error("Sidebar not found");
return;
}
sidebar.insertBefore(newPanel, sidebar.childNodes[3 + boxofficeLocation]);
const titleData = data.data.title || {};
const panelBodyElement = document.getElementById('box_office').querySelector('.panel__body');
const boxOfficeContainer = document.createElement('div');
boxOfficeContainer.className = 'boxOffice';
boxOfficeContainer.style.color = "#fff";
boxOfficeContainer.style.fontSize = "1em";
const formatCurrency = (amount) => {
return new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', minimumFractionDigits: 0 }).format(amount);
};
const formatRankedGross = (title, boxOfficeData) => {
if (boxOfficeData && boxOfficeData.total && boxOfficeData.total.amount) {
return `<strong>${title}:</strong> ${formatCurrency(boxOfficeData.total.amount)} (Rank: ${boxOfficeData.rank})<br>`;
}
return "";
};
const formatOpeningWeekendGross = (title, boxOfficeData) => {
if (boxOfficeData && boxOfficeData.gross && boxOfficeData.gross.total.amount) {
return `<strong>${title}:</strong> ${formatCurrency(boxOfficeData.gross.total.amount)}<br>`;
}
return "";
};
const formatProductionBudget = (budgetData) => {
if (budgetData && budgetData.amount) {
return `<strong>Production Budget:</strong> ${formatCurrency(budgetData.amount)}<br>`;
}
return "";
};
let output = '';
if (titleData.productionBudget && titleData.productionBudget.budget) {
output += formatProductionBudget(titleData.productionBudget.budget);
}
if (titleData.worldwideGross) {
output += formatRankedGross("Worldwide Gross", titleData.worldwideGross);
}
if (titleData.domesticGross) {
output += formatRankedGross("Domestic Gross", titleData.domesticGross);
}
if (titleData.internationalGross) {
output += formatRankedGross("International Gross", titleData.internationalGross);
}
if (titleData.domesticOpeningWeekend) {
output += formatOpeningWeekendGross("Domestic Opening Weekend Gross", titleData.domesticOpeningWeekend);
if (titleData.domesticOpeningWeekend) {
output += `<strong>Theater Count:</strong> ${titleData.domesticOpeningWeekend.theaterCount}<br>
<strong>Weekend Start Date:</strong> ${titleData.domesticOpeningWeekend.weekendStartDate}<br>
<strong>Weekend End Date:</strong> ${titleData.domesticOpeningWeekend.weekendEndDate}<br>`;
}
}
if (titleData.internationalOpeningWeekend) {
output += formatOpeningWeekendGross("International Opening Weekend Gross", titleData.internationalOpeningWeekend);
}
boxOfficeContainer.innerHTML = output;
panelBodyElement.appendChild(boxOfficeContainer);
};
const displayAwardsData = (titleData) => {
const imdbId = titleData.id;
const wins = titleData.prestigiousAwardSummary?.wins ?? 0;
const nominations = titleData.prestigiousAwardSummary?.nominations ?? 0;