🏠 Home 

Greasy Fork is available in English.

Google Drive Direct Links

Direct link functionality for Google Drive


安装此脚本?
  1. // ==UserScript==
  2. // @name Google Drive Direct Links
  3. // @version 2.0
  4. // @description Direct link functionality for Google Drive
  5. // @author Drazen Bjelovuk
  6. // @match *://drive.google.com/*
  7. // @grant none
  8. // @namespace https://greasyfork.org/users/11679
  9. // @contributionURL https://goo.gl/dYIygm
  10. // ==/UserScript==
  11. var observer = new MutationObserver(function(mutations) {
  12. mutations.forEach(function(mutation) {
  13. for (var i = 0; i < mutation.addedNodes.length; i++) {
  14. var node = mutation.addedNodes[i];
  15. if (node.dataset.target === 'linkBubble') {
  16. var link = node.getElementsByTagName('input')[0];
  17. var directLink = link.cloneNode(true);
  18. directLink.classList.remove('H-qa-A-zt');
  19. directLink.value = 'https://drive.google.com/uc?id='+ node.parentNode.dataset.id;
  20. directLink.onclick = function() { this.select(); };
  21. var label = document.createElement('p');
  22. label.style.cssText = "margin-top: 0px; margin-bottom: 0px;";
  23. label.textContent = 'Direct link:';
  24. link.parentNode.insertBefore(directLink, link.nextSibling);
  25. link.parentNode.insertBefore(label, link.nextSibling);
  26. break;
  27. }
  28. else setClickEvent(node);
  29. }
  30. });
  31. });
  32. var content = document.getElementById('drive_main_page');
  33. if (content) observer.observe(content, { childList: true, subtree: true });
  34. function setClickEvent(elem) {
  35. if (elem.classList && (elem.classList.contains('WYuW0e'))) {
  36. elem.addEventListener('contextmenu', adjustMenu);
  37. }
  38. else {
  39. for (var i = 0; i < elem.children.length; i++) {
  40. setClickEvent(elem.children[i]);
  41. }
  42. }
  43. }
  44. function adjustMenu() {
  45. var file = this;
  46. setTimeout(function() {
  47. var menus = document.getElementsByClassName('h-w');
  48. for (var i = 0; i < menus.length; i++) {
  49. var menu = menus[i];
  50. if (menu.style.display !== 'none') {
  51. var existing = document.getElementById('DLID');
  52. if (existing) existing.remove();
  53. var container = menu.children[0];
  54. var preview = Array.from(container.querySelectorAll('.h-v')).find((node) => node.style.display !== 'none');
  55. var clone = preview.cloneNode(true);
  56. clone.id = 'DLID';
  57. clone.style.display = 'block';
  58. clone.className = 'h-v';
  59. clone.getElementsByClassName('a-v-T')[0].innerHTML = 'Open direct';
  60. clone.onmouseleave = clone.onmouseenter = function() {
  61. this.classList.toggle('h-v-pc');
  62. };
  63. clone.onclick = function() {
  64. window.open('https://drive.google.com/uc?id='+ file.dataset.id);
  65. };
  66. container.insertBefore(clone, preview.nextSibling);
  67. break;
  68. }
  69. }
  70. });
  71. }