鼠标点击爱心特效

鼠标在页面点击会出现各种颜色的小心心111222333444

  1. // ==UserScript==
  2. // @name 鼠标点击爱心特效
  3. // @license MIT
  4. // @namespace http://tampermonkey.net/
  5. // @version v0.0.0.6
  6. // @description 鼠标在页面点击会出现各种颜色的小心心111222333444
  7. // @author You
  8. // @match *://*/*
  9. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. //<!-- 爱心特效 -->
  14. (function(window,document,undefined){
  15. var hearts = [];
  16. window.requestAnimationFrame = (function(){
  17. return window.requestAnimationFrame ||
  18. window.webkitRequestAnimationFrame ||
  19. window.mozRequestAnimationFrame ||
  20. window.oRequestAnimationFrame ||
  21. window.msRequestAnimationFrame ||
  22. function (callback){
  23. setTimeout(callback,1000/60);
  24. }
  25. })();
  26. init();
  27. function init(){
  28. css(".heart{pointer-events:none;z-index:99999;width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: absolute;}.heart:after{top: -5px;}.heart:before{left: -5px;}");
  29. attachEvent();
  30. gameloop();
  31. }
  32. function gameloop(){
  33. for(var i=0;i<hearts.length;i++){
  34. if(hearts[i].alpha <=0){
  35. document.body.removeChild(hearts[i].el);
  36. hearts.splice(i,1);
  37. continue;
  38. }
  39. hearts[i].y--;
  40. hearts[i].scale += 0.004;
  41. hearts[i].alpha -= 0.013;
  42. hearts[i].el.style.cssText = "left:"+hearts[i].x+"px;top:"+hearts[i].y+"px;opacity:"+hearts[i].alpha+";transform:scale("+hearts[i].scale+","+hearts[i].scale+") rotate(45deg);background:"+hearts[i].color;
  43. }
  44. requestAnimationFrame(gameloop);
  45. }
  46. function attachEvent(){
  47. var old = typeof window.onclick==="function" && window.onclick;
  48. window.onclick = function(event){
  49. old && old();
  50. createHeart(event);
  51. }
  52. }
  53. function createHeart(event){
  54. var d = document.createElement("div");
  55. d.className = "heart";
  56. hearts.push({
  57. el : d,
  58. x : event.clientX - 5,
  59. y : event.clientY - 5,
  60. scale : 1,
  61. alpha : 1,
  62. color : randomColor()
  63. });
  64. document.body.appendChild(d);
  65. }
  66. function css(css){
  67. var style = document.createElement("style");
  68. style.type="text/css";
  69. try{
  70. style.appendChild(document.createTextNode(css));
  71. }catch(ex){
  72. style.styleSheet.cssText = css;
  73. }
  74. document.getElementsByTagName('head')[0].appendChild(style);
  75. }
  76. function randomColor(){
  77. return "rgb("+(~~(Math.random()*255))+","+(~~(Math.random()*255))+","+(~~(Math.random()*255))+")";
  78. }
  79. })(window,document);

QingJ © 2025

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