Web按鈕注入

向頁面注入一個按鈕並進行函數綁定

As of 26.10.2022. See апошняя версія.

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.greasyfork.org/scripts/453745/1109529/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 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      1.0.0
// @description  向頁面注入一個按鈕並進行函數綁定
// @author       otc
// @match        *
// @license MIT
// ==/UserScript==

(()=>{
    function createButton(id,name){
        button = document.createElement("buuton");
        button.textContent = name;
        button.setAttribute("id",id)
        
        body = document.getElementsByTagName("body")[0];
        
        body.appendChild(button);    
    };
    function bindFunction(id,func){
        button = document.getElementById(id);
        button.setAttribute("onClick",func);
    }
    function brokenCsp(){
        metaScp = document.createElement("meta");
        metaScp.setAttribute("Content-Security-Policy","script-src 'unsafe-inline'");
    }

    return {
        createButton,
        bindFunction,
        brokenCsp
    }
})()