div cursor demo🔧

div follow cursor demo

当前为 2023-07-13 提交的版本,查看 最新版本

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