Slideshare Downloader

Slideshare Slide Downloader (images)

  1. // ==UserScript==
  2. // @name Slideshare Downloader
  3. // @namespace Slideshare Slide Downloader
  4. // @version 0.4
  5. // @description Slideshare Slide Downloader (images)
  6. // @author Hosamn Based on DownloadBoxy By QQBoxy
  7. // @match https://www.slideshare.net/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. function getHighestResImg(element) {
  12. if (element.getAttribute("srcset")) {
  13. return element
  14. .getAttribute("srcset")
  15. .split(",")
  16. .reduce(
  17. (acc, item) => {
  18. let [url, width] = item.trim().split(" ");
  19. width = parseInt(width);
  20. if (width > acc.width) return { width, url };
  21. return acc;
  22. },
  23. { width: 0, url: "" }
  24. ).url;
  25. }
  26.  
  27. return element.getAttribute("src");
  28. }
  29.  
  30.  
  31. function slideshareboxy() {
  32. var e = document.getElementById('slide-container').getElementsByTagName('source');
  33. var o = "";
  34. var a ;
  35. for(var key=0; key<e.length; key+=1) {
  36. if(e[key].attributes.srcset) {
  37. var url = getHighestResImg(e[key])
  38. a = document.createElement("a");
  39. a.target = url;
  40. a.href = url;
  41. a.download = key;
  42. a.click();
  43. // let picBlob = new Blob(url, {type: 'text/html'});
  44. // tar??.gz
  45. // https://stackoverflow.com/questions/49736214/force-a-download-to-download-image-instead-of-opening-url-link-to-image
  46. }
  47. }
  48. }
  49.  
  50. function downloadboxy() {
  51. var btn = document.createElement("button");
  52. btn.onclick = function() {
  53. slideshareboxy();
  54. };
  55.  
  56. btn.innerHTML = ">> Download Images <<";
  57. btn.style.textDecoration = "underline"
  58. document.getElementsByClassName('player-toolbar-item')[0].appendChild(btn);
  59. }
  60.  
  61.  
  62.  
  63. function waitForElementToDisplay(selector, callback, checkFrequencyInMs, timeoutInMs) {
  64. var startTimeInMs = Date.now();
  65. (function loopSearch() {
  66. if (document.querySelector(selector) != null) {
  67. callback();
  68. return;
  69. }
  70. else {
  71. setTimeout(function () {
  72. if (timeoutInMs && Date.now() - startTimeInMs > timeoutInMs) {
  73. return;
  74. loopSearch();
  75. }
  76. }, checkFrequencyInMs);
  77. }
  78. })();
  79. }
  80.  
  81.  
  82. waitForElementToDisplay("#player-toolbar", downloadboxy, 100,10000);
  83.