FOP小助手

FOP开发小助手

  1. // ==UserScript==
  2. // @name FOP小助手
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description FOP开发小助手
  6. // @author sudongxu
  7. // @match *://*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=sankuai.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12. // 脚本 - FOP小助手
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Your code here...
  18. let isMouseDown = false;
  19. const initStyle = {
  20. width: "40px",
  21. height: "100px",
  22. "background-color": "#fff",
  23. display: "flex",
  24. "flex-direction": "column",
  25. "justify-content": "flex-end",
  26. "border-radius": "0 0 30px 30px",
  27. border: "1px solid rgba(0, 0, 0, 0.3)",
  28. overflow: "hidden",
  29. transform: "translateY(-75px)",
  30. transition: "0.3s linear",
  31. cursor: "pointer",
  32. position: "fixed",
  33. "z-index": 100000000,
  34. };
  35. const hoverStyle = {
  36. transform: "translateY(-60px)",
  37. cursor: "pointer",
  38. "background-color": "#ffd100",
  39. };
  40. const logoStyle = {
  41. "-webkit-user-select": "none" /* Chrome/Safari */,
  42. "user-select": "none",
  43. width:"30px",
  44. height:"30px",
  45. "margin-left":"5px",
  46. };
  47.  
  48. // 设置css样式
  49. function setStyle(e, styleObj) {
  50. Object.keys(styleObj).forEach((key) => {
  51. e.style[key] = styleObj[key];
  52. });
  53. }
  54.  
  55. const container = document.createElement("div");
  56. // 创建img元素
  57. const img = document.createElement("img");
  58.  
  59. // 设置img元素的属性
  60. img.src =
  61. "https://p0.meituan.net/travelcube/0bbafeea1f1db5387528e8ad62bbd0781653.png";
  62. img.draggable = false;
  63. setStyle(img, logoStyle);
  64.  
  65. // 将img元素添加到指定的父元素中
  66. container.appendChild(img);
  67. // 从localStorage中获取上次的位置
  68. let lastLeft = localStorage.getItem("divLeft");
  69. if (lastLeft) {
  70. container.style.left = lastLeft + "px";
  71. }
  72. setStyle(container, initStyle);
  73.  
  74. // 移入
  75. container.addEventListener("mouseover", function (e) {
  76. setStyle(container, hoverStyle);
  77. });
  78. // 移出
  79. container.addEventListener("mouseout", function (e) {
  80. setStyle(container, initStyle);
  81. });
  82.  
  83. // 鼠标按下事件
  84. container.addEventListener("mousedown", function (e) {
  85. isMouseDown = true;
  86. e.preventDefault();
  87. });
  88. // 鼠标移动事件
  89. window.addEventListener("mousemove", function (e) {
  90. if (isMouseDown) {
  91. setStyle(container, hoverStyle);
  92. container.style.left = e.clientX - container.offsetWidth / 2 + "px";
  93. }
  94. });
  95. // 鼠标松开事件
  96. window.addEventListener("mouseup", function () {
  97. isMouseDown = false;
  98. setStyle(container, initStyle);
  99. // 将位置存储到localStorage中
  100. localStorage.setItem("divLeft", parseInt(container.style.left));
  101. });
  102.  
  103. document.body.appendChild(container);
  104. })();

QingJ © 2025

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