Hello8tsmedavidson

Mine a Website

Nov 14th, 2025
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function () {
  2.     let target = null
  3.     let holdTimer = null
  4.     let pick = null
  5.     let crack = null
  6.     let startTime = null
  7.     const mineTime = 3000
  8.  
  9.     const pickaxe = "https://freepngimg.com/thumb/minecraft/94806-square-angle-pocket-edition-pickaxe-minecraft.png"
  10.     const breakImg = "https://www.onlygfx.com/wp-content/uploads/2018/02/crack-3.png"
  11.  
  12.     function avgColor(el) {
  13.         const r = el.getBoundingClientRect()
  14.         const c = document.createElement("canvas")
  15.         c.width = Math.max(1, r.width)
  16.         c.height = Math.max(1, r.height)
  17.         const ctx = c.getContext("2d")
  18.  
  19.         try {
  20.             ctx.drawImage(el, 0, 0, c.width, c.height)
  21.             const data = ctx.getImageData(0, 0, c.width, c.height).data
  22.             let rSum = 0, gSum = 0, bSum = 0
  23.             for (let i = 0; i < data.length; i += 4) {
  24.                 rSum += data[i]
  25.                 gSum += data[i + 1]
  26.                 bSum += data[i + 2]
  27.             }
  28.             const count = data.length / 4
  29.             return `rgb(${rSum / count}, ${gSum / count}, ${bSum / count})`
  30.         } catch (e) {
  31.             const cs = getComputedStyle(el)
  32.             return cs.backgroundColor || "gray"
  33.         }
  34.     }
  35.  
  36.     function spawnDebris(el, intense = false) {
  37.         const r = el.getBoundingClientRect()
  38.         const baseColor = avgColor(el)
  39.         const amount = intense ? 15 : 3
  40.  
  41.         for (let i = 0; i < amount; i++) {
  42.             const d = document.createElement("div")
  43.             d.style.position = "fixed"
  44.             d.style.width = "6px"
  45.             d.style.height = "6px"
  46.             d.style.background = baseColor
  47.             d.style.left = (r.left + r.width / 2) + "px"
  48.             d.style.top = (r.top + r.height / 2) + "px"
  49.             d.style.pointerEvents = "none"
  50.             d.style.borderRadius = "2px"
  51.             d.style.transition = "opacity 0.6s linear"
  52.             document.body.appendChild(d)
  53.  
  54.             const angle = Math.random() * Math.PI * 2
  55.             const dist = intense ? 60 : 25
  56.             const x = Math.cos(angle) * dist
  57.             const y = Math.sin(angle) * dist
  58.  
  59.             setTimeout(() => {
  60.                 d.style.transform = `translate(${x}px, ${y}px)`
  61.                 d.style.opacity = "0"
  62.             }, 10)
  63.  
  64.             setTimeout(() => d.remove(), 700)
  65.         }
  66.     }
  67.  
  68.     function spawnPick(x, y) {
  69.         pick = document.createElement("img")
  70.         pick.src = pickaxe
  71.         pick.style.position = "fixed"
  72.         pick.style.left = x + "px"
  73.         pick.style.top = y + "px"
  74.         pick.style.width = "60px"
  75.         pick.style.pointerEvents = "none"
  76.         pick.style.transformOrigin = "bottom center"
  77.         pick.style.transition = "transform 0.1s ease-in-out"
  78.         document.body.appendChild(pick)
  79.  
  80.         let flip = false
  81.         pick._int = setInterval(() => {
  82.             flip = !flip
  83.             pick.style.transform = flip ? "rotate(90deg)" : "rotate(0deg)"
  84.         }, 100)
  85.     }
  86.  
  87.     function spawnCrack(el) {
  88.         crack = document.createElement("img")
  89.         crack.src = breakImg
  90.         crack.style.position = "absolute"
  91.  
  92.         const r = el.getBoundingClientRect()
  93.         crack.style.left = r.left + "px"
  94.         crack.style.top = r.top + "px"
  95.         crack.style.width = r.width + "px"
  96.         crack.style.height = r.height + "px"
  97.         crack.style.pointerEvents = "none"
  98.         crack.style.opacity = "1"
  99.         crack.style.transition = "opacity 0.1s linear"
  100.  
  101.         document.body.appendChild(crack)
  102.     }
  103.  
  104.     function updateCrack() {
  105.         if (!crack || startTime === null) return
  106.         const elapsed = Date.now() - startTime
  107.         const progress = Math.min(elapsed / mineTime, 1)
  108.         crack.style.opacity = String(1 - progress)
  109.  
  110.         if (progress < 1) {
  111.             spawnDebris(target, false)
  112.             requestAnimationFrame(updateCrack)
  113.         }
  114.     }
  115.  
  116.     function removePick() {
  117.         if (pick) {
  118.             clearInterval(pick._int)
  119.             pick.remove()
  120.             pick = null
  121.         }
  122.     }
  123.  
  124.     function removeCrack() {
  125.         if (crack) {
  126.             crack.remove()
  127.             crack = null
  128.         }
  129.     }
  130.  
  131.     document.addEventListener("mousedown", e => {
  132.         target = e.target
  133.         spawnPick(e.clientX, e.clientY)
  134.         spawnCrack(target)
  135.         startTime = Date.now()
  136.         updateCrack()
  137.  
  138.         holdTimer = setTimeout(() => {
  139.             spawnDebris(target, true)
  140.             if (target) target.remove()
  141.             removePick()
  142.             removeCrack()
  143.             target = null
  144.             startTime = null
  145.         }, mineTime)
  146.     })
  147.  
  148.     document.addEventListener("mouseup", () => {
  149.         clearTimeout(holdTimer)
  150.         removePick()
  151.         removeCrack()
  152.         target = null
  153.         startTime = null
  154.     })
  155. })()
  156.  
Advertisement
Add Comment
Please, Sign In to add comment