SharePoint list download link

Add download link to SharePoint list items that contain links to files

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         SharePoint list download link
// @namespace    http://tampermonkey.net/
// @version      0.1.3
// @description  Add download link to SharePoint list items that contain links to files
// @author       apple-phi
// @match        *://*/*.aspx*
// @grant        none
// @license      MIT; https://opensource.org/licenses/MIT
// @run-at       document-start
// ==/UserScript==
"use strict";

(async () => {
  const { BlobWriter, HttpReader, ZipWriter } = await import(
    "https://unpkg.com/@zip.js/zip.js/index.js"
  );
  for (const table of document.querySelectorAll(
    "table:has(> tbody > tr > td.ms-vb-title > .ms-vb.itx > a[href])"
  )) {
    const availableFiles = table.querySelectorAll(
      "td.ms-vb-title > .ms-vb.itx > a[href]"
    );
    let anchor = document.createElement("a");
    anchor.href = "#";
    anchor.textContent = `Zipped 0 of ${availableFiles.length} files`;
    table.closest("div").prepend(anchor);
    let progress = 0;
    const zipWriter = new ZipWriter(new BlobWriter("application/zip"));
    async function addFileToZip(link) {
      const absUrl = new URL(link, window.location.origin).href;
      const segments = absUrl.split("/");
      const filename = segments.pop() || segments.pop();
      await zipWriter.add(decodeURIComponent(filename), new HttpReader(absUrl));
      progress++;
      anchor.textContent = `Zipped ${progress} of ${availableFiles.length} files`;
    }
    await Promise.all(
      [...availableFiles].map((a) => a.getAttribute("href")).map(addFileToZip)
    ).then(async () => {
      anchor.textContent = "Download zip file";
      anchor.href = URL.createObjectURL(await zipWriter.close());
      anchor.download = `${
        document.querySelector("span.ms-sitemapdirectional").textContent ||
        "download"
      }.zip`;
    });
  }
})();