谷歌插件编写

目录

manifest.json

{
    "manifest_version": 3,
    "name": "Floating Ball",
    "version": "1.0",
    "description": "A floating ball on the right side of the webpage.",
    "permissions": ["activeTab"],
    "action": {
      "default_popup": "popup.html",
      "default_icon": {
        "16": "1.jpg"
      }
    },
    "content_scripts": [
      {
        "matches": ["<all_urls>"],
        "js": ["content.js"]
      }
    ]
  }
  

popup.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>小宠物插件</title>
    <style>
        #root {
            width: 200px;
        }
    </style>
</head>

<body>
    <div id="root">
        <div>悬浮球插件</div>
        <div>Copyright (c) 2024, Qvfan</div>
    </div>
</body>

</html>

content.js

const floatingBall = document.createElement('div');
const smallBox = document.createElement('div');

Object.assign(floatingBall.style, {
    position: 'fixed',
    right: '20px',
    bottom: '200px',
    width: '50px',
    height: '50px',
    background: 'url(https://pic4.zhimg.com/80/v2-3628c58a24939a53ffd00bb55ccaa7c3_1440w.webp) no-repeat',
    backgroundSize: 'cover',
    borderRadius: '50%',
    boxShadow: '0 0 10px rgba(0,0,0,0.5)',
    zIndex: '1000',
    cursor: 'pointer'
});

Object.assign(smallBox.style, {
    position: 'absolute',
    top: '-270px',
    left: '-298px',
    width: '300px',
    height: '300px',
    backgroundColor: '#fafafa',
    boxShadow: '0 0 10px rgba(0,0,0,0.5)',
    display: 'none' // 初始时隐藏
});

document.body.appendChild(floatingBall);

floatingBall.appendChild(smallBox);

const showSmallBox = () => {
    smallBox.style.display = 'block';
};

const hideSmallBox = () => {
    smallBox.style.display = 'none';
};


floatingBall.addEventListener('mouseover', showSmallBox);
floatingBall.addEventListener('mouseout', hideSmallBox);

smallBox.addEventListener('mouseover', showSmallBox);
smallBox.addEventListener('mouseout', hideSmallBox);



floatingBall.addEventListener('click', (e) => {
    alert('屈凡的悬浮球被点击了!' + JSON.stringify(e));
});

直接打开

效果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值