slideshow

View Imgur media in a slideshow format

  1. // ==UserScript==
  2. // @name slideshow
  3. // @namespace https://greatest.deepsurf.us/en/users/94062-oshaw
  4. // @version 3
  5. // @description View Imgur media in a slideshow format
  6. // @author Oscar Shaw
  7. // @grant none
  8. // @include https://*.reddit.*/r/*
  9. // @include http://imgur.com/*
  10. // @include https://imgur.com/*
  11. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
  12. // @run-at document-start
  13. // ==/UserScript==
  14.  
  15. /* "name": "library.js",
  16. "program": "Slideshow",
  17. "description": ""
  18. */
  19.  
  20. function say(str_input, tab_input = window) {
  21. tab_input.console.log(str_input);
  22. } say("Compiled");
  23. function list(arrkvp_input, tab_input = window) {
  24. var str_output = "";
  25. for (var i = 0; i < arrkvp_input.length; i++) {
  26. str_output += (
  27. arrkvp_input[i][0] + ": \t\t"
  28. + arrkvp_input[i][1] + "\n"
  29. );
  30. }
  31. say(str_output, tab_input);
  32. }
  33. function shout(str_input, tab_input = window) {
  34. tab_input.alert(str_input);
  35. }
  36. function tag(str_element, tab_input = window) {
  37. switch (str_element[0]) {
  38. case '.': return tab_input.document.getElementsByClassName(str_element.substring(1));
  39. case '#': return tab_input.document.getElementById(str_element.substring(1));
  40. default: return;
  41. }
  42. }
  43. function sayTab(str_body, str_title = "") {
  44. window.open().document.body.appendChild(document.createElement('pre')).innerHTML
  45. = (str_title != "" ? str_function + "\n\n" : "")
  46. + str_body;
  47. }
  48. function tryCatch(anon) {
  49. try { anon(); }
  50. catch(str_error) { say(str_error); }
  51. }
  52. function isDef(var_input) {
  53. return !(var_input == null || var_input == undefined || var_input == "");
  54. }
  55. function func_xhr(obj_input) {
  56. say("func_xhr requesting " + obj_input.url_destination);
  57. var xhr = new XMLHttpRequest();
  58. xhr.onload = function() {
  59. try { var json = JSON.parse(this.responseText); }
  60. catch(str_error) {
  61. say("func_error\n\n" + str_error + "\n\n" + this.responseText);
  62. obj_input.func_error(str_error);
  63. }
  64. if (!isDef(json.status)) obj_input.func_success(json);
  65. if (json.status == 200) {
  66. say("func_success");
  67. obj_input.func_success(json);
  68. }
  69. else {
  70. say("func_failure");
  71. obj_input.func_failure(json.status);
  72. }
  73. };
  74. xhr.open("GET", obj_input.url_destination, true);
  75. if (obj_input.str_headerKey != undefined && obj_input.str_headerValue != undefined) {
  76. xhr.setRequestHeader(
  77. obj_input.str_headerKey,
  78. obj_input.str_headerValue
  79. );
  80. }
  81. xhr.send();
  82. }
  83. function func_htmlUnescape(str_input) {
  84. return str_input
  85. .replace(/&quot;/g, '"')
  86. .replace(/&#39;/g, "'")
  87. .replace(/&lt;/g, '<')
  88. .replace(/&gt;/g, '>')
  89. .replace(/&amp;/g, '&');
  90. }
  91.  
  92. /* "name": "parsers.js",
  93. "program": "Slideshow",
  94. "description": ""
  95. */
  96.  
  97. function func_imgurUrlToJson(url_input, func_callback, arrstr_endpoints = ["append", "album", "image"]) {
  98. const constr_imgurApiId = "b5abfbf0e29baf1";
  99. var hash_source = url_input.substring(url_input.lastIndexOf("/") + 1);
  100. var anon_request = function(str_endpoint, func_next) {
  101. var obj_xhrInputs;
  102. switch(str_endpoint) {
  103. case "append": {
  104. obj_xhrInputs = { url_destination: url_input + ".json" }
  105. break;
  106. }
  107. case "album": {
  108. obj_xhrInputs = {
  109. url_destination: "https://api.imgur.com/3/album/" + hash_source
  110. , str_headerKey: "Authorization"
  111. , str_headerValue: "Client-ID " + constr_imgurApiId
  112. }
  113. break;
  114. }
  115. case "image": {
  116. obj_xhrInputs = {
  117. url_destination: "https://api.imgur.com/3/image/" + hash_source
  118. , str_headerKey: "Authorization"
  119. , str_headerValue: "Client-ID " + constr_imgurApiId
  120. }
  121. break;
  122. }
  123. default: break;
  124. }
  125. func_xhr({
  126. url_destination: obj_xhrInputs.url_destination
  127. , func_success: function(json_response) { func_callback(json_response); }
  128. , func_error: func_next
  129. , func_failure: func_next
  130. , str_headerKey: obj_xhrInputs.str_headerKey
  131. , str_headerValue: obj_xhrInputs.str_headerValue
  132. });
  133. };
  134. var i = 0;
  135. anon_request(arrstr_endpoints[i], function() {
  136. if (isDef(arrstr_endpoints[i + 1])) {
  137. i++;
  138. anon_request(arrstr_endpoints[i], function() {
  139. if (isDef(arrstr_endpoints[i + 1])) {
  140. i++;
  141. anon_request(arrstr_endpoints[i]);
  142. }
  143. });
  144. }
  145. }, function() {
  146. if (isDef(arrstr_endpoints[i + 1])) {
  147. i++;
  148. anon_request(arrstr_endpoints[i], function() {
  149. if (isDef(arrstr_endpoints[i + 1])) {
  150. i++;
  151. anon_request(arrstr_endpoints[i]);
  152. }
  153. });
  154. }
  155. });
  156. }
  157. function func_imgurJsonToSsdn(json_input) {
  158. say("func_imgur_jsonToSsdn");
  159. var bool_isAppend = json_input.data.hasOwnProperty("image");
  160. var node_inputHeader = bool_isAppend ? json_input.data.image : json_input.data;
  161. var node_imageArray = bool_isAppend ? json_input.data.image.album_images.images : json_input.data.images;
  162. var ssdn_output = {
  163. node_header:
  164. {
  165. str_title: (node_inputHeader.title === null) ? "" : node_inputHeader.title
  166. , str_description: (node_inputHeader.description === null) ? "" : node_inputHeader.description
  167. , str_poster: node_inputHeader.account_url
  168. , int_length: bool_isAppend ? node_inputHeader.num_images : node_inputHeader.images_count
  169. , int_views: node_inputHeader.views
  170. , int_points: node_inputHeader.points
  171. , int_ups: node_inputHeader.ups
  172. , int_downs: node_inputHeader.downs
  173. }
  174. , node_payload: []
  175. };
  176. var int_outputLength = ssdn_output.node_header.int_length;
  177. ssdn_output.node_header.int_length = (int_outputLength == null) ? 1 : int_outputLength;
  178. if (ssdn_output.node_header.int_length > 1) { // If album
  179. $.each(node_imageArray, function(i, node_image) {
  180. ssdn_output.node_payload.push({
  181. str_title: (node_image.title === null) ? "" : node_image.title
  182. , str_description: (node_image.description === null) ? "" : node_image.description
  183. , url_direct: bool_isAppend ? "http://i.imgur.com/" + node_image.hash + node_image.ext : node_image.link
  184. });
  185. });
  186. }
  187. else { // If image
  188. ssdn_output.node_payload.push({
  189. str_title: undefined
  190. , str_description: undefined
  191. , url_direct: node_inputHeader.link
  192. });
  193. }
  194. say("func_imgur_jsonToSsdn payload completed");
  195. return ssdn_output;
  196. }
  197. function class_redditParser(url_input, func_send) {
  198. function func_stringToUrlArray(str_input) {
  199. // say("func_stringToUrlArray");
  200. var array_urls = [];
  201. if (isDef(str_input.match(/http(.*?)(?=["?])/g))) {
  202. $.each(str_input.match(
  203. /http(.*?)(?=["?])/g
  204. ), function(i, url) { array_urls.push(url); });
  205. }
  206. // say("func_stringToUrlArray completed");
  207. return array_urls;
  208. }
  209. function func_isUrlImageDirect(url_input) {
  210. return (url_input.indexOf(".jpg") != -1
  211. || url_input.indexOf(".png") != -1
  212. || url_input.indexOf(".gif") != -1);
  213. }
  214. function func_redditThreadHeaderToSsdnHeader(json_redditHeader) {
  215. return {
  216. node_header: {
  217. str_title: json_redditHeader.title
  218. }
  219. };
  220. }
  221. function func_urlWithRedditContextToSsdnPayload(url, json_redditComment) {
  222. return {
  223. node_payload:
  224. [
  225. {
  226. str_title: json_redditComment.author
  227. , str_description: func_htmlUnescape(json_redditComment.body_html)
  228. , int_points: json_redditComment.score
  229. , url_direct: url
  230. }
  231. ]
  232. };
  233. }
  234. function func_main() {
  235. func_xhr({ url_destination: url_input + ".json", func_success: function(json_reddit) {
  236. { func_send( // Fabricate and send header
  237. func_redditThreadHeaderToSsdnHeader
  238. (json_reddit[0].data.children[0].data)
  239.  
  240. ); }
  241. $.each(json_reddit[1].data.children, function(i, json_comment) { // Each comment
  242. if (!isDef(json_comment.data.body_html)) return;
  243. $.each(func_stringToUrlArray(json_comment.data.body_html), function(j, url) {
  244. if (func_isUrlImageDirect(url)) { // Direct
  245. { func_send(
  246. func_urlWithRedditContextToSsdnPayload
  247. (url, json_comment.data)
  248. ); }
  249. }
  250. else if (url.indexOf("imgur") != -1) { // Indirect
  251. func_imgurUrlToJson(url, function(json_indirectUrlResponse) {
  252. $.each(json_indirectUrlResponse.data.images,
  253. function(k, json_imgurImage) {
  254. ssdn_output = func_urlWithRedditContextToSsdnPayload(
  255. json_imgurImage.link,
  256. json_comment.data);
  257. var node_image = ssdn_output.node_payload[0];
  258. node_image.int_index = k + 1;
  259. node_image.int_length = json_indirectUrlResponse.data.images.length;
  260. node_image.url_album = url;
  261. func_send(ssdn_output);
  262. });
  263. }, ["album", "image"]);
  264. }
  265. }); // Next url in comment
  266. }); // Next comment
  267. }});
  268. } func_main();
  269. say("class_redditParser completed");
  270. }
  271.  
  272. /* "name": "slideshow.js",
  273. "program": "Slideshow",
  274. "description": ""
  275. */
  276.  
  277. function class_slideshow(tab) {
  278. const contab_home = tab;
  279. var css_head = ""; { // CSS
  280. { css_head +=
  281. "\
  282. <script type='text/javascript' src='http://ajax.googleapis.com/\
  283. ajax/libs/jquery/1.4.1/jquery.min.js'></script>\
  284. "; }
  285. { css_head += "<title></title><style>"; }
  286. { css_head += // #ctn_main, #ctn_image,
  287. "\
  288. #ctn_main\
  289. {\
  290. top: 0px;\
  291. right: 0px;\
  292. height: " + contab_home.innerHeight + "px;\
  293. width: " + contab_home.innerWidth + "px;\
  294. position: absolute;\
  295. }\
  296. #ctn_image\
  297. {\
  298. height: " + contab_home.innerHeight + "px;\
  299. width: 100%;\
  300. }\
  301. #act_image\
  302. {\
  303. display: block;\
  304. height: " + contab_home.innerHeight + "px;\
  305. width: 100%;\
  306. position: absolute;\
  307. background-position: center center;\
  308. background-repeat: no-repeat;\
  309. background-size: contain;\
  310. z-index: 1;\
  311. }\
  312. "; }
  313. { css_head += // .grp_details
  314. "\
  315. .grp_textBoxes\
  316. {\
  317. margin: 0px;\
  318. text-align: center;\
  319. }\
  320. .grp_details\
  321. {\
  322. display: none;\
  323. z-index: 1;\
  324. }\
  325. .grp_bold\
  326. {\
  327. font-weight: bold;\
  328. }\
  329. #ctn_header\
  330. {\
  331. width: 100%;\
  332. }\
  333. #act_header\
  334. {\
  335. box-sizing: border-box;\
  336. padding-top: 0px;\
  337. padding-bottom: 7px;\
  338. padding-left: 45px;\
  339. padding-right: 45px;\
  340. }\
  341. #ctn_footer\
  342. {\
  343. width: 100%;\
  344. }\
  345. #act_footer\
  346. {\
  347. box-sizing: border-box;\
  348. padding-top: 10px;\
  349. padding-bottom: 10px;\
  350. padding-left: 45px;\
  351. padding-right: 45px;\
  352. bottom: 0px;\
  353. width: 100%;\
  354. }\
  355. #p_imageNumbers\
  356. {\
  357. display: none;\
  358. }\
  359. ul\
  360. {\
  361. padding: 0px;\
  362. margin: 0px;\
  363. }\
  364. ol\
  365. {\
  366. padding: 0px;\
  367. margin: 0px;\
  368. }\
  369. p\
  370. {\
  371. padding: 0px;\
  372. margin: 0px;\
  373. }\
  374. "; }
  375. { css_head += // .grp_navButtons
  376. "\
  377. .grp_navButtons\
  378. {\
  379. top: 0px;\
  380. display: none;\
  381. line-height: " + contab_home.innerHeight + "px;\
  382. height: 100%;\
  383. margin: 0px;\
  384. cursor: pointer;\
  385. text-align: center;\
  386. vertical-align: middle;\
  387. position: absolute;\
  388. z-index: 10;\
  389. }\
  390. #btn_prev\
  391. {\
  392. left: 0px;\
  393. padding-left: 15px;\
  394. padding-right: 15px;\
  395. }\
  396. #btn_next\
  397. {\
  398. padding-left: 15px;\
  399. padding-right: 15px;\
  400. right: 0px;\
  401. }\
  402. "; }
  403. { css_head += // css_head suffix
  404. "\
  405. </style>\
  406. "; }
  407. }
  408. var html_body = ""; { // HTML
  409. { html_body += // #ctn_main prefix
  410. "\
  411. <div id = 'ctn_main'>\
  412. "; }
  413. { html_body += // #ctn_header
  414. "\
  415. <div class = 'grp_details' id = 'ctn_header'>\
  416. <div id = 'act_header'>\
  417. <h1 class = 'grp_textBoxes' id = 'h1_title'></h1>\
  418. <p class = 'grp_textBoxes' id = 'p_subtitle'></p>\
  419. </div>\
  420. </div>\
  421. "; }
  422. { html_body += // #ctn_image
  423. "\
  424. <div class = 'grp_image' id = 'ctn_image'>\
  425. <div class = 'grp_image' id = 'act_image'></div>\
  426. </div>\
  427. "; }
  428. { html_body += // #ctn_footer
  429. "\
  430. <div class = 'grp_details' id = 'ctn_footer'>\
  431. <div id = 'act_footer'>\
  432. <p class = 'grp_textBoxes' id = 'p_desc'></p>\
  433. <p class = 'grp_textBoxes grp_bold' id = 'p_imageNumbers'></p>\
  434. </div>\
  435. </div>\
  436. "; }
  437. { html_body += // #ctn_main suffix, .grp_navButtons,
  438. "\
  439. <div class = 'grp_navButtons' id = 'btn_prev'></div>\
  440. <div class = 'grp_navButtons' id = 'btn_next'></div>\
  441. </div>\
  442. "; }
  443. }
  444. var ssdn_source = { node_header: {}, node_payload: [] };
  445. var int_imageCurrent = 0;
  446. var bool_detailsDisplay = false;
  447. function func_detailsDisplay(bool_newDetailsDisplay = bool_detailsDisplay) {
  448. bool_detailsDisplay = bool_newDetailsDisplay;
  449. if (bool_detailsDisplay) { // Show
  450. var int_allocateHeightHeader = 0;
  451. var int_allocateHeightFooter = 0;
  452. { var bool_showHeader =
  453. isDef(tag("#h1_title", contab_home).textContent)
  454. || isDef(tag("#p_subtitle", contab_home).textContent)
  455. };
  456. { var bool_showFooter =
  457. isDef(tag("#p_desc", contab_home).textContent)
  458. || tag("#p_imageNumbers", contab_home).style.display == "block"
  459. };
  460. if (bool_showHeader) {
  461. tag("#ctn_header", contab_home).style.display = "block";
  462. int_allocateHeightHeader = tag("#ctn_header", contab_home).clientHeight;
  463. }
  464. if (bool_showFooter) {
  465. tag("#ctn_footer", contab_home).style.display = "block";
  466. int_allocateHeightFooter = tag("#act_footer", contab_home).clientHeight;
  467. }
  468. $.each(tag(".grp_image", contab_home), function(i, elmt) {
  469. elmt.style.height = (
  470. contab_home.innerHeight
  471. - int_allocateHeightHeader
  472. - int_allocateHeightFooter
  473. ).toString() + "px";
  474. });
  475. }
  476. else { // Hide
  477. $.each(tag(".grp_details", contab_home), function(i, elmt) {
  478. elmt.style.display = "none";
  479. });
  480. $.each(tag(".grp_image", contab_home), function(i, elmt) {
  481. elmt.style.height = contab_home.innerHeight.toString() + "px";
  482. });
  483. }
  484. say("func_detailsDisplay completed", contab_home);
  485. }
  486. function func_imageDisplay(int_newImageCurrent = int_imageCurrent) {
  487. // If reached end or beginning of album, stop
  488. if (!isDef(ssdn_source.node_payload[int_newImageCurrent])) {
  489. say("func_imageDisplay completed early with " + int_imageCurrent, contab_home);
  490. return;
  491. }
  492. int_imageCurrent = int_newImageCurrent;
  493. var node_image = ssdn_source.node_payload[int_imageCurrent];
  494. { tag("#act_image", contab_home).style.backgroundImage = (
  495. "url("
  496. + ((!isDef(node_image.url_direct)) ? "" : node_image.url_direct)
  497. + ")"
  498. ); }
  499. { tag("#p_desc", contab_home).innerHTML = (
  500. (
  501. (!isDef(node_image.str_title)) ? ""
  502. : ( "<span class = 'grp_bold'>"
  503. + node_image.str_title
  504. + "</span> " )
  505. ) + (
  506. (!isDef(node_image.str_description)) ? ""
  507. : node_image.str_description
  508. )
  509. ); }
  510. { tag("#p_imageNumbers", contab_home).innerHTML = (
  511. (int_imageCurrent + 1).toString()
  512. + " / "
  513. + (
  514. (!isDef(ssdn_source.node_header))
  515. ? ssdn_source.node_payload.length
  516. : (
  517. (!isDef(ssdn_source.node_header.int_length))
  518. ? ssdn_source.node_payload.length
  519. : ssdn_source.node_header.int_length
  520. )
  521. ).toString()
  522. ); }
  523. if (isDef(tag(".md", contab_home)[0])) {
  524. $.each(tag(".md", contab_home)[0].querySelectorAll('a'), function(i, elmt) {
  525. if (elmt.href.indexOf(node_image.url_direct) != -1
  526. || elmt.href.indexOf(node_image.url_album) != -1) {
  527. var str_indexAndLength = "";
  528. if (isDef(node_image.int_index)
  529. && isDef(node_image.int_length)
  530. && (node_image.int_length != 1)) {
  531. str_indexAndLength
  532. = " (" + node_image.int_index + " / "
  533. + node_image.int_length + ")";
  534. }
  535. elmt.innerHTML = (
  536. '<span class = "grp_bold">'
  537. + elmt.innerHTML
  538. + str_indexAndLength
  539. + '</span>'
  540. );
  541. }
  542. });
  543. }
  544. func_detailsDisplay();
  545. }
  546. function func_headerUpdate() {
  547. var node = (!isDef(ssdn_source.node_header))
  548. ? {}
  549. : ssdn_source.node_header;
  550. { (tag("#h1_title", contab_home)).textContent =
  551. (!isDef(node.str_title)) ? ""
  552. : node.str_title;
  553. }
  554. { (tag("#p_subtitle", contab_home)).innerHTML =
  555. ((!isDef(node.str_poster)) ? "" :
  556. "Posted by <span class = 'grp_bold'>\
  557. <a href = 'http://imgur.com/user/"
  558. + node.str_poster + "'>"
  559. + node.str_poster
  560. + "</a></span>"
  561. ) +
  562. ((isDef(node.str_poster) && (isDef(node.int_points)
  563. || isDef(node.int_views))) ? " with " : "") +
  564. ((!isDef(node.int_points)) ? "" :
  565. "<span class = 'grp_bold'>"
  566. + node.int_points
  567. + " point" + ((node.int_points > 1) ? "s" : "") + "</span>"
  568. ) +
  569. ((isDef(node.int_points) && isDef(node.int_views)) ? " and " : "") +
  570. ((!isDef(node.int_views)) ? "" :
  571. "<span class = 'grp_bold'>"
  572. + node.int_views
  573. + " view" + ((node.int_views > 1) ? "s" : "") + "</span>"
  574. )
  575. }
  576. if (isDef(ssdn_source.node_header.str_title)) func_detailsDisplay(true);
  577. contab_home.document.title = ssdn_source.node_header.str_title;
  578. }
  579. function func_pageSetup() {
  580. // contab_home.document.head.innerHTML = css_head ;
  581. // contab_home.document.body.innerHTML = html_body ;
  582. // contab_home.document.title = "Slideshow";
  583. $("html").html("<head></head><body></body>");
  584. $("head").html(css_head);
  585. $("body").html(html_body);
  586. tag("#btn_prev", contab_home).textContent = "<" ;
  587. tag("#btn_next", contab_home).textContent = ">" ;
  588. say("func_pageSetup completed", contab_home);
  589. }
  590. function func_pageListeners() {
  591. say("func_pageListeners", contab_home);
  592. contab_home.document.addEventListener('keydown', function(key) {
  593. key.cancelBubble = true;
  594. key.stopImmediatePropagation();
  595. switch(key.keyCode) {
  596. case 39: func_imageDisplay(int_imageCurrent + 1); break;
  597. case 37: func_imageDisplay(int_imageCurrent - 1); break;
  598. case 38: case 40: func_detailsDisplay(!bool_detailsDisplay); break;
  599. default: break;
  600. }
  601. return false;
  602. }, !contab_home.opera);
  603. contab_home.addEventListener("resize", function() {
  604. tag("#ctn_main", contab_home).style.width = contab_home.innerWidth + "px";
  605. tag("#ctn_main", contab_home).style.height = contab_home.innerHeight + "px";
  606. func_detailsDisplay();
  607. $.each(tag(".grp_navButtons", contab_home), function(i, elmt) {
  608. elmt.style.lineHeight = contab_home.innerHeight + "px";
  609. });
  610. });
  611. tag("#btn_prev", contab_home).onmousedown = function() {
  612. func_imageDisplay(int_imageCurrent - 1);
  613. };
  614. tag("#btn_next", contab_home).onmousedown = function() {
  615. func_imageDisplay(int_imageCurrent + 1);
  616. };
  617. tag("#act_image", contab_home).onmousedown = function() {
  618. func_detailsDisplay(!bool_detailsDisplay);
  619. };
  620. say("func_pageListeners completed", contab_home);
  621. }
  622. function func_main() {
  623. func_pageSetup();
  624. func_pageListeners();
  625. func_detailsDisplay();
  626. say("class_slideshow.func_main completed", contab_home);
  627. } func_main();
  628. this.meth_sourceAdd = function(ssdn_input) { try {
  629. if (isDef(ssdn_input.node_header)) { // Header
  630. ssdn_source.node_header = ssdn_input.node_header;
  631. func_headerUpdate();
  632. }
  633. if (isDef(ssdn_input.node_payload)) { // If input payload exists
  634. $.each(ssdn_input.node_payload, function(i, node) {
  635. ssdn_source.node_payload.push(node);
  636. });
  637. }
  638. if (ssdn_source.node_payload.length > 1) { // Update
  639. $("#p_imageNumbers").css("display", "block");
  640. $(".grp_navButtons").css("display", "block");
  641. $("#act_menuButton").css("display", "block");
  642. $("#btn_next").text(">");
  643. $("#btn_prev").text("<");
  644. (tag("#p_imageNumbers", contab_home)).style.display = "block";
  645. $.each(tag(".grp_navButtons", contab_home), function(i, elmt) {
  646. elmt.style.display = "block";
  647. });
  648. }
  649. func_imageDisplay();
  650. } catch(str_error) { say(str_error, contab_home); } };
  651. }
  652.  
  653. /* "name": "launcher.js",
  654. "program": "Slideshow",
  655. "description": ""
  656. */
  657.  
  658. function func_main(str_source) {
  659. window.stop();
  660. var obj_slideshow = new class_slideshow(window);
  661. if (str_source == "imgur") {
  662. func_imgurUrlToJson(location.href, function(json_output) {
  663. var ssdn_input = func_imgurJsonToSsdn(json_output);
  664. obj_slideshow.meth_sourceAdd(ssdn_input);
  665. if (ssdn_input.node_header.int_length > ssdn_input.node_payload.length) {
  666. func_imgurUrlToJson(location.href, function(json_output) {
  667. var ssdn_append = func_imgurJsonToSsdn(json_output);
  668. ssdn_append.node_header = null;
  669. ssdn_append.node_payload.splice(0, ssdn_input.node_payload.length);
  670. obj_slideshow.meth_sourceAdd(ssdn_append);
  671. }, ["album"]);
  672. }
  673. });
  674. }
  675. if (str_source == "reddit") {
  676. var obj_redditParser = new class_redditParser(location.href, function(ssdn_outputEntry) {
  677. obj_slideshow.meth_sourceAdd(ssdn_outputEntry);
  678. });
  679. }
  680. say("func_main completed");
  681. }
  682. function func_handler() {
  683. if (location.href.includes("imgur.com")) func_main("imgur");
  684. if (location.href.includes("reddit.com")) {
  685. $(function() {
  686. var p_launch = document.createElement("p"); {
  687. p_launch.textContent = "slideshow";
  688. p_launch.onclick = function() { func_main("reddit"); };
  689. { p_launch.setAttribute(
  690. "style", "\
  691. background: none !important; \
  692. background-color: Transparent !important;\
  693. padding: 0 !important;\
  694. font: inherit;\
  695. border: none !important;\
  696. cursor: pointer;\
  697. font-weight: bold;"
  698. ); }
  699. { p_launch.style.color = (
  700. window
  701. .getComputedStyle(tag(".bylink comments may-blank")[0])
  702. .color
  703. ); }
  704. }
  705. var ctn_launch = document.createElement("li"); {
  706. ctn_launch.appendChild(p_launch);
  707. }
  708. { tag(".flat-list buttons")[0].insertBefore(
  709. ctn_launch,
  710. tag(".flat-list buttons")[0].children[1]
  711. ); }
  712. });
  713. }
  714. } func_handler();