创建新窗口 with 链接

在当前页面点击悬浮图标后,在新窗口中打开当前页面的链接

  1. // ==UserScript==
  2. // @name 创建新窗口 with 链接
  3. // @namespace http://your-namespace.com
  4. // @version 1.1.0
  5. // @description 在当前页面点击悬浮图标后,在新窗口中打开当前页面的链接
  6. // @author 吃不吃香菜
  7. // @license MIT
  8. // @match http://*/*
  9. // @match https://*/*
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. var iconUrl = GM_getValue('iconUrl', 'https://vip.helloimg.com/images/2023/10/18/o2TCvg.jpg'); // 获取保存的图标地址,默认为默认图标地址
  18.  
  19. // 创建悬浮图标
  20. var floatingIcon = document.createElement('div');
  21. floatingIcon.style.backgroundImage = 'url(' + iconUrl + ')';
  22. floatingIcon.style.backgroundSize = '100% 100%';
  23. floatingIcon.style.position = 'fixed';
  24. floatingIcon.style.bottom = '20px';
  25. floatingIcon.style.right = '20px';
  26. floatingIcon.style.width = '50px';
  27. floatingIcon.style.height = '50px';
  28. floatingIcon.style.borderRadius = '50%';
  29. floatingIcon.style.cursor = 'pointer';
  30. document.body.appendChild(floatingIcon);
  31.  
  32. // 取消窗口和文档失去焦点事件的处理函数,并在控制台中输出“运行成功”
  33. window.onblur = null;
  34. document.onblur = null;
  35. console.log("运行成功");
  36.  
  37. // 点击悬浮图标时创建新窗口
  38. floatingIcon.addEventListener('click', function() {
  39. var newWindow = window.open(window.location.href, '_blank', 'width=300,height=300');
  40. newWindow.focus();
  41. });
  42.  
  43. // 右击悬浮图标时上传新图标
  44. floatingIcon.addEventListener('contextmenu', function(event) {
  45. event.preventDefault();
  46. var fileInput = document.createElement('input');
  47. fileInput.type = 'file';
  48. fileInput.accept = 'image/*';
  49. fileInput.style.display = 'none';
  50. document.body.appendChild(fileInput);
  51.  
  52. fileInput.addEventListener('change', function() {
  53. var file = fileInput.files[0];
  54. var reader = new FileReader();
  55. reader.onload = function(e) {
  56. iconUrl = e.target.result;
  57. floatingIcon.style.backgroundImage = 'url(' + iconUrl + ')';
  58. GM_setValue('iconUrl', iconUrl); // 保存图标地址
  59. };
  60. reader.readAsDataURL(file);
  61. document.body.removeChild(fileInput);
  62. });
  63.  
  64. fileInput.click();
  65. });
  66.  
  67. })();

QingJ © 2025

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