Web按鈕注入

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

Version vom 21.12.2023. Aktuellste Version

Dieses Skript sollte nicht direkt installiert werden. Es handelt sich hier um eine Bibliothek für andere Skripte, welche über folgenden Befehl in den Metadaten eines Skriptes eingebunden wird // @require https://update.greasyfork.org/scripts/453745/1299382/Web%E6%8C%89%E9%88%95%E6%B3%A8%E5%85%A5.js

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

You will need to install an extension such as Tampermonkey 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.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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