阿里云盘复制

解决阿里云盘网页不能复制的问题

  1. // ==UserScript==
  2. // @name 阿里云盘复制
  3. // @license No License
  4. // @namespace http://tampermonkey.net/
  5. // @version 2024-07-07
  6. // @description 解决阿里云盘网页不能复制的问题
  7. // @author CunShao
  8. // @match https://www.alipan.com/*
  9. // @match https://www.aliyundrive.com/*
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=alipan.com
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. window.onload = function() {
  18. console.log('************************************');
  19.  
  20. setTimeout(() => {
  21. const observer = new MutationObserver((mutationsList, observer) => {
  22. for (let mutation of mutationsList) {
  23. if (mutation.type === 'childList') {
  24. document.querySelectorAll('.name--TC3kz').forEach(function(element) { // 根据实际类名调整
  25. if (!element.querySelector('button.copy-button')) { // 检查是否已经有复制按钮
  26. // 创建复制按钮
  27. var copyButton = document.createElement('button');
  28. copyButton.innerText = '复制';
  29. copyButton.classList.add('copy-button'); // 添加类名,便于选择和避免重复
  30. copyButton.style.marginLeft = '10px';
  31. copyButton.style.display = 'inline-block';
  32. copyButton.style.fontSize = '12px'; // 调整按钮字体大小
  33. copyButton.style.padding = '2px 5px'; // 调整按钮内边距
  34. copyButton.style.backgroundColor = '#007bff'; // 按钮背景颜色
  35. copyButton.style.color = '#fff'; // 按钮文字颜色
  36. copyButton.style.border = 'none'; // 去除按钮边框
  37. copyButton.style.borderRadius = '4px'; // 按钮圆角
  38. copyButton.style.cursor = 'pointer'; // 鼠标悬停时显示手型光标
  39.  
  40. // 按钮点击事件
  41. copyButton.addEventListener('click', function(e) {
  42. e.stopPropagation(); // 防止触发父元素的点击事件
  43. var directoryText = element.innerText.replace('复制', ''); // 去除“复制”按钮的文字
  44. navigator.clipboard.writeText(directoryText).then(function() {
  45. // 创建提示消息
  46. var alertBox = document.createElement('div');
  47. alertBox.innerText = '文字已复制到剪贴板!';
  48. alertBox.style.position = 'fixed';
  49. alertBox.style.bottom = '10px';
  50. alertBox.style.right = '10px';
  51. alertBox.style.backgroundColor = '#28a745';
  52. alertBox.style.color = '#fff';
  53. alertBox.style.padding = '10px';
  54. alertBox.style.borderRadius = '4px';
  55. alertBox.style.zIndex = '1000';
  56. document.body.appendChild(alertBox);
  57.  
  58. // 设置3秒后自动关闭提示消息
  59. setTimeout(function() {
  60. document.body.removeChild(alertBox);
  61. }, 3000);
  62. }).catch(function(err) {
  63. console.error('无法复制文字: ', err);
  64. });
  65. });
  66.  
  67. // 将按钮添加到目录文本元素旁边
  68. element.appendChild(copyButton);
  69. element.style.display = 'flex'; // 使父元素成为flex容器
  70. element.style.alignItems = 'center'; // 垂直居中对齐
  71. }
  72. });
  73. }
  74. }
  75. });
  76.  
  77. observer.observe(document.body, { childList: true, subtree: true });
  78.  
  79. console.log('************************************');
  80. }, 1000); // 延时1秒
  81. };
  82. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址