1// Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification 2// for details on configuring this project to bundle and minify static web assets. 3 4import { CodeJar } from "../lib/Prism/codejar.js"; 5 6 7// Responsive nav 8const closeSiderbar = document.querySelector("#closeSidebar"); 9const openSiderbar = document.querySelector("#openSidebar"); 10 11 12closeSiderbar?.addEventListener("click", () => { 13 14 let mobileCanvas = document.querySelector(".mobile"); 15 mobileCanvas.classList.toggle("invisible"); 16}) 17openSiderbar?.addEventListener("click", () => { 18 19 let mobileCanvas = document.querySelector(".mobile"); 20 mobileCanvas.classList.toggle("invisible"); 21}) 22 23function copyToClipboard(text) { 24 if (window.clipboardData && window.clipboardData.setData) { 25 // IE specific code path to prevent textarea being shown while dialog is visible. 26 return clipboardData.setData("Text", text); 27 28 } else if (document.queryCommandSupported && document.queryCommandSupported("copy")) { 29 var textarea = document.createElement("textarea"); 30 textarea.textContent = text; 31 textarea.style.position = "fixed"; // Prevent scrolling to bottom of page in MS Edge. 32 document.body.appendChild(textarea); 33 textarea.select(); 34 try { 35 return document.execCommand("copy"); // Security exception may be thrown by some browsers. 36 } catch (ex) { 37 console.warn("Copy to clipboard failed.", ex); 38 return false; 39 } finally { 40 document.body.removeChild(textarea); 41 } 42 } 43} 44 45const apiKeyField = document.querySelector("#api-key"); 46 if (apiKeyField) { 47 apiKeyField.onclick = function () { 48 copyToClipboard(document.querySelector('.api-key').value); 49 this.innerHTML = this.innerHTML.replace("copy", "copied!"); 50 window.setTimeout(() => { 51 this.innerHTML = this.innerHTML.replace("copied!", "copy"); 52 }, 1000); 53 }; 54 } 55 56 57function tryParseJSON (jsonString){ 58 try { 59 const o = JSON.parse(jsonString); 60 61 // Handle non-exception-throwing cases: 62 // Neither JSON.parse(false) or JSON.parse(1234) throw errors, hence the type-checking, 63 // but... JSON.parse(null) returns null, and typeof null === "object", 64 // so we must check for that, too. Thankfully, null is falsey, so this suffices: 65 if (o && typeof o === "object") { 66 return o; 67 } 68 } 69 catch (e) { } 70 71 return false; 72}; 73 74$(function () { 75 'use strict'; 76 77 const editor = document.querySelector(".editor"); 78 const responseBodyField = document.querySelector(".response-body"); 79 80 if (editor && responseBodyField) { 81 const requestBody = new CodeJar(editor, Prism.highlightElement); 82 const responseBody = new CodeJar(responseBodyField, Prism.highlightElement); 83 //const responseHeader = new CodeJar(document.querySelector(".spam-response-header"), Prism.highlightElement) 84 85 // $('[data-toggle="tooltip"]').tooltip() 86 87 // Fetch all the forms we want to apply custom Bootstrap validation styles to 88 document.getElementById("sendrequest").addEventListener('click', function (event) { 89 event.preventDefault(); 90 event.stopPropagation(); 91 let payload = tryParseJSON(requestBody.toString()) 92 if (!payload) return alert("There is an error in your request JSON - please fix before submitting.") 93 let responsePromise = spamDetection(JSON.stringify(payload)); 94 responsePromise.then(data => { 95 responseBody.updateCode(JSON.stringify(JSON.parse(data), null, 2).trim()); 96 } 97 ); 98 }) 99 } 100 101 $("#planInterval").click(function (e) { 102 console.log("e.target.classList", e.target.classList) 103 if (e.target.classList.contains("monthly") & !document.querySelector('.yearly-price').classList.contains("hidden")) { 104 document.querySelectorAll('.yearly-price').forEach( f => f.classList.toggle("hidden")); 105 document.querySelectorAll('.monthly-price').forEach( f => f.classList.remove("text-strike", "text-secondary")); 106 107 document.querySelectorAll('.btn-monthly').forEach( f => f.classList.remove("block", "hidden")); 108 document.querySelectorAll('.btn-yearly').forEach( f => f.classList.remove("block", "hidden")); 109 110 document.querySelectorAll('.btn-yearly').forEach( f => f.classList.toggle("hidden")); 111 document.querySelectorAll('.btn-monthly').forEach( f => f.classList.add("block")); 112 } else if(e.target.classList.contains("yearly") & document.querySelector('.yearly-price').classList.contains("hidden")) { 113 // annual 114 document.querySelectorAll('.yearly-price').forEach( f => f.classList.remove("hidden")); 115 document.querySelectorAll('.monthly-price').forEach( f => f.classList.add("text-strike", "text-secondary")); 116 117 document.querySelectorAll('.btn-monthly').forEach( f => f.classList.remove("block", "hidden")); 118 document.querySelectorAll('.btn-yearly').forEach( f => f.classList.remove("block", "hidden")); 119 120 document.querySelectorAll('.btn-monthly').forEach( f => f.classList.remove("block")); 121 document.querySelectorAll('.btn-yearly').forEach( f => f.classList.toggle("block")); 122 document.querySelectorAll('.btn-monthly').forEach( f => f.classList.add("hidden")); 123 } 124 }) 125}) 126 127
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.