🔧div cursor demo

div follow cursor demo

当前为 2023-04-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name 🔧div cursor demo
  3. // @description div follow cursor demo
  4. // @namespace div_cursor
  5. // @author Covenant
  6. // @version 1.0.4
  7. // @license MIT
  8. // @homepage
  9. // @match *://*/*
  10. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAABICAMAAABiM0N1AAAAOVBMVEVHcEwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADMzMwAAACmpqY6Ojq6urp9fX1QUFCUlJQbGxs9xjm/AAAACnRSTlMACqKHwVaUN/PaZCFdUwAAAXxJREFUWMPt2NuOgyAQBmBRhBHk+P4PuwJtNgrCYHeTXvBfNenkywBeDEzTyONwRkFeApTxPoWsm7zJtvZ0c8tECt3VCrIaQDa1pnLrtAjZY+JP7Wz6DyXx2I9NyhkKVqQAs7q4P0aIMiSEifuEOK+Lk0FJWlENWVGDhMW0FBvSdUiHmtYusWtDBSi2xBoQPWpcC3JHEW1AcF2Z2I1S5gyFtUEDCssXZ0gdOUMiVA3oq6H8+B9C+Qc5oK+HdHD0H0BBujgPoUIGNKABDej/oXw+KgQzH4VZdG9BO2IapZfhuBiDGP2WbBgtJAyjC2I89i3IIyZ2AtlYmyUMtUBaE/t8VKk6pI6SuX05kq2WHGbwf52bb+0QbTupJVs/Mom6jTJZ+5biJYthnIlsFSld+wgKel9Gb9cF6Gt2knx2ds73OW9JqhPllOx1fp8QvDVhONK7sb73+eC146z8eMDI1BtOc4by6Un4fHrbgPkZk14BFrodGmx0Wck08ll+AGC5Y59UZba/AAAAAElFTkSuQmCC
  11. // @grant GM_setValue
  12. // @grant GM_getValue
  13. // @grant GM_registerMenuCommand
  14. // @connect
  15. // @run-at document-body
  16. // @noframes
  17. // ==/UserScript==
  18. var style_div_cursor;
  19. var ary_div=[];
  20. var timeoutID_1;
  21. var timeoutID_2;
  22. function create_style(innerText,class_name){
  23. var style=document.createElement("style");
  24. if(Array.isArray(class_name)){
  25. for(let i=0; i<class_name.length; i++){style.classList.add(class_name[i]);}
  26. }
  27. else if(typeof class_name==='string'){style.classList.add(class_name);}
  28. style.textContent=innerText;
  29. document.body.appendChild(style);
  30. return style;
  31. }
  32. style_div_cursor=create_style(".gm_cursor1, .gm_cursor2, .gm_cursor3{position:fixed;border-radius:50%;transform:translateX(-50%) translateY(-50%);pointer-events:none;left:-100px;top:50%;mix-blend-mode:difference;transition:all 300ms linear;z-index:9999999;cursor:pointer;color: #212529}\n",["user_gm_css","css_div_cursor"]);
  33. style_div_cursor.textContent+=".gm_cursor1{background-color:#ffffff;height:0;width:0;z-index:9999999;border:8px solid;}\n";
  34. style_div_cursor.textContent+=".gm_cursor2, .gm_cursor3{height:36px;width:36px;z-index:99998;transition:all .3s ease-out;}\n";
  35. style_div_cursor.textContent+=".gm_cursor2.hover, .gm_cursor3.hover{transform:scale(2) translateX(-25%) translateY(-25%);border:none;}\n";
  36. style_div_cursor.textContent+=".gm_cursor2{border:2px solid #ffffff;box-shadow:0 0 12px rgba(255,255,255,.2);}\n";
  37. style_div_cursor.textContent+=".gm_cursor2.hover{background:white;box-shadow:0 0 0 rgba(255,255,255,.2);}\n";
  38. function create_div(class_name,id,is_appendChild,node,refNode){
  39. var div=document.createElement("div");
  40. div.id=id;
  41. if(Array.isArray(class_name)){
  42. for(let i=0; i<class_name.length; i++){div.classList.add(class_name[i]);}
  43. }
  44. else if(typeof class_name==='string'){div.classList.add(class_name);}
  45. div.style.backgroundSize='contain';
  46. div.style.backgroundRepeat='no-repeat';
  47. if(is_appendChild){
  48. node.appendChild(div);
  49. }
  50. else{node.insertBefore(div, refNode);}
  51. return div;
  52. }
  53. function main_01(){
  54. if(style_div_cursor.parent==undefined){
  55. document.body.appendChild(style_div_cursor);
  56. document.body.appendChild(ary_div[0]);
  57. document.body.appendChild(ary_div[1]);
  58. document.body.appendChild(ary_div[2]);
  59. window.clearInterval(timeoutID_1);
  60. }
  61. }
  62. function main_02(){
  63. var anchor=document.querySelectorAll('a');
  64. var div_cursor=document.querySelectorAll('.hover-target');
  65. for(let i = 0; i < anchor.length; i++){
  66. for(let j = 0; j < div_cursor.length; j++){
  67. anchor[i].addEventListener('mouseenter', function(){div_cursor[j].classList.add('hover');});
  68. anchor[i].addEventListener('mouseleave', function(){div_cursor[j].classList.remove('hover');});
  69. }
  70. }
  71. }
  72. (function() {
  73. 'use strict';
  74. if(document.querySelectorAll("#index_cursor1").length==0){
  75. ary_div[0]=create_div("gm_cursor1","gm_cursor1",true,document.body);
  76. ary_div[1]=create_div(["gm_cursor2","hover-target"],"gm_cursor2",true,document.body);
  77. ary_div[2]=create_div(["gm_cursor3","hover-target"],"gm_cursor3",true,document.body);
  78. timeoutID_1=window.setInterval(( () => main_01()), 1000);
  79. //move
  80. var div_c1 = document.getElementById("gm_cursor1");var div_c2 = document.getElementById("gm_cursor2");var div_c3 = document.getElementById("gm_cursor3");
  81. var x, y;
  82. // On mousemove use event.clientX and event.clientY to set the location of the div to the location of the cursor:
  83. window.addEventListener('mousemove', function(event){
  84. x = event.clientX;
  85. y = event.clientY;
  86. if ( typeof x !== 'undefined' ){
  87. div_c1.style.left=x+"px";div_c2.style.left=x+"px";div_c3.style.left=x+"px";
  88. div_c1.style.top=y+"px";div_c2.style.top=y+"px";div_c3.style.top=y+"px";
  89. }
  90. }, false);
  91. //anchor
  92. //document.addEventListener('DOMContentLoaded', function() {console.log("DOMContentLoaded div_cursor");main_02();});
  93. timeoutID_2=window.setInterval(( () => main_02() ), 1000);//bak
  94. window.setTimeout(( () => window.clearInterval(timeoutID_2) ), 30000);
  95. }
  96. /*jshint multistr: true */
  97. })();