-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
1 lines (1 loc) · 5.93 KB
/
script.js
1
const editor=CodeMirror(document.getElementById("editor"),{mode:"markdown",theme:"3024-night",lineNumbers:!0,lineWrapping:!0,autoCloseBrackets:!0,matchBrackets:!0}),initialContent="# Hello, Markdown World!\nThis is a default content.\n- Ali Hamza Kamboh \n# Markdown2PDF \n[https://EasyDoc.alihamzakamboh.com/](https://EasyDoc.alihamzakamboh.com/)\n> Awesome Markdown to PDF!\n```diff\n- Online? Upload resume.md to stranger server?\n+ Try Offline Web App!\n```\n\n## How to use md2pdf?\n1. Click button choose `.md` file.\n2. Edit in editor (left panel).\n3. Click **Transform**!\n4. Switch 'Destination' to **Save as PDF**.\n4. **Chrome recommended**\n\n## Tips\n- `Resize` the layout what you want.\n- After click `Transform` button, inverse the checkbox of **'Headers and Footers'**. \n- **反選頁首與頁尾**.\n\n## What's special?\n## Profile \n- Github: [@ahkamboh](https://github.com/ahkamboh)\n- Project: md2pdf (Markdown2PDF)\n- What about me: ☕ 、 \uD83D\uDC68\uD83C\uDFFB\uD83D\uDCBB️、 \uD83C\uDF55、 \uD83C\uDF9E️\n## Code Like this\n```javascript\n// index.js\n function Hello(){\nconsole.log('World!'}\nHello();\n```";editor.setValue("# Hello, Markdown World!\nThis is a default content.\n- Ali Hamza Kamboh \n# Markdown2PDF \n> Awesome Markdown to PDF!\n```diff\n- Online? Upload resume.md to stranger server?\n+ Try Offline Web App!\n```\n\n## How to use md2pdf?\n1. Click button choose `.md` file.\n2. Edit in editor (left panel).\n3. Click **Transform**!\n4. Switch 'Destination' to **Save as PDF**.\n4. **Chrome recommended**\n\n## Tips\n- `Resize` the layout what you want.\n- After click `Transform` button, inverse the checkbox of **'Headers and Footers'**. \n- **反選頁首與頁尾**.\n\n## What's special?\n## Profile \n- Github: [@ahkamboh](https://github.com/ahkamboh)\n- Project: md2pdf (Markdown2PDF)\n- What about me: ☕ 、 \uD83D\uDC68\uD83C\uDFFB\uD83D\uDCBB️、 \uD83C\uDF55、 \uD83C\uDF9E️\n## Code Like this\n```javascript\n// index.js\n function Hello(){\nconsole.log('World!'}\nHello();\n```");const converter=new showdown.Converter({extensions:["table"]});function updatePreview(){let e=editor.getValue(),t=converter.makeHtml(e);document.getElementById("output").innerHTML=t,Prism.highlightAll()}function changeTheme(){let e=document.getElementById("themeSelector").value;editor.setOption("theme",e),preview.classList.remove(...preview.classList),preview.classList.add(e)}editor.on("change",updatePreview),window.addEventListener("load",()=>{updatePreview()}),window.jsPDF=window.jspdf.jsPDF;var docPDF=new jsPDF;function downloadPDF(e){updatePreview();var t=document.querySelector("#output");docPDF.html(t,{callback:function(t){t.save(e+".pdf")},x:15,y:15,width:170,windowWidth:650})}let profileCard=document.querySelector(".profile-card"),html=document.querySelector("html");document.querySelector(".circle-1").addEventListener("click",()=>{profileCard.style.display="grid",html.style.overflow="hidden"}),profileCard.addEventListener("click",()=>{profileCard.style.display="none",html.style.overflow="visible"});let output=document.querySelector("#preview"),ide=document.querySelector("#editor"),previewBtnName=document.querySelector("#previewBtnName");function hideLoader(){document.querySelector(".loader-container").style.display="none"}document.querySelector(".previewBtn").addEventListener("click",()=>{ide.classList.toggle("hiddenIde"),"grid"===output.style.display?(output.style.display="none",previewBtnName.textContent="Preview"):(output.style.display="grid",previewBtnName.textContent="Go Back")}),lucide.createIcons(),window.addEventListener("load",function(){setTimeout(hideLoader,7e3)}),window.onbeforeunload=e=>(e.preventDefault(),"");const ky=document.getElementById("xcdsasasasa").value,promptInput=document.getElementById("messageInput"),generateButton=document.querySelector("#sendButton");let promptCount=0;async function generateMarkdown(e){try{let t=await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=${ky}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({contents:[{parts:[{text:e}]}],generationConfig:{temperature:.7,topK:40,topP:.95,maxOutputTokens:1024}})});if(!t.ok)throw Error("API request failed");let n=await t.json();return n.candidates[0].content.parts[0].text}catch(o){return console.error("Error:",o),"An error occurred while generating the markdown."}}function handleCustomResponse(e){let t=e.toLowerCase().trim();switch(t){case"who are you?":case"who are y":case"who are":return"I am Ahkamboh, I'm trained on large amounts of publicly available data and I can communicate and generate human-like text in response to a wide range of questions. Just try me out and see what I can do for you.";case"who are you":case"who ar you":return"I am Ahkamboh, trained by Google. I am designed to provide information and answer questions to the best of my abilities. How can I assist you?";case"what is your name?":return"My name is Ahkamboh. How can I assist you today?";case"identify yourself":return"I am Ahkamboh, an AI assistant trained by Google. How can I help you?";case"tell me about yourself":return"I am Ahkamboh, a virtual assistant designed to assist with information and generate human-like text based on input prompts.";case"explain yourself":return"I am Ahkamboh, an AI assistant created to answer questions and generate text based on provided prompts.";case"are you human?":return"I am Ahkamboh, an AI assistant trained to mimic human-like responses. How can I assist you today?";default:return null}}generateButton.addEventListener("click",async()=>{if(promptCount<5){let e=promptInput.value.trim();if(e){editor.setValue("Generating...");let t,n=handleCustomResponse(e);n?(editor.setValue(n),promptCount++):(t=await generateMarkdown(e),editor.setValue(t),promptCount++),5===promptCount&&(generateButton.disabled=!0,alert("You have reached the maximum limit of prompts (5)."))}else alert("Please enter a prompt.")}else alert("You have reached the maximum limit of prompts (5).")});