Codemao bcmc edit

bcmc读取与编辑

当前为 2023-12-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Codemao bcmc edit
  3. // @namespace CODEMAO_BCMC_EDIT
  4. // @version 1.1
  5. // @description bcmc读取与编辑
  6. // @author Orangesoft,一只无辜的草方块
  7. // @match https://*.codemao.cn/*
  8. // @require https://cdn.jsdelivr.net/npm/lil-gui@0.16
  9. // @require https://cdn.jsdelivr.net/npm/three@0.142.0/examples/js/libs/stats.min.js
  10. // @require https://unpkg.com/mdui@1.0.2/dist/js/mdui.min.js
  11. // @license MIT
  12. // @grant GM_xmlhttpRequest
  13. // @compatible edge
  14. // @compatible chrome
  15. // @icon https://cdn-community.codemao.cn/community_frontend/asset/cute_4caf9.png
  16. // ==/UserScript==
  17.  
  18. var getworkid = () => location.href.substring(location.href.lastIndexOf('/') + 1,location.href.length)
  19.  
  20. function geth (sth){
  21. return document.getElementsByClassName(sth)
  22. }
  23.  
  24. function log (messge){
  25. console.log(
  26. '%c %s %c %s',
  27. 'border: 1px solid white;border-radius: 3px 0 0 3px;padding: 2px 5px;color: white;background-color: green;',
  28. '[Codemao bcmc edit 1.0]',
  29. 'border: 1px solid white;border-radius: 0 3px 3px 0;padding: 2px 5px;color: black;background-color: white;border-left: none;',
  30. messge
  31. );
  32. }
  33.  
  34. (function() {
  35. if(window.location.pathname.indexOf("/work/")+1) {
  36. let player_url = 'https://player.codemao.cn/new/'
  37. if (geth('r-work-c-work_info--work_tool r-work-c-work_info--kitten3')[0] != null)player_url = 'https://player.codemao.cn/w/'
  38. else if(geth('r-work-c-work_info--work_tool r-work-c-work_info--kitten4')[0] != null)player_url = 'https://player.codemao.cn/new/'
  39. else if(geth('r-work-c-work_info--nemo')[0] != null)player_url = 'https://nemo.codemao.cn/w/'
  40. var under = {
  41. 'not code': () => {
  42. log('not code');
  43. },
  44. 'debugging': () => {
  45. log('debugging');
  46. },
  47. };
  48. var inject= {
  49. '文件': () =>{
  50. const input = document.createElement("input");
  51. input.type = "file";
  52. input.style.display = "none";
  53. input.addEventListener("change", () => {
  54. let reader = new FileReader();
  55. reader.addEventListener("load", () => {
  56. GM_xmlhttpRequest({
  57. method: "post",
  58. url: "https://static.box3.codemao.cn/block",
  59. data: reader.result,
  60. binary: true,
  61. onload({ response }) {
  62. const { Key, Size } = JSON.parse(response);
  63. log("上传成功! Hash: "+Key);
  64. const hash = Key;
  65. input.remove();
  66. prompt('url:',player_url+getworkid()+'?bcmc_url=https://static.box3.codemao.cn/block/'+hash+'.json')
  67. },
  68. });
  69. });
  70. reader.readAsBinaryString(input.files[0]);
  71. });
  72.  
  73. input.click();
  74. },
  75. 'id': () =>{
  76. var wi = prompt('请输入修改bcmc后的作品id','');
  77. GM_xmlhttpRequest({
  78. method:"get",
  79. url:"https://api.codemao.cn/api/v2/work/display/"+wi,
  80. onload({response}){
  81. let res = JSON.parse(response);
  82. console.log(res['data']['work_url'][0]);
  83. prompt('url:',`${player_url}${getworkid()}?bcmc_url=${res['data']['work_url'][0]}`)
  84. }
  85. })
  86. }
  87. }
  88. window.gui = new lil.GUI({ title: '🧰BCMC EDIT TOOLS' });
  89. window.gui.domElement.style.top = 'unset';
  90. window.gui.domElement.style.bottom = '0';
  91. window.gui.domElement.style.userSelect = 'none';
  92. var page1 = gui.addFolder('注入');
  93. page1.add(inject, '文件').name('上传bcmc文件');
  94. page1.add(inject, 'id').name('作品id');
  95. }
  96. })();