· 6 years ago · Jan 14, 2020, 09:44 AM
1// ==UserScript==
2// @name Blackpearl IMDB
3// @version 3.0.0
4// @description Template Maker
5// @author Blackpearl_Team
6// @icon https://blackpearl.biz/favicon.png
7// @homepage https://github.com/BlackPearl-Forum/Blackpearl-Template-Poster/
8// @supportURL https://github.com/BlackPearl-Forum/Blackpearl-Template-Poster/issues/
9// @updateURL https://github.com/BlackPearl-Forum/Blackpearl-Template-Poster/raw/master/script.user.js
10// @downloadURL https://github.com/BlackPearl-Forum/Blackpearl-Template-Poster/raw/master/script.user.js
11// @include /^https:\/\/blackpearl\.biz\/forums\/(129|172|173|174|175|176|178|179|180|181|182|183|184|187|188|189|190|193|194|197|198|199|200|203|204|206|207|208|210|223)\/post-thread/
12// @require https://code.jquery.com/jquery-3.4.1.min.js
13// @require https://code.jquery.com/ui/1.12.1/jquery-ui.js
14// @require https://raw.githubusercontent.com/Semantic-Org/UI-Search/master/search.js
15// @require https://raw.githubusercontent.com/Semantic-Org/UI-Api/master/api.js
16// @grant GM_addStyle
17// @grant GM_xmlhttpRequest
18// @grant GM_setClipboard
19// @grant GM.setValue
20// @grant GM.getValue
21// ==/UserScript==
22
23var Generate_Template = `
24<button id="gmShowTemplate" name="template_button" style="display:none" type="button">Show</button>
25<div id="OmdbGenerator">
26<input type="text" id="hiddenIID" value="" style="display:none">
27<div class="ui search">
28<input type="text" class="prompt input" id="searchID" placeholder="IMDB ID or Title" onfocus="this.placeholder = ''" onblur="this.placeholder = 'IMDB ID or Title'">
29<div class="results input" style="display:none"></div>
30</div>
31<input type="text" id="screensLinks" value="" class="input" placeholder="Screenshot Links" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Screenshot Links'">
32<input type="text" id="ytLink" value="" class="input" placeholder="Youtube Trailer Link" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Youtube Trailer Link'">
33<input type="text" id="ddl" value="" class="input" placeholder="Download Link" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Download Link'">
34<textarea rows="1" style="width:100%;" class="input" id="Media_Info" placeholder="Mediainfo" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Mediainfo'"></textarea>
35<div id="textarea_divider"> </div>
36<span>DownCloud</span>
37<label class="switch">
38<input type="checkbox" id="Downcloud" value="Downcloud" checked></input>
39<span class="slider round"></span></label>
40HideReactScore
41<input type="number" id="HideReactScore" min="0" max="100" value="0">
42HidePosts
43<input type="number" id="HidePosts" min="0" max="50" value="0"> <br>
44<div id="textarea_divider"> </div>
45<button id="gmGenerate" name="template_button" type="button">Generate Template</button>
46<button id="gmClearBtn" name="template_button" type="reset">Clear</button>
47<button id="gmHideTemplate" name="template_button" type="button">Hide</button>
48</div>
49`
50
51var omdbinput = `
52<button id="gmShowTemplate" name="template_button" style="display:none" type="button">Show</button>
53<div id="OmdbGenerator">
54<label>Enter Your OMDB API Key, Then Click On Save :)</label>
55<input type="text" id="omdbKey" value="" class="input" placeholder="Omdb API Key">
56<button id="gmGenerate" name="template_button" onClick="window.location.reload();" type="button">Save Key</button>
57<button id="gmClearBtn" name="template_button" type="reset">Clear</button>
58<button id="gmHideTemplate" name="template_button" type="button">Hide</button>
59</div>
60`
61
62GM.getValue("APIKEY", "foo").then(value => { const APIVALUE = value
63if (APIVALUE !== 'foo'){
64 var temphtml = document.getElementsByTagName("dd")[0];
65 temphtml.innerHTML += Generate_Template;
66} else {
67 temphtml = document.getElementsByTagName("dd")[0];
68 temphtml.innerHTML += omdbinput;
69}
70
71GM.getValue("APIKEY", "foo").then(value => {
72 const APIKEY = value
73 var url_check = window.location.href;
74 var section_check = url_check.match(/\d+/, '');
75 var Movies = "204 183 184 172 173 174 175 176 178 179 180 181 182 202 129";
76 var Series = "208 206 193 194 187 188 189 190 197 198 199 200 203 209 223";
77 if (Series.includes(section_check)){
78 query = `https://www.omdbapi.com/?apikey=${APIKEY}&r=JSON&s={query}&type=series`
79 } else if (Movies.includes(section_check)) {
80 query = `https://www.omdbapi.com/?apikey=${APIKEY}&r=JSON&s={query}&type=movie`
81 } else {
82 query = `https://www.omdbapi.com/?apikey=${APIKEY}&r=JSON&s={query}`
83 }
84 $('.ui.search')
85 .search({
86 type : 'category',
87 apiSettings: {
88 url: query,
89 onResponse : function(myfunc) {
90 var
91 response = {
92 results : {}
93 };
94 $.each(myfunc.Search, function(index, item) {
95 var
96 category = item.Type.toUpperCase() || 'Unknown',
97 maxResults = 10;
98 if(index >= maxResults) {
99 return false;
100 }
101 if(response.results[category] === undefined) {
102 response.results[category] = {
103 name : "~~~~~~~~~~"+category+"~~~~~~~~~~",
104 results : []
105 };
106 }
107 var Name = item.Title +" ("+ item.Year+")";
108 response.results[category].results.push({
109 title : Name,
110 description : Name,
111 imdbID : item.imdbID
112 });
113 });
114 return response;
115 }
116 },
117 fields: {
118 results : 'results',
119 title : 'name',
120 },
121 onSelect: function(response){
122 $('#hiddenIID').val(response.imdbID);
123 $('#searchID').val(response.title);
124 },
125 minCharacters : 3
126 });
127
128 $(document).on('keydown', function(event) {
129 if (event.key == "Escape") {
130 $("#OmdbGenerator").hide ();
131 document.getElementById("gmShowTemplate").style.display = "block";
132 }
133 });
134
135 $("#gmHideTemplate").click ( function () {
136 document.getElementById("gmShowTemplate").style.display = "block";
137 $("#OmdbGenerator").hide ();
138 });
139
140 $("#gmShowTemplate").click ( function () {
141 document.getElementById("gmShowTemplate").style.display = "none";
142 $("#OmdbGenerator").show ();
143 });
144 //--- Use jQuery to activate the dialog buttons.
145 $("#gmGenerate").click ( function () {
146 var omdbkey = $("#omdbKey").val ();
147 var IID = $("#hiddenIID").val ();
148 var screenshots = $("#screensLinks").val ();
149 var uToob = $("#ytLink").val ();
150 var ddl = $("#ddl").val ();
151 var MEDIAINFO = $("#Media_Info").val ();
152 var hidereactscore = $("#HideReactScore").val ();
153 var hideposts = $("#HidePosts").val ();
154 if (APIKEY == "foo") {
155 if (omdbkey) {
156 GM.setValue("APIKEY", omdbkey);
157 } else {
158 alert("You Didn't Enter Your Key!!")
159 }
160 } else {
161 if (!IID){
162 IID = $("#searchID").val ();
163 if (IID.includes("imdb")) {
164 IID = IID.match(/tt\d+/)[0];
165 }
166 }
167 if (!IID) {
168 alert("You Didn't Select A Title or Enter a IMDB ID!");
169 } else if (!ddl) {
170 alert("Uh Oh! You Forgot Your Download Link! That's Pretty Important...");
171 } else if (!MEDIAINFO){
172 alert("You Don't Have Any Mediainfo? It's Required!");
173 } else {
174 if (Downcloud.checked){
175 var ddlsplit = ddl.split(" ");
176 ddl = ''
177 for (var dls of ddlsplit) {
178 ddl += `[DOWNCLOUD]${dls}[/DOWNCLOUD]\n`;
179 }
180 } else {
181 ddl = ddl.replace(/\ /g, '\n');
182 }
183 ddl = '[HIDEREACT=1,2,3,4,5,6]\n' + ddl + '\n[/HIDEREACT]'
184 if (hidereactscore !== "0"){
185 ddl = `[HIDEREACTSCORE=${hidereactscore}]` + ddl + '[/HIDEREACTSCORE]'
186 }
187 if (hideposts !== "0"){
188 ddl = `[HIDEPOSTS=${hideposts}]` + ddl + '[/HIDEPOSTS]'
189 }
190 if (screenshots) {
191 screenshots = screenshots.split(" ");
192 var screen = `\n[hr][/hr][indent][size=6][color=rgb(250, 197, 28)][b]Screenshots[/b][/color][/size][/indent]\n [Spoiler='screenshots']`;
193 for (var ss of screenshots) {
194 screen += `[img]${ss}[/img]`;
195 }
196 screen += `[/Spoiler] \n`;
197 } else {
198 screen = ""
199 }
200 if (uToob.match(/[a-z]/)) {
201 var trailer = `\n[hr][/hr][indent][size=6][color=rgb(250, 197, 28)][b]Trailer[/b][/color][/size][/indent]\n ${uToob}`
202 } else {
203 trailer = ""
204 }
205 GM_xmlhttpRequest({
206 method: "GET",
207 url: `http://www.omdbapi.com/?apikey=${APIKEY}&i=${IID}&plot=full&y&r=json`,
208 onload: function(response) {
209 var json = JSON.parse(response.responseText);
210 if (json.Poster && json.Poster !== "N/A"){
211 var poster = "[center][img] " + json.Poster + " [/img]\n";
212 } else {
213 poster = ''
214 }
215 if (json.Title && json.Title !== "N/A"){
216 var title = "[color=rgb(250, 197, 28)][b][size=6] " + json.Title;
217 } else {
218 alert("You Messed Up! Check That You've Entered Something Into The IMDB Field!")
219 }
220 if (json.Year && json.Year !== "N/A"){
221 var year = json.Year + ")[/size][/b][/color]\n";
222 } else {
223 year = ''
224 }
225 if (json.imdbID && json.imdbID !== "N/A"){
226 var imdb_id = "[url=https://www.imdb.com/title/" + json.imdbID + "][img]https://i.imgur.com/rcSipDw.png[/img][/url]";;
227 } else {
228 imdb_id = ''
229 }
230 if (json.imdbRating && json.imdbRating !== "N/A"){
231 var rating = "[size=6][b]" + json.imdbRating + "[/b]/10[/size]\n";
232 } else {
233 rating = ''
234 }
235 if (json.imdbVotes && json.imdbVotes !== "N/A"){
236 var imdbvotes = "[size=6][img]https://i.imgur.com/sEpKj3O.png[/img]" + json.imdbVotes + "[/size][/center]\n";
237 } else {
238 imdbvotes = ''
239 }
240 if (json.Plot && json.Plot !== "N/A"){
241 var plot = "[hr][/hr][indent][size=6][color=rgb(250, 197, 28)][b]Plot[/b][/color][/size][/indent]\n\n " + json.Plot;
242 } else {
243 plot = ''
244 }
245 if (json.Rated && json.Rated !== "N/A"){
246 var rated = "[B]Rating: [/B]" + json.Rated + "\n";
247 } else {
248 rated = ''
249 }
250 if (json.Genre && json.Genre !== "N/A"){
251 var genre = "[*][B]Genre: [/B] " + json.Genre + "\n";
252 } else {
253 genre = ''
254 }
255 if (json.Director && json.Director !== "N/A"){
256 var director = "[*][B]Directed By: [/B] " + json.Director + "\n";
257 } else {
258 director = ''
259 }
260 if (json.Writer && json.Writer !== "N/A"){
261 var writer = "[*][B]Written By: [/B] " + json.Writer + "\n";
262 } else {
263 writer = ''
264 }
265 if (json.Actors && json.Actors !== "N/A"){
266 var actors = "[*][B]Starring: [/B] " + json.Actors + "\n";
267 } else {
268 actors = ''
269 }
270 if (json.Released && json.Released !== "N/A"){
271 var released = "[*][B]Release Date: [/B] " + json.Released + "\n";
272 } else {
273 released = ''
274 }
275 if (json.Runtime && json.Runtime !== "N/A"){
276 var runtime = "[*][B]Runtime: [/B] " + json.Runtime + "\n";
277 } else {
278 runtime = ''
279 }
280 if (json.Production && json.Production !== "N/A"){
281 var production = "[*][B]Production: [/B] " + json.Production + "\n";
282 } else {
283 production = ''
284 }
285 MEDIAINFO = "[hr][/hr][indent][size=6][color=rgb(250, 197, 28)][b]Media Info[/b][/color][/size][/indent]\n [spoiler='Click here to view Media Info']\n " + MEDIAINFO + "\n[/spoiler]\n"
286 ddl = "[hr][/hr][center][size=6][color=rgb(250, 197, 28)][b]Download Link[/b][/color][/size]\n" + ddl + "\n[/center]"
287 var dump = `${poster}${title} (${year}${imdb_id} ${rating}${imdbvotes}${plot}${trailer}${screen}
288[hr][/hr][indent][size=6][color=rgb(250, 197, 28)][b]Movie Info[/b][/color][/size][/indent]
289[LIST][*]${rated}${genre}${director}${writer}${actors}${released}${runtime}${production}[/LIST]\n${MEDIAINFO}${ddl}`;
290 GM_setClipboard (dump);
291 try {
292 document.getElementsByName("message")[0].value = dump;
293 } catch(err) {
294 alert('You should be running this in BBCode Mode. Check the Readme for more information!\n' + err);
295 } finally {
296 var xf_title_value = document.getElementById("title").value;
297 if (!xf_title_value){
298 document.getElementById("title").value = json.Title + " (" + json.Year + ")";
299 }
300 }
301 }
302 })
303 }
304 }
305 });
306});
307
308//--- CSS styles make it work...
309GM_addStyle ( " \
310 @media screen and (min-width: 300px) { \
311 /* Divide Buttons */ \
312 .divider{ \
313 width: 8px; \
314 height: auto; \
315 display: inline-block; \
316 } \
317 /* Buttons */ \
318 button[name=template_button] { \
319 background-color: #4caf50; \
320 color: white; \
321 text-align: center; \
322 text-decoration: none; \
323 display: inline-block; \
324 font-size: 14px; \
325 font-weight: 600; \
326 padding: 4px; \
327 cursor: pointer; \
328 outline: none; \
329 margin-right: 8px; \
330 border: none; \
331 border-radius: 3px; \
332 border-color: #67bd6a; \
333 margin-top: 5px; \
334 box-shadow: 0 0 2px 0 rgba(0,0,0,0.14), \
335 0 2px 2px 0 rgba(0,0,0,0.12), \
336 0 1px 3px 0 rgba(0,0,0,0.2); \
337 } \
338 /* Reactscore & Posts */ \
339 input[type=number]{ \
340 border-bottom: 2px solid teal; \
341 border-image: linear-gradient(to right, #11998e,#38ef7d);\
342 border-image-slice: 1; \
343 background: transparent; \
344 color: white; \
345 max-width: 35px; \
346 } \
347 #textarea_divider { \
348 margin-top: -11px; \
349 } \
350 /* Start Rounded sliders Checkboxes */ \
351 .switch { \
352 position: relative; \
353 display: inline-block; \
354 width: 42px; \
355 height: 17px; \
356 } \
357 .switch input { \
358 opacity: 0; \
359 width: 0; \
360 height: 0; \
361 } \
362 .slider { \
363 position: absolute; \
364 cursor: pointer; \
365 top: 0; \
366 left: 0; \
367 right: 0; \
368 bottom: 0; \
369 background-color: #ccc; \
370 -webkit-transition: .4s; \
371 transition: .4s; \
372 } \
373 .slider:before { \
374 position: absolute; \
375 content: ''; \
376 height: 13px; \
377 width: 13px; \
378 left: 2px; \
379 bottom: 2px; \
380 background-color: #42464D; \
381 -webkit-transition: .4s; \
382 transition: .4s; \
383 } \
384 input:checked + .slider { \
385 background-color: #4caf50; \
386 } \
387 input:focus + .slider { \
388 box-shadow: 0 0 1px #4caf50; \
389 } \
390 input:checked + .slider:before { \
391 -webkit-transform: translateX(26px); \
392 -ms-transform: translateX(26px); \
393 transform: translateX(26px); \
394 } \
395 .slider.round { \
396 border-radius: 34px; \
397 } \
398 .slider.round:before { \
399 border-radius: 50%; \
400 } \
401} \
402 @media screen and (min-width: 768px) { \
403 /* Divide Buttons */ \
404 .divider{ \
405 width: 15px; \
406 height: auto; \
407 display: inline-block; \
408 } \
409 /* Buttons */ \
410 button[name=template_button] { \
411 background-color: #4caf50; \
412 color: white; \
413 text-align: center; \
414 text-decoration: none; \
415 display: inline-block; \
416 font-size: 15px; \
417 font-weight: 600; \
418 padding: 6px; \
419 cursor: pointer; \
420 outline: none; \
421 margin-right: 8px; \
422 border: none; \
423 border-radius: 3px; \
424 border-color: #67bd6a; \
425 margin-top: 5px; \
426 box-shadow: 0 0 2px 0 rgba(0,0,0,0.14), \
427 0 2px 2px 0 rgba(0,0,0,0.12), \
428 0 1px 3px 0 rgba(0,0,0,0.2); \
429 } \
430 /* Reactscore & Posts */ \
431 input[type=number]{ \
432 border-bottom: 2px solid teal; \
433 border-image: linear-gradient(to right, #11998e,#38ef7d);\
434 border-image-slice: 1; \
435 background: transparent; \
436 color: white; \
437 max-width: 35px; \
438 } \
439 #textarea_divider { \
440 margin-top: -11px; \
441 } \
442 .switch { \
443 position: relative; \
444 display: inline-block; \
445 width: 42px; \
446 height: 17px; \
447 } \
448 .switch input { \
449 opacity: 0; \
450 width: 0; \
451 height: 0; \
452 } \
453 .slider { \
454 position: absolute; \
455 cursor: pointer; \
456 top: 0; \
457 left: 0; \
458 right: 0; \
459 bottom: 0; \
460 background-color: #ccc; \
461 -webkit-transition: .4s; \
462 transition: .4s; \
463 } \
464 .slider:before { \
465 position: absolute; \
466 content: ''; \
467 height: 13px; \
468 width: 13px; \
469 left: 2px; \
470 bottom: 2px; \
471 background-color: #42464D; \
472 -webkit-transition: .4s; \
473 transition: .4s; \
474 } \
475 input:checked + .slider { \
476 background-color: #4caf50; \
477 } \
478 input:focus + .slider { \
479 box-shadow: 0 0 1px #4caf50; \
480 } \
481 input:checked + .slider:before { \
482 -webkit-transform: translateX(26px); \
483 -ms-transform: translateX(26px); \
484 transform: translateX(26px); \
485 } \
486 /* Rounded sliders */ \
487 .slider.round { \
488 border-radius: 34px; \
489 } \
490 .slider.round:before { \
491 border-radius: 50%; \
492 } \
493} \
494")});