-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
166 lines (153 loc) · 10.1 KB
/
script.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
// ==UserScript==
// @name Wikipedia Movie Rating
// @namespace https://en.wikipedia.org/
// @version 0.1
// @description Display movie rating on top of the wikipedia page
// @author Vatsal Singh
// @match https://en.wikipedia.org/wiki/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=wikipedia.com
// @grant GM_xmlhttpRequest
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
/* global $ */
var OMDB_API_KEY = ''
var IMDB_FAVICON = 'data:image/x-icon;base64,AAABAAEAEBAQAAAAAAAoAQAAFgAAACgAAAAQAAAAIAAAAAEA' +
'BAAAAAAAgAAAAAAAAAAAAAAAEAAAAAAAAAAAP0cAAAAAACPQ6AAAhqEAAoeZADvo/wAAeZkAAGFuAAC2zwAio8UA' +
'ENHrAAAAAAAAAAAAAAAAAAAAAAAAAAAAERERERERERERERERERERERFmZmZmZmYRFoiIiIiIiGFlqqqqqqqohmUU' +
'GBQRNBdGZRQYFBMUEEZlFBEUGBQRRmUUFxQYFBeGZRQXFBMUGYZlFBkUETQahmVaqqoqqqqGFlVVVVVVVWERZmZm' +
'ZmZmERERERERERERERERERERERH//wAA//8AAMADAACAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
'AACAAQAAwAMAA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ushDAAAAAAAAAAAAAAAAAwhKypOvG1or' +
'JM7j2naaxllIQwAAAAAAAAAAAAAAAAAAAw0DAZZTheDNMwrGU4lIQwAAAAAAAAAAAAAAAAAAAAAAAAMDAwz17Ozl' +
'6UMDAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDAwMDAAAAAAAAAAAAAAAAAA//wf///AA///AAD//gAAP/wAAB' +
'/4AAAP8AAAB+AAAAfAAAADwAAAAcAAAAGAAAABgAAAAYAAAACAAAAAgAAAAIAAAACAAAAAgAAAAIAAAAGAAAABwA' +
'AAAcAAAAHAAAAD4AAAB/AAAAfwAAAP+AAAH/4AAD//AAD//8AD///8H/8=';
var RATING_TO_FAVICON = {
'Internet Movie Database': IMDB_FAVICON,
'Rotten Tomatoes': ROTTEN_TOMATOES_FAVICON,
'Metacritic': METACRITIC_FAVICON
};
(function() {
'use strict';
var imdb_links = [];
var links = document.getElementsByTagName("a");
for(var i=0, max=links.length; i<max; i++) {
if (links[i].href.indexOf("https://www.imdb.com/title/") !== -1){
imdb_links.push(links[i].href);
}
}
if (imdb_links.length == 0) {
console.warn("No IMDB URL found on the page")
return
}
var url_obj = new URL(imdb_links[0])
if (url_obj.pathname.split(/\//).length < 3) {
console.warn("IMDB URL doesn't contain a title ID")
return
}
if (OMDB_API_KEY.length == 0) {
console.warn("OMDB_API_KEY is not defined")
return
}
var title_id = url_obj.pathname.split(/\//)[2]
var res = GM_xmlhttpRequest({
method: "Get",
url: `http://www.omdbapi.com/?i=${title_id}&apikey=${OMDB_API_KEY}`,
onload: function (response) {
var movie_info = JSON.parse(response.responseText)
console.log (movie_info);
var wiki_title = $('#firstHeading');
var ratingContainer = $('<div id="ratingContainer"></div>');
createRatings(ratingContainer, movie_info.Ratings);
ratingContainer.insertBefore(wiki_title);
ratingContainer.css({"float": "right", "padding": "10px 0 10px 0", "display": "flex"});
}
})
}
)();
function createRatings(ratingContainer, ratings) {
for (var key in ratings) {
if (ratings[key].Source in RATING_TO_FAVICON) {
$("<img />")
.attr("src", (RATING_TO_FAVICON[ratings[key].Source]))
.attr("alt", "IMBD")
.attr("width", "20")
.attr("height", "20")
.appendTo(ratingContainer);
$("<p />")
.text(ratings[key].Value)
.attr("display", "inline")
.attr("style", "padding: 0px 10px 0px 10px")
.appendTo(ratingContainer);
}
}
}