Direct File for Google Classroom

Directly Download the Files in Google Classroom using Ctrl Click

当前为 2023-10-03 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Direct File for Google Classroom
// @namespace    http://tampermonkey.net/
// @version      0.4.0
// @description  Directly Download the Files in Google Classroom using Ctrl Click
// @author       You
// @match        https://classroom.google.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=google.com
// @grant        none
// @license MIT
// ==/UserScript==

(function () {

  'use strict';
  // Your code here...

  const M_HREF = "https://drive.google.com/file/d/"



  new MutationObserver(() => {

    Promise.resolve().then(() => {

      const links = document.querySelectorAll(`[href*="${M_HREF}"]:not([data-ozhref])`)
      if (links.length > 0) {
        for (const linkElm of links) {

          const orhref = linkElm.href;

          linkElm.dataset.ozhref = orhref;

          const mres = orhref.match(/\https\:\/\/drive\.google\.com\/file\/d\/([0-9a-zA-Z\-\_\+]+)\/\w+/);
          if (!mres) return;


          let dfileId = `${mres[1]}`;

          // let newHref=`https://drive.google.com/u/1/uc?id=${mres[1]}&export=download`;


          let uo = null;
          try {
            uo = new URL(orhref);
          } catch (e) { }
          if (!uo) continue;

          let uo2 = new URL(`https://drive.google.com/uc?export=download&id=${dfileId}`);



          uo.searchParams.forEach((value, key) => {
            uo2.searchParams.set(key, value);
          });
          let newHref = uo2.toString()

          if (!newHref || typeof newHref !== 'string') continue;
          // console.log(orhref, newHref)
          // linkElm.setAttribute('href',newHref)

          // let newHref = `https://drive.google.com/uc?export=download&id=${dfileId}&usp=drive_web&authuser=2`
          linkElm.setAttribute('href', newHref)

          linkElm.setAttribute('target', '_blank')

          linkElm.addEventListener('click', function (evt) {

              const linkElm = this;
              evt.stopPropagation();
              evt.stopImmediatePropagation();


          }, true);




        }

      }

    });

  }).observe(document, { subtree: true, childList: true })




})();