🏠 Home 

简单易用一键保存当前网页,无需复杂操作。自动化离线保存,方便又高效

永久保存重要内容


Install this script?
  1. // ==UserScript==
  2. // @name 简单易用一键保存当前网页,无需复杂操作。自动化离线保存,方便又高效
  3. // @namespace 保存当前网页实现离线浏览
  4. // @version 1.1
  5. // @description 永久保存重要内容
  6. // @author 让雅克卢梭博客园
  7. // @match *://*/*
  8. // @license MIT
  9. // @grant none
  10. // ==/UserScript==
  11. (function() {
  12. 'use strict';
  13. // 获取当前页面的 URL
  14. const currentUrl = window.location.href;
  15. // 创建一个按钮元素
  16. const button = document.createElement('button');
  17. button.textContent = '保存到 Archive.today';
  18. button.style.position = 'fixed';
  19. button.style.bottom = '20px';
  20. button.style.right = '20px';
  21. button.style.backgroundColor = '#007bff';
  22. button.style.color = '#fff';
  23. button.style.border = 'none';
  24. button.style.padding = '10px 15px';
  25. button.style.borderRadius = '5px';
  26. button.style.cursor = 'pointer';
  27. button.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.3)';
  28. button.style.zIndex = '9999';
  29. // 按钮点击事件
  30. button.addEventListener('click', () => {
  31. // 创建一个隐藏的表单并提交到 archive.today
  32. const form = document.createElement('form');
  33. form.method = 'POST';
  34. form.action = 'https://archive.today/submit/';
  35. form.target = '_blank'; // 打开新标签
  36. // 添加 URL 输入字段
  37. const input = document.createElement('input');
  38. input.type = 'hidden';
  39. input.name = 'url';
  40. input.value = currentUrl;
  41. form.appendChild(input);
  42. // 将表单添加到文档并提交
  43. document.body.appendChild(form);
  44. form.submit();
  45. // 提交后移除表单
  46. document.body.removeChild(form);
  47. });
  48. // 添加拖动功能
  49. let isDragging = false;
  50. let offsetX, offsetY;
  51. button.addEventListener('mousedown', (e) => {
  52. isDragging = true;
  53. offsetX = e.clientX - button.getBoundingClientRect().left;
  54. offsetY = e.clientY - button.getBoundingClientRect().top;
  55. button.style.cursor = 'grabbing'; // 更改鼠标样式
  56. });
  57. document.addEventListener('mousemove', (e) => {
  58. if (isDragging) {
  59. const x = e.clientX - offsetX;
  60. const y = e.clientY - offsetY;
  61. button.style.left = `${x}px`;
  62. button.style.top = `${y}px`;
  63. button.style.bottom = 'auto'; // 禁止固定在底部
  64. button.style.right = 'auto'; // 禁止固定在右边
  65. }
  66. });
  67. document.addEventListener('mouseup', () => {
  68. isDragging = false;
  69. button.style.cursor = 'pointer'; // 恢复鼠标样式
  70. });
  71. // 将按钮添加到页面
  72. document.body.appendChild(button);
  73. })();