-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
1 lines (1 loc) · 1.95 KB
/
index.js
1
"use strict";function byteFormat(e){let t;return e>=1e12?(e=(e/1099511627776).toFixed(2),t="TB"):e>=1e9?(e=(e/1073741824).toFixed(2),t="GB"):e>=1e6?(e=(e/1048576).toFixed(2),t="MB"):e>=1e3?(e=(e/1024).toFixed(2),t="KB"):t="B",`${e} ${t}`}function parseResponseHeaders(e){let t={};return e=e.split(/\r?\n/g).filter(e=>""!==e).map(e=>e=e.split(/:\s/g)).forEach(e=>t[e[0]]=e[1]),t}function timeFormat(e){let t;return e>=36e5?(e=(e/36e5).toFixed(2),t="h"):e>=6e4?(e=(e/6e4).toFixed(2),t="m"):e>=1e3?(e=(e/1e3).toFixed(2),t="s"):t="ms",`${e} ${t}`}function sendRequest(){event.preventDefault();let e=Date.now();$.ajax({complete:function(t,s){let r=Date.now(),a;a=t.status>=500||t.status>=400&&t.status<500?"danger":t.status>=300&&t.status<400?"warning":t.status>=200&&t.status<300?"success":"secondary",0!==t.status?($("#responseStatus").text(`${t.status} ${httpStatus[t.status]}`),$("#responseStatus").removeClass().addClass(["badge",`text-bg-${a}`]),$("#responseTime").text(`${timeFormat(r-e)}`),$("#responseSize").text(`${byteFormat(JSON.stringify(t.responseJSON).length)}`),$("#responseInfo").show(),$("#responseHeaders").text(JSON.stringify(parseResponseHeaders(t.getAllResponseHeaders()),null,"\t")),$("#responseBody").text(JSON.stringify(t.responseJSON,null,"\t"))):($("#responseHeaders").text("Could not send request"),$("#responseBody").text("Could not send request"))},data:JSON.parse($("#requestBody").val()||"{}"),headers:JSON.parse($("#requestHeaders").val()||"{}"),method:$("#method").val(),url:$("#endpoint").val()})}function setTheme(e=null){if(null!==e){e=JSON.parse(e),$("html").attr("data-bs-theme",e?"dark":"light"),$("#theme").prop("checked",e);return}e=$(event.target).prop("checked"),localStorage.setItem("isDarkMode",e),$("html").attr("data-bs-theme",e?"dark":"light")}$(document).ready(function(){setTheme(localStorage.getItem("isDarkMode"))});$(document).on("scroll",function(){$(document).scrollTop()>20?$("#scrollToTop").fadeIn("fast"):$("#scrollToTop").fadeOut("fast")});