Slideshare Downloader

Slideshare Slide Downloader (images)

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Slideshare Downloader
// @namespace    Slideshare Slide Downloader
// @version      0.4
// @description  Slideshare Slide Downloader (images)
// @author       Hosamn Based on DownloadBoxy By QQBoxy
// @match        https://www.slideshare.net/*
// @grant        none
// ==/UserScript==

function getHighestResImg(element) {
  if (element.getAttribute("srcset")) {
    return element
      .getAttribute("srcset")
      .split(",")
      .reduce(
        (acc, item) => {
          let [url, width] = item.trim().split(" ");
          width = parseInt(width);
          if (width > acc.width) return { width, url };
          return acc;
        },
        { width: 0, url: "" }
      ).url;
  }

  return element.getAttribute("src");
}


function slideshareboxy() {
    var e = document.getElementById('slide-container').getElementsByTagName('source');
    var o = "";
    var a ;
    for(var key=0; key<e.length; key+=1) {
        if(e[key].attributes.srcset) {
            var url = getHighestResImg(e[key])
            a = document.createElement("a");
            a.target = url;
            a.href = url;
            a.download = key;
            a.click();
            // let picBlob = new Blob(url, {type: 'text/html'});
            // tar??.gz
            // https://stackoverflow.com/questions/49736214/force-a-download-to-download-image-instead-of-opening-url-link-to-image
        }
    }
}

function downloadboxy() {
    var btn = document.createElement("button");
    btn.onclick = function() {
        slideshareboxy();
    };

    btn.innerHTML = ">> Download Images <<";
    btn.style.textDecoration = "underline"
    document.getElementsByClassName('player-toolbar-item')[0].appendChild(btn);
}



function waitForElementToDisplay(selector, callback, checkFrequencyInMs, timeoutInMs) {
  var startTimeInMs = Date.now();
  (function loopSearch() {
    if (document.querySelector(selector) != null) {
      callback();
      return;
    }
    else {
      setTimeout(function () {
        if (timeoutInMs && Date.now() - startTimeInMs > timeoutInMs) {
          return;
        loopSearch();
        }
      }, checkFrequencyInMs);
    }
  })();
}


waitForElementToDisplay("#player-toolbar", downloadboxy, 100,10000);