mousetip

跟随鼠标的提示框改进,并为其他模块提供鼠标提示框相关接口

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/450214/1085823/mousetip.js

  1. /* eslint-disable no-multi-spaces */
  2. /* eslint-disable no-implicit-globals */
  3. /* eslint-disable userscripts/no-invalid-headers */
  4. /* eslint-disable userscripts/no-invalid-grant */
  5.  
  6. // ==UserScript==
  7. // @name mousetip
  8. // @displayname 鼠标提示框
  9. // @namespace Wenku8++
  10. // @version 0.1.3
  11. // @description 跟随鼠标的提示框改进,并为其他模块提供鼠标提示框相关接口
  12. // @author PY-DNG
  13. // @license GPL-v3
  14. // @regurl https?://www\.wenku8\.net/.*
  15. // @require https://gf.qytechs.cn/scripts/449412-basic-functions/code/Basic%20Functions.js?version=1085783
  16. // @grant none
  17. // ==/UserScript==
  18.  
  19. (function __MAIN__() {
  20. 'use strict';
  21. const tipready = tipcheck();
  22. tipscroll();
  23. exports = {
  24. tipready: tipready,
  25. settip: settip,
  26. showtip: showtip,
  27. hidetip: hidetip
  28. };
  29.  
  30. // Check if tipobj is ready, if not, then make it
  31. function tipcheck() {
  32. DoLog(LogLevel.Info, 'checking tipobj...');
  33. if (typeof(tipobj) === 'object' && tipobj !== null) {
  34. DoLog(LogLevel.Info, 'tipobj ready...');
  35. return true;
  36. } else {
  37. DoLog(LogLevel.Warning, 'tipobj not ready');
  38. if (typeof(tipinit) === 'function') {
  39. DoLog(LogLevel.Success, 'tipinit executed');
  40. tipinit();
  41. return true;
  42. } else {
  43. DoLog(LogLevel.Error, 'tipinit not found');
  44. return false;
  45. }
  46. }
  47. }
  48.  
  49. // New tipobj movement method. Makes sure the tipobj stay close with the mouse.
  50. function tipscroll() {
  51. if (!tipready) {return false;}
  52.  
  53. DoLog('tipscroll executed. ')
  54. tipobj.style.position = 'fixed';
  55. window.addEventListener('mousemove', tipmoveplus)
  56. return true;
  57.  
  58. function tipmoveplus(e) {
  59. tipobj.style.left = e.clientX + tipx + 'px';
  60. tipobj.style.top = e.clientY + tipy + 'px';
  61. }
  62. }
  63.  
  64. // show & hide tip when mouse in & out. accepts tip as a string or a function that returns the tip string
  65. function settip(elm, tip) {
  66. typeof(tip) === 'string' && (elm.tiptitle = tip);
  67. typeof(tip) === 'function' && (elm.tipgetter = tip);
  68. elm.removeEventListener('mouseover', showtip);
  69. elm.removeEventListener('mouseout', hidetip);
  70. elm.addEventListener('mouseover', showtip);
  71. elm.addEventListener('mouseout', hidetip);
  72. }
  73.  
  74. function showtip(e) {
  75. if (e && e.currentTarget && (e.currentTarget.tiptitle || e.currentTarget.tipgetter)) {
  76. const tip = e.currentTarget.tiptitle || e.currentTarget.tipgetter();
  77. if (tipready) {
  78. tipshow(tip);
  79. e.currentTarget.title && e.currentTarget.removeAttribute('title');
  80. } else {
  81. e.currentTarget.title = e.currentTarget.tiptitle;
  82. }
  83. } else if (typeof(e) === 'string') {
  84. tipready && tipshow(e);
  85. }
  86. }
  87.  
  88. function hidetip() {
  89. tipready && tiphide();
  90. }
  91. })();

QingJ © 2025

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