Web按鈕注入

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

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

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/453745/1109534/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.2
  5. // @description 向頁面注入一個按鈕並進行函數綁定
  6. // @author otc
  7. // @match *
  8. // @license MIT
  9. // ==/UserScript==
  10.  
  11. function createButton(id,name){
  12. button = document.createElement("buuton");
  13. button.textContent = name;
  14. button.setAttribute("id",id)
  15. body = document.getElementsByTagName("body")[0];
  16. body.appendChild(button);
  17. };
  18. function bindFunction(id,func){
  19. button = document.getElementById(id);
  20. button.setAttribute("onClick",func);
  21. }
  22. function brokenCsp(){
  23. metaScp = document.createElement("meta");
  24. metaScp.setAttribute("Content-Security-Policy","script-src 'unsafe-inline'");
  25. }
  26.  
  27. var wi = {
  28. createButton,
  29. bindFunction,
  30. brokenCsp
  31. };