Web按鈕注入

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

Tính đến 26-10-2022. Xem phiên bản mới nhất.

Script này sẽ không được không được cài đặt trực tiếp. Nó là một thư viện cho các script khác để bao gồm các chỉ thị meta // @require https://update.greatest.deepsurf.us/scripts/453745/1109529/Web%E6%8C%89%E9%88%95%E6%B3%A8%E5%85%A5.js

// ==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
    }
})()