-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMinimizedBookmark.js
1 lines (1 loc) · 2.24 KB
/
MinimizedBookmark.js
1
javascript:(()=>{if(document.URL.toLocaleLowerCase().includes("leetcode")){let e=!0,t=Array.from(document.querySelectorAll('a[href^="/tag/"]')).map(e=>"[["+e.textContent.trim()+"]]").join(", "),l=Array.from(document.querySelectorAll('a[href^="/problems/"]')).filter(e=>""!==e.textContent.trim()&&!document.URL.includes(e.href)&&0===e.children.length).map(e=>"[["+e.textContent.trim()+"]]").join(", "),n="";try{n=Array.from(document.querySelector(".elfjS").children).map(e=>{if("P"===e.tagName){let t=e.cloneNode(!0);return Array.from(t.querySelectorAll("span")).forEach(e=>e.replaceWith(e.textContent)),e.textContent.includes("Example")||e.textContent.includes("Constraints")?"### "+t.textContent+"\n":t.innerHTML}return"PRE"===e.tagName?"```java\n"+e.innerHTML.replaceAll("<strong>","").replaceAll("</strong>","").trim()+"\n```\n":"UL"===e.tagName?Array.from(e.children).map(e=>"- "+e.innerHTML).join("\n"):"IMG"===e.tagName?`![IMG](${e.src})`:""}).filter(Boolean).map(e=>e.replaceAll("<code>","`").replaceAll("</code>","`").replaceAll("<sup>","^").replaceAll("</sup>","").replaceAll(" ","\n").replaceAll("<","<").replaceAll("<strong>","**").replaceAll("</strong>","**").replaceAll("<em>","_").replaceAll("</em>","_")).join("\n")}catch(o){console.log("Failed Question"),console.log(o),e=!1}navigator.clipboard.writeText("Tags: "+t+"\nSimilar Questions: "+l+"\n## Question\n\n"+n+"\n\n## Algorithm\n\n## Code\n\n## Links\n[LeetCode]("+document.URL+")").then(()=>{let t=document.createElement("div");Object.assign(t.style,{position:"fixed",top:"20px",right:"20px",padding:"10px 20px",color:"white",borderRadius:"4px",zIndex:"10000",fontFamily:"Arial, sans-serif",background:e?"#4CAF50":"#d10000"}),t.textContent=e?"Copied to clipboard!":"Check Console for Error",document.body.appendChild(t),setTimeout(()=>document.body.removeChild(t),2e3)}).catch(e=>{console.error("Failed to copy:",e),alert("Failed to copy to clipboard")})}else{let r=document.createElement("div");Object.assign(r.style,{position:"fixed",top:"20px",right:"20px",padding:"10px 20px",color:"white",borderRadius:"4px",zIndex:"10000",fontFamily:"Arial, sans-serif",background:"#d10000"}),r.textContent="Not on Leetcode You Fucking Idiot",document.body.appendChild(r),setTimeout(()=>document.body.removeChild(r),1e4)}})();