div cursor demo🔧

div follow cursor demo

目前为 2023-08-25 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name div cursor demo🔧
  3. // @description div follow cursor demo
  4. // @namespace div_cursor
  5. // @author Covenant
  6. // @version 1.0.6
  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. if(document.body!=null){
  31. style_div_cursor=create_style("","gm_user_css_div_cursor",["user_gm_css","css_div_cursor"]);
  32. style_div_cursor.textContent+=`
  33. .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}
  34. .gm_cursor1{background-color:#ffffff;height:0;width:0;z-index:9999999;border:8px solid;}
  35. .gm_cursor2, .gm_cursor3{height:36px;width:36px;z-index:99998;transition:all .3s ease-out;}
  36. .gm_cursor2.hover, .gm_cursor3.hover{transform:scale(2) translateX(-25%) translateY(-25%);border:none;}
  37. .gm_cursor2{border:2px solid #ffffff;box-shadow:0 0 12px rgba(255,255,255,.2);}
  38. .gm_cursor2.hover{background:white;box-shadow:0 0 0 rgba(255,255,255,.2);}\n`;
  39. }
  40. function create_div(class_name,is_appendChild,node,refNode){
  41. let div=create_node("div",class_name,is_appendChild,node,refNode);
  42. div.style.backgroundSize='contain';
  43. div.style.backgroundRepeat='no-repeat';
  44. div.lang='ja';
  45. return div;
  46. }
  47. function create_node(tagname,class_name,is_appendChild,node,refNode){
  48. let element=document.createElement(tagname);
  49. element.id="";
  50. /*if(Array.isArray(tagname)){
  51. element=document.createElement(tagname[0]);
  52. element.id=tagname[1];
  53. }else if(typeof tagname==='string'){element=document.createElement(tagname);}//*/
  54. if(Array.isArray(class_name)){
  55. for(let i=0; i<class_name.length; i++){element.classList.add(class_name[i]);}
  56. }else if(typeof class_name==='string'){element.classList.add(class_name);}
  57. if(is_appendChild){node.appendChild(element);}else{node.insertBefore(element, refNode);}
  58. return element;
  59. }
  60. //console.log("break");
  61. function main_01(){
  62. if(style_div_cursor.parentNode==undefined){
  63. console.log("style_div_cursor undefined");
  64. document.body.appendChild(style_div_cursor);
  65. document.body.appendChild(ary_div[0]);
  66. document.body.appendChild(ary_div[1]);
  67. document.body.appendChild(ary_div[2]);
  68. window.clearInterval(timeoutID_1);
  69. }
  70. }
  71. function main_02(){
  72. let anchor=document.querySelectorAll('a');
  73. let div_cursor=document.querySelectorAll('.hover-target');
  74. for(let i = 0; i < anchor.length; i++){
  75. for(let j = 0; j < div_cursor.length; j++){
  76. anchor[i].addEventListener('mouseenter', function(){div_cursor[j].classList.add('hover');});
  77. anchor[i].addEventListener('mouseleave', function(){div_cursor[j].classList.remove('hover');});
  78. }
  79. }
  80. }
  81. (function() {
  82. 'use strict';
  83. if(document.body==null)return;
  84. if(document.querySelectorAll("#index_cursor1").length==0){
  85. ary_div[0]=create_div("gm_cursor1",true,document.body);
  86. ary_div[1]=create_div(["gm_cursor2","hover-target"],true,document.body);
  87. ary_div[2]=create_div(["gm_cursor3","hover-target"],true,document.body);
  88. let div_c1=ary_div[0];
  89. let div_c2=ary_div[1];
  90. let div_c3=ary_div[2];
  91. div_c1.id="gm_cursor1";
  92. div_c2.id="gm_cursor2";
  93. div_c3.id="gm_cursor3";
  94. timeoutID_1=window.setInterval(( () => main_01()), 1000);
  95. //move
  96. var x, y;
  97. // On mousemove use event.clientX and event.clientY to set the location of the div to the location of the cursor:
  98. window.addEventListener('mousemove', function(event){
  99. x = event.clientX;
  100. y = event.clientY;
  101. if ( typeof x !== 'undefined' ){
  102. div_c1.style.left=x+"px";div_c2.style.left=x+"px";div_c3.style.left=x+"px";
  103. div_c1.style.top=y+"px";div_c2.style.top=y+"px";div_c3.style.top=y+"px";
  104. }
  105. }, false);
  106. //anchor
  107. //document.addEventListener('DOMContentLoaded', function() {console.log("DOMContentLoaded div_cursor");main_02();});
  108. timeoutID_2=window.setInterval(( () => main_02() ), 1000);//bak
  109. window.setTimeout(( () => window.clearInterval(timeoutID_2) ), 30000);
  110. }
  111. /*jshint multistr: true */
  112. })();