{"id":"78aa2a0c-3478-4ecf-9766-a4816b2f4038","name":"ai生成-计算器","type":"window","description":"此脚本有AI助手生成，以作演示。","matches":["*://*/*"],"code":"(function () {\n  const rootId = 'dog-calculator-root';\n  const styleId = 'dog-calculator-style';\n\n  if (typeof window.__dogCalculatorCleanup === 'function') {\n    try {\n      window.__dogCalculatorCleanup();\n    } catch (e) {}\n  }\n\n  const oldRoot = document.getElementById(rootId);\n  if (oldRoot) oldRoot.remove();\n\n  const css = `\n.dog-calculator *,\n#dog-calculator-root * {\n  box-sizing: border-box;\n}\n\n.dog-calculator,\n#dog-calculator-root.dog-calculator {\n  display: block !important;\n  visibility: visible !important;\n  opacity: 1 !important;\n  position: relative !important;\n  z-index: 999999 !important;\n  width: 340px;\n  max-width: calc(100vw - 24px);\n  margin: 28px auto !important;\n  padding: 20px !important;\n  border-radius: 28px !important;\n  background:\n    radial-gradient(120% 120% at 0% 0%, rgba(34, 211, 238, 0.13), transparent 42%),\n    radial-gradient(120% 120% at 100% 0%, rgba(129, 140, 248, 0.13), transparent 46%),\n    linear-gradient(145deg, rgba(15, 23, 42, 0.97), rgba(2, 6, 23, 0.96)) !important;\n  border: 1px solid rgba(148, 163, 184, 0.18) !important;\n  box-shadow:\n    0 24px 60px rgba(2, 6, 23, 0.52),\n    0 0 0 1px rgba(34, 211, 238, 0.04),\n    inset 0 1px rgba(255, 255, 255, 0.08) !important;\n  font-family: \"SF Pro Display\", \"Inter\", -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif !important;\n  color: #e5e7eb !important;\n  user-select: none !important;\n  pointer-events: auto !important;\n  overflow: hidden;\n}\n\n.dog-calculator::before,\n#dog-calculator-root.dog-calculator::before {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  pointer-events: none;\n  background:\n    linear-gradient(90deg, rgba(34, 211, 238, 0.08), transparent 38%),\n    linear-gradient(270deg, rgba(129, 140, 248, 0.08), transparent 38%);\n  opacity: 0.7;\n}\n\n.dog-calculator:focus-visible,\n#dog-calculator-root.dog-calculator:focus-visible {\n  outline: none !important;\n  border-color: rgba(34, 211, 238, 0.58) !important;\n  box-shadow:\n    0 24px 60px rgba(2, 6, 23, 0.52),\n    0 0 0 1px rgba(34, 211, 238, 0.22),\n    inset 0 1px rgba(255, 255, 255, 0.08),\n    0 0 28px rgba(34, 211, 238, 0.16) !important;\n}\n\n.dog-calc-screen {\n  position: relative;\n  background:\n    radial-gradient(130% 100% at 85% 15%, rgba(34, 211, 238, 0.12), transparent 45%),\n    radial-gradient(120% 90% at 12% 88%, rgba(129, 140, 248, 0.10), transparent 42%),\n    linear-gradient(135deg, rgba(2, 6, 23, 0.82), rgba(15, 23, 42, 0.64)) !important;\n  border: 1px solid rgba(148, 163, 184, 0.16) !important;\n  border-radius: 22px !important;\n  padding: 16px 18px 20px !important;\n  margin-bottom: 18px !important;\n  min-height: 104px !important;\n  display: flex !important;\n  flex-direction: column !important;\n  justify-content: flex-end !important;\n  align-items: flex-end !important;\n  overflow: hidden !important;\n  box-shadow:\n    inset 0 0 28px rgba(34, 211, 238, 0.07),\n    0 12px 26px rgba(2, 6, 23, 0.22) !important;\n  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;\n}\n\n.dog-calc-screen::after {\n  content: \"\";\n  position: absolute;\n  top: -35%;\n  right: -20%;\n  width: 180px;\n  height: 180px;\n  background: radial-gradient(circle, rgba(34, 211, 238, 0.12), transparent 68%);\n  filter: blur(12px);\n  pointer-events: none;\n  opacity: 0.55;\n}\n\n.dog-calc-expression {\n  font-size: 14px !important;\n  line-height: 1.35 !important;\n  color: rgba(148, 163, 184, 0.86) !important;\n  min-height: 18px !important;\n  max-width: 100% !important;\n  white-space: nowrap !important;\n  overflow: hidden !important;\n  text-overflow: ellipsis !important;\n  letter-spacing: 0.03em !important;\n  text-align: right !important;\n}\n\n.dog-calc-current {\n  font-size: 42px !important;\n  font-weight: 600 !important;\n  line-height: 1.05 !important;\n  color: #e0f2fe !important;\n  max-width: 100% !important;\n  white-space: nowrap !important;\n  overflow: hidden !important;\n  text-overflow: ellipsis !important;\n  text-align: right !important;\n  text-shadow: 0 0 18px rgba(34, 211, 238, 0.28), 0 2px 8px rgba(2, 6, 23, 0.45) !important;\n  letter-spacing: -0.02em !important;\n  transition: color 0.18s ease, text-shadow 0.18s ease;\n}\n\n.dog-calc-error.dog-calc-screen {\n  border-color: rgba(248, 113, 113, 0.42) !important;\n  box-shadow:\n    inset 0 0 30px rgba(248, 113, 113, 0.10),\n    0 12px 26px rgba(2, 6, 23, 0.22) !important;\n}\n\n.dog-calc-error .dog-calc-expression {\n  color: rgba(253, 164, 175, 0.92) !important;\n}\n\n.dog-calc-error .dog-calc-current {\n  color: #fecaca !important;\n  text-shadow: 0 0 20px rgba(248, 113, 113, 0.36), 0 2px 8px rgba(2, 6, 23, 0.45) !important;\n}\n\n.dog-calc-keypad {\n  display: grid !important;\n  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;\n  gap: 12px !important;\n}\n\n.dog-calc-btn {\n  appearance: none !important;\n  -webkit-appearance: none !important;\n  position: relative;\n  width: 100%;\n  height: 60px;\n  border: 1px solid rgba(148, 163, 184, 0.16) !important;\n  border-radius: 16px !important;\n  background:\n    linear-gradient(180deg, rgba(51, 65, 85, 0.92), rgba(15, 23, 42, 0.96)) !important;\n  color: #f8fafc !important;\n  font-family: inherit !important;\n  font-size: 20px !important;\n  font-weight: 500 !important;\n  line-height: 1 !important;\n  cursor: pointer !important;\n  display: block;\n  padding: 0;\n  margin: 0;\n  box-shadow:\n    0 8px 20px rgba(2, 6, 23, 0.24),\n    inset 0 1px rgba(255, 255, 255, 0.07) !important;\n  transition:\n    transform 0.10s ease,\n    border-color 0.18s ease,\n    box-shadow 0.18s ease,\n    filter 0.18s ease,\n    background-color 0.18s ease;\n  outline: none !important;\n  z-index: 1;\n}\n\n.dog-calc-btn::before {\n  content: \"\";\n  position: absolute;\n  inset: -1px;\n  border-radius: inherit;\n  background: linear-gradient(135deg, rgba(34, 211, 238, 0.10), rgba(129, 140, 248, 0.06));\n  opacity: 0;\n  pointer-events: none;\n  transition: opacity 0.18s ease;\n}\n\n.dog-calc-btn:hover::before {\n  opacity: 1;\n}\n\n.dog-calc-btn:hover {\n  transform: translateY(-1px);\n  border-color: rgba(34, 211, 238, 0.28) !important;\n  box-shadow:\n    0 12px 26px rgba(2, 6, 23, 0.28),\n    0 0 18px rgba(34, 211, 238, 0.07),\n    inset 0 1px rgba(255, 255, 255, 0.10) !important;\n  filter: brightness(1.12);\n}\n\n.dog-calc-btn:active {\n  transform: translateY(1px) scale(0.98);\n  border-color: rgba(34, 211, 238, 0.38) !important;\n  box-shadow:\n    0 4px 12px rgba(2, 6, 23, 0.24),\n    inset 0 0 14px rgba(34, 211, 238, 0.08),\n    inset 0 1px rgba(255, 255, 255, 0.06) !important;\n  filter: brightness(1.05);\n}\n\n.dog-calc-btn:focus-visible {\n  border-color: rgba(34, 211, 238, 0.58) !important;\n  box-shadow:\n    0 0 0 2px rgba(34, 211, 238, 0.18),\n    0 10px 22px rgba(2, 6, 23, 0.28),\n    inset 0 1px rgba(255, 255, 255, 0.08) !important;\n}\n\n.dog-calc-btn-num {\n  background:\n    linear-gradient(180deg, rgba(15, 23, 42, 0.94), rgba(2, 6, 23, 0.98)) !important;\n  color: #e5e7eb !important;\n}\n\n.dog-calc-btn-num:hover {\n  background:\n    linear-gradient(180deg, rgba(30, 41, 59, 0.96), rgba(15, 23, 42, 0.98)) !important;\n}\n\n.dog-calc-btn-func {\n  background:\n    linear-gradient(180deg, rgba(51, 65, 85, 0.86), rgba(15, 23, 42, 0.94)) !important;\n  color: #a5f3fc !important;\n}\n\n.dog-calc-btn-func:hover {\n  background:\n    linear-gradient(180deg, rgba(71, 85, 105, 0.88), rgba(30, 41, 59, 0.96)) !important;\n}\n\n.dog-calc-btn-op {\n  background:\n    linear-gradient(180deg, #38bdf8, #0284c7) !important;\n  color: #082032 !important;\n  font-weight: 700 !important;\n  border-color: rgba(56, 189, 248, 0.32) !important;\n  box-shadow:\n    0 8px 22px rgba(2, 6, 23, 0.24),\n    0 0 18px rgba(56, 189, 248, 0.18),\n    inset 0 1px rgba(255, 255, 255, 0.18) !important;\n}\n\n.dog-calc-btn-op:hover {\n  background:\n    linear-gradient(180deg, #7dd3fc, #0ea5e9) !important;\n  border-color: rgba(125, 211, 252, 0.44) !important;\n  box-shadow:\n    0 12px 26px rgba(2, 6, 23, 0.28),\n    0 0 22px rgba(56, 189, 248, 0.24),\n    inset 0 1px rgba(255, 255, 255, 0.22) !important;\n}\n\n.dog-calc-btn-eq {\n  background:\n    linear-gradient(135deg, #22d3ee, #818cf8) !important;\n  color: #071018 !important;\n  font-weight: 800 !important;\n  border-color: rgba(129, 140, 248, 0.34) !important;\n  box-shadow:\n    0 10px 26px rgba(2, 6, 23, 0.30),\n    0 0 22px rgba(34, 211, 238, 0.18),\n    inset 0 1px rgba(255, 255, 255, 0.22) !important;\n}\n\n.dog-calc-btn-eq:hover {\n  background:\n    linear-gradient(135deg, #67e8f9, #a5b4fc) !important;\n  border-color: rgba(165, 180, 252, 0.46) !important;\n  box-shadow:\n    0 14px 30px rgba(2, 6, 23, 0.34),\n    0 0 26px rgba(34, 211, 238, 0.24),\n    inset 0 1px rgba(255, 255, 255, 0.26) !important;\n}\n\n@media (max-width: 420px) {\n  .dog-calculator,\n  #dog-calculator-root.dog-calculator {\n    margin: 14px auto !important;\n    padding: 16px !important;\n    border-radius: 24px !important;\n  }\n\n  .dog-calc-screen {\n    min-height: 96px !important;\n    padding: 14px 16px 18px !important;\n    margin-bottom: 14px !important;\n  }\n\n  .dog-calc-current {\n    font-size: 36px !important;\n  }\n\n  .dog-calc-btn {\n    height: 56px;\n    border-radius: 14px !important;\n    font-size: 19px !important;\n  }\n}\n  `;\n\n  function injectDomStyle() {\n    if (document.getElementById(styleId)) return;\n\n    const style = document.createElement('style');\n    style.id = styleId;\n    style.textContent = css;\n\n    const target = document.head || document.body || document.documentElement;\n    if (target) {\n      target.appendChild(style);\n    } else {\n      setTimeout(injectDomStyle, 50);\n    }\n  }\n\n  injectDomStyle();\n\n  if (typeof Dog !== 'undefined' && typeof Dog.addStyle === 'function') {\n    if (!window.__dogCalculatorDogStyleInjected) {\n      try {\n        Dog.addStyle(css);\n        window.__dogCalculatorDogStyleInjected = true;\n      } catch (e) {}\n    }\n  }\n\n  const root = document.createElement('div');\n  root.id = rootId;\n  root.className = 'dog-calculator';\n  root.tabIndex = 0;\n  root.setAttribute('aria-label', 'Dog Calculator');\n\n  root.style.setProperty('display', 'block', 'important');\n  root.style.setProperty('visibility', 'visible', 'important');\n  root.style.setProperty('opacity', '1', 'important');\n  root.style.setProperty('position', 'relative', 'important');\n  root.style.setProperty('z-index', '999999', 'important');\n  root.style.setProperty('user-select', 'none', 'important');\n  root.style.setProperty('pointer-events', 'auto', 'important');\n\n  root.innerHTML = `\n    <div class=\"dog-calc-screen\">\n      <div class=\"dog-calc-expression\"></div>\n      <div class=\"dog-calc-current\">0</div>\n    </div>\n    <div class=\"dog-calc-keypad\"></div>\n  `;\n\n  function mount() {\n    if (document.body) {\n      if (document.getElementById(rootId) !== root) {\n        document.body.appendChild(root);\n      }\n    } else {\n      setTimeout(mount, 50);\n    }\n  }\n\n  if (document.readyState === 'loading') {\n    document.addEventListener('DOMContentLoaded', mount, { once: true });\n  } else {\n    mount();\n  }\n\n  const screen = root.querySelector('.dog-calc-screen');\n  const expressionEl = root.querySelector('.dog-calc-expression');\n  const currentEl = root.querySelector('.dog-calc-current');\n  const keypad = root.querySelector('.dog-calc-keypad');\n\n  const buttons = [\n    { label: 'AC', value: 'clear', className: 'dog-calc-btn-func' },\n    { label: '⌫', value: 'backspace', className: 'dog-calc-btn-func' },\n    { label: '%', value: 'percent', className: 'dog-calc-btn-func' },\n    { label: '÷', value: '/', className: 'dog-calc-btn-op' },\n\n    { label: '7', value: '7', className: 'dog-calc-btn-num' },\n    { label: '8', value: '8', className: 'dog-calc-btn-num' },\n    { label: '9', value: '9', className: 'dog-calc-btn-num' },\n    { label: '×', value: '*', className: 'dog-calc-btn-op' },\n\n    { label: '4', value: '4', className: 'dog-calc-btn-num' },\n    { label: '5', value: '5', className: 'dog-calc-btn-num' },\n    { label: '6', value: '6', className: 'dog-calc-btn-num' },\n    { label: '−', value: '-', className: 'dog-calc-btn-op' },\n\n    { label: '1', value: '1', className: 'dog-calc-btn-num' },\n    { label: '2', value: '2', className: 'dog-calc-btn-num' },\n    { label: '3', value: '3', className: 'dog-calc-btn-num' },\n    { label: '+', value: '+', className: 'dog-calc-btn-op' },\n\n    { label: '±', value: 'sign', className: 'dog-calc-btn-func' },\n    { label: '0', value: '0', className: 'dog-calc-btn-num' },\n    { label: '.', value: '.', className: 'dog-calc-btn-num' },\n    { label: '=', value: 'equals', className: 'dog-calc-btn-eq' }\n  ];\n\n  buttons.forEach(function (item) {\n    const btn = document.createElement('button');\n    btn.type = 'button';\n    btn.className = 'dog-calc-btn ' + item.className;\n    btn.textContent = item.label;\n    btn.dataset.value = item.value;\n    keypad.appendChild(btn);\n  });\n\n  let current = '0';\n  let previous = null;\n  let operator = null;\n  let resetNext = true;\n  let expression = '';\n  let error = false;\n\n  function opSymbol(op) {\n    if (op === '*') return '×';\n    if (op === '/') return '÷';\n    if (op === '-') return '−';\n    return op;\n  }\n\n  function formatNumber(value) {\n    if (!isFinite(value)) return 'Error';\n    if (value === 0) return '0';\n\n    let str = String(value);\n\n    if (str.length > 15) {\n      const rounded = Number(value.toPrecision(12));\n      str = String(rounded);\n    }\n\n    return str;\n  }\n\n  function updateDisplay() {\n    currentEl.textContent = current;\n    expressionEl.textContent = expression || '\\u00A0';\n    screen.classList.toggle('dog-calc-error', error);\n  }\n\n  function resetAll() {\n    current = '0';\n    previous = null;\n    operator = null;\n    resetNext = true;\n    expression = '';\n    error = false;\n    updateDisplay();\n  }\n\n  function evaluate(a, b, op) {\n    const x = parseFloat(a);\n    const y = parseFloat(b);\n\n    if (isNaN(x) || isNaN(y)) {\n      return { ok: false };\n    }\n\n    let result;\n\n    switch (op) {\n      case '+':\n        result = x + y;\n        break;\n      case '-':\n        result = x - y;\n        break;\n      case '*':\n        result = x * y;\n        break;\n      case '/':\n        if (y === 0) {\n          return { ok: false, error: true };\n        }\n        result = x / y;\n        break;\n      default:\n        return { ok: false };\n    }\n\n    return {\n      ok: true,\n      result: formatNumber(result)\n    };\n  }\n\n  function calculate() {\n    if (operator === null || previous === null) return false;\n\n    const res = evaluate(previous, current, operator);\n\n    if (!res.ok) {\n      error = true;\n      current = 'Error';\n      expression = 'Error';\n      operator = null;\n      previous = null;\n      resetNext = true;\n      updateDisplay();\n      return false;\n    }\n\n    current = res.result;\n    previous = res.result;\n    operator = null;\n    resetNext = true;\n    return true;\n  }\n\n  function inputDigit(d) {\n    if (error) resetAll();\n\n    if (resetNext) {\n      current = d;\n      resetNext = false;\n    } else {\n      current = current === '0' ? d : current + d;\n    }\n\n    updateDisplay();\n  }\n\n  function inputDecimal() {\n    if (error) resetAll();\n\n    if (resetNext) {\n      current = '0.';\n      resetNext = false;\n    } else if (current.indexOf('.') === -1) {\n      current += '.';\n    }\n\n    updateDisplay();\n  }\n\n  function inputOperator(op) {\n    if (error) return;\n\n    if (operator !== null && previous !== null) {\n      if (!resetNext) {\n        if (!calculate()) return;\n      } else {\n        operator = op;\n        expression = previous + ' ' + opSymbol(op);\n        updateDisplay();\n        return;\n      }\n    }\n\n    previous = current;\n    operator = op;\n    resetNext = true;\n    expression = previous + ' ' + opSymbol(op);\n    updateDisplay();\n  }\n\n  function equals() {\n    if (error) return;\n\n    if (operator !== null && previous !== null) {\n      expression = previous + ' ' + opSymbol(operator) + ' ' + current + ' =';\n\n      if (!calculate()) {\n        updateDisplay();\n        return;\n      }\n\n      expression = current;\n      operator = null;\n      previous = null;\n      resetNext = true;\n      updateDisplay();\n    } else {\n      expression = current;\n      resetNext = true;\n      updateDisplay();\n    }\n  }\n\n  function backspace() {\n    if (error) {\n      resetAll();\n      return;\n    }\n\n    if (resetNext) {\n      current = '0';\n      resetNext = false;\n    } else if (current.length > 1) {\n      current = current.slice(0, -1);\n\n      if (current === '-' || current === '-0') {\n        current = '0';\n      }\n    } else {\n      current = '0';\n      resetNext = true;\n    }\n\n    updateDisplay();\n  }\n\n  function toggleSign() {\n    if (error) return;\n\n    if (resetNext) {\n      current = '0';\n      resetNext = false;\n    }\n\n    if (current === '0' || current === '0.') return;\n\n    if (current.charAt(0) === '-') {\n      current = current.slice(1);\n    } else {\n      current = '-' + current;\n    }\n\n    updateDisplay();\n  }\n\n  function percent() {\n    if (error) return;\n\n    const value = parseFloat(current);\n    if (isNaN(value)) return;\n\n    current = formatNumber(value / 100);\n    resetNext = false;\n    updateDisplay();\n  }\n\n  function handle(value) {\n    if (/^[0-9]$/.test(value)) {\n      inputDigit(value);\n    } else if (value === '.') {\n      inputDecimal();\n    } else if (value === '+' || value === '-' || value === '*' || value === '/') {\n      inputOperator(value);\n    } else if (value === 'equals') {\n      equals();\n    } else if (value === 'clear') {\n      resetAll();\n    } else if (value === 'backspace') {\n      backspace();\n    } else if (value === 'sign') {\n      toggleSign();\n    } else if (value === 'percent') {\n      percent();\n    }\n  }\n\n  keypad.addEventListener('click', function (e) {\n    const btn = e.target.closest('button');\n    if (!btn) return;\n\n    handle(btn.dataset.value);\n  });\n\n  root.addEventListener('keydown', function (e) {\n    if (e.ctrlKey || e.metaKey || e.altKey) return;\n\n    const ae = document.activeElement;\n    if (\n      ae &&\n      (\n        ae.tagName === 'INPUT' ||\n        ae.tagName === 'TEXTAREA' ||\n        ae.tagName === 'SELECT' ||\n        ae.isContentEditable\n      )\n    ) {\n      return;\n    }\n\n    const key = e.key;\n\n    if (key >= '0' && key <= '9') {\n      inputDigit(key);\n    } else if (key === '.') {\n      inputDecimal();\n    } else if (key === '+' || key === '-' || key === '*' || key === '/') {\n      inputOperator(key);\n    } else if (key === 'Enter' || key === '=') {\n      e.preventDefault();\n      equals();\n    } else if (key === 'Backspace') {\n      e.preventDefault();\n      backspace();\n    } else if (key === 'Escape' || key === 'Delete') {\n      resetAll();\n    } else if (key === '%') {\n      percent();\n    }\n  });\n\n  window.__dogCalculatorCleanup = function () {\n    const r = document.getElementById(rootId);\n    if (r) r.remove();\n\n    const s = document.getElementById(styleId);\n    if (s) s.remove();\n  };\n\n  updateDisplay();\n})();","source":"","installTime":1749434109652,"author":"script dog","version":"1.0.0","enabled":true,"runAt":"document_idle","showRunLogo":true,"useDog":true,"useGM":false,"templates":{},"requires":[],"window":{"icon":"","width":"360","height":"550","left":"","top":""},"size":18872,"updateTime":1791523718180,"programmingType":"text","loading":false}