Web按鈕注入

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

当前为 2022-10-26 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/453745/1109529/Web%E6%8C%89%E9%88%95%E6%B3%A8%E5%85%A5.js

  1. // ==UserScript==
  2. // @name Web按鈕注入
  3. // @namespace
  4. // @version 1.0.0
  5. // @description 向頁面注入一個按鈕並進行函數綁定
  6. // @author otc
  7. // @match *
  8. // @license MIT
  9. // ==/UserScript==
  10.  
  11. (()=>{
  12. function createButton(id,name){
  13. button = document.createElement("buuton");
  14. button.textContent = name;
  15. button.setAttribute("id",id)
  16. body = document.getElementsByTagName("body")[0];
  17. body.appendChild(button);
  18. };
  19. function bindFunction(id,func){
  20. button = document.getElementById(id);
  21. button.setAttribute("onClick",func);
  22. }
  23. function brokenCsp(){
  24. metaScp = document.createElement("meta");
  25. metaScp.setAttribute("Content-Security-Policy","script-src 'unsafe-inline'");
  26. }
  27.  
  28. return {
  29. createButton,
  30. bindFunction,
  31. brokenCsp
  32. }
  33. })()