Direct File for Google Classroom

Directly Download the Files in Google Classroom using Ctrl Click

目前为 2022-03-27 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Direct File for Google Classroom
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description Directly Download the Files in Google Classroom using Ctrl Click
  6. // @author You
  7. // @match https://classroom.google.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=google.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Your code here...
  17.  
  18. const M_HREF="https://drive.google.com/file/d/"
  19. const chkEvtKey=(evt)=>evt.ctrlKey || evt.metaKey;
  20. const chkEvtKey2=(evt)=>evt.key=='Control' || evt.key=='Meta';
  21. document.addEventListener('mouseenter',function(evt){
  22. const linkElm = evt.target.closest(`[href*="${M_HREF}"]`) || evt.target.closest(`[data-ozhref*="${M_HREF}"]`) ;
  23. if(!linkElm)return;
  24. const orhref= linkElm.dataset.ozhref || (linkElm.dataset.ozhref=linkElm.href);
  25. const mres=orhref.match(/\https\:\/\/drive\.google\.com\/file\/d\/([0-9a-zA-Z\-\_\+]+)\/\w+/);
  26. if(!mres)return;
  27. linkElm.href=chkEvtKey(evt)?`https://drive.google.com/u/1/uc?id=${mres[1]}&export=download`:orhref
  28. },true);
  29. document.addEventListener('keydown',function(evt){
  30. const linkElm = evt.target.closest(`[data-ozhref*="${M_HREF}"]`) ;
  31. if(!linkElm)return;
  32. if(chkEvtKey2(evt)) evt.preventDefault();
  33. },true);
  34. document.addEventListener('keypress',function(evt){
  35. const linkElm = evt.target.closest(`[data-ozhref*="${M_HREF}"]`) ;
  36. if(!linkElm)return;
  37. if(chkEvtKey2(evt)) evt.preventDefault();
  38. },true);
  39.  
  40.  
  41. })();