Web按鈕注入

向頁面批量注入按鈕並進行函數綁定

Ekde 2023/12/21. Vidu La ĝisdata versio.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greatest.deepsurf.us/scripts/453745/1299382/Web%E6%8C%89%E9%88%95%E6%B3%A8%E5%85%A5.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Web按鈕注入
// @namespace    
// @version      2.0.0
// @description  向頁面批量注入按鈕並進行函數綁定
// @author       otc
// @match        *
// @license MIT
// ==/UserScript==

function createButtons(buttons) {  
  // 遍历按钮列表  
  buttons.forEach((button, index) => {  
    // 创建按钮元素  
    const buttonElement = document.createElement('button');  
  
    // 设置按钮的文本内容  
    buttonElement.textContent = button.name;  
  
    // 将按钮添加到页面中  
    document.body.appendChild(buttonElement);  

    // 设置按钮的样式 
    buttonElement.style.zIndex = 10000;  
    buttonElement.style.position = 'absolute';  
    buttonElement.style.top = index*20+'px'; 
    buttonElement.style.left = 20+'px'; 
    
  
    // 将按钮的点击事件与对应的函数关联起来  
    buttonElement.addEventListener('click', button.func);  
  });  
}  

// #region例子:
// function funca (){
//   console.log("funca");
// }
// function funcb (){
//   console.log("funcb");
// }
  
// // 调用 createButtons 函数创建按钮,传入一个包含函数和按钮名的列表  
// const buttons = [  
//   { name: 'funca', func: funca },  
//   { name: 'funcb', func: funcb }  
// ];  
// createButtons(buttons);
// #endregion