Json2Blob

导入导出json到blob

当前为 2022-09-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Json2Blob
  3. // @namespace http://firefoxcn.net/
  4. // @description 导入导出json到blob
  5. // @version 0.8
  6. // @author Dniness
  7. // @match https://greasyfork.org/*
  8. // @grant none
  9. // @license GPL License
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. let e = document.getElementById("install-area");
  15. e&&!e.Json2BlobFun&&fetch(e.Json2BlobFun = e.firstElementChild.href)
  16. .then(e=>e.text()).then(e=>{
  17. let div = document.getElementById("install-area");
  18. e = eval(e);
  19. let html = Object.keys(e);
  20. html.forEach(c=>{e[c]=JSON.stringify(e[c])});
  21. div.Json2BlobArray = e ;
  22. e = div.Json2BlobFun = e =>{
  23. let x = div.Json2BlobArray[e.outerHTML = e.options[e.selectedIndex].value];
  24. x = new Blob([x], {type: 'text/plain'});
  25. x = URL.createObjectURL(x);
  26. e.outerHTML = '<a href="'+x+'" download="'+e.outerHTML+'.json">右键复制</a>';
  27. }
  28. html.unshift('<select onChange="this.parentNode.Json2BlobFun(this)"><option style="display:none">存在数组引用');
  29. div.innerHTML+=html.join('</option><option>');
  30. }).catch(e=>console.log('not objects of json'));
  31. return {
  32. HeaderEditorCORS:{
  33. "request": [
  34. {
  35. "enable": true,
  36. "name": "跨域js外链式",
  37. "ruleType": "redirect",
  38. "matchType": "prefix",
  39. "pattern": "https://0.0.0.0/fetch.js?",
  40. "exclude": "",
  41. "group": "跨域length128",
  42. "isFunction": true,
  43. "action": "redirect",
  44. "code": "return `data:,(${o=>{\nconst fetch = o.fetch;\no.fetch = (url,opt='')=>(opt.headers = {\n\t\tAccept:(e=>\n\t\t\te.forEach((a,i)=>\n\t\t\t\te[i]=a.join(';')\n\t\t\t)||'-X;-'+e.join(';-')\n\t\t)(Object.entries(opt.headers||''))\n\t})&&fetch(url,opt||opt.o)\n}})(${val.split('?').pop()||'this'})`;"
  45. }
  46. ],
  47. "sendHeader": [
  48. {
  49. "enable": true,
  50. "name": "复杂跨域绕过预检",
  51. "ruleType": "modifySendHeader",
  52. "matchType": "all",
  53. "pattern": "",
  54. "exclude": "",
  55. "group": "跨域length128",
  56. "isFunction": true,
  57. "code": "val.forEach(e=>\ne.name.toLowerCase() === 'accept'&&\ne.value.startsWith('-X;-')?(e.value=\ne.value.split(';-').slice(1).forEach(e=>{let i = e.indexOf(';');\nval.push({\"name\": e.slice(0,i), \"value\": e.slice(1+i)})})||' */*; q=0.01'):\ne.name.toLowerCase() === 'referer'?(e.value=''):\ne.name.toLowerCase() === 'origin'?(e.name = \"H-Referer-Origin\"):0);"
  58. }
  59. ],
  60. "receiveHeader": [
  61. {
  62. "enable": true,
  63. "name": "跨域访问许可",
  64. "ruleType": "modifyReceiveHeader",
  65. "matchType": "all",
  66. "pattern": "",
  67. "exclude": "",
  68. "group": "跨域length128",
  69. "isFunction": true,
  70. "code": "const H={name:\"H-Referer-Origin\"};\ndetail.originUrl&&((S = new Set())=>{ top[H.name] = S ; H.value = \nS.has(detail.id)?'null':detail.originUrl.split('/').slice(0,3).join('/');\nS[(detail.statusCode&0740)===0440?'add':'delete'](detail.id);\n})(top[H.name] );\n(detail.Referer= (detail.requestHeaders||[H]).find(e=>e.name==H.name))&&\n!val.forEach(e=>e.name.toLowerCase()===\"location\"?e.value[4]==':'&&\n(e.value = detail.url.split(':')[0]+e.value.slice(4)):\n(e.name.toLowerCase().startsWith(\"access-control-allow-\")&&e).name+=\"-X\")&&\nval.push({\"name\": \"Access-Control-Allow-Origin\", \"value\":detail.Referer.value})&&\nval.push({\"name\": \"Access-Control-Allow-Credentials\", \"value\": \"true\"})&&\nval.push({\"name\": \"Access-Control-Allow-Headers\", \"value\":detail.Referer.name})&&\nval.push({\"name\": \"Access-Control-Allow-Methods\", \"value\": \"POST,GET,OPTIONS,DELETE\"}); "
  71. }
  72. ],
  73. "receiveBody": []
  74. }
  75. }
  76. })();