Created
May 19, 2025 19:28
-
-
Save parthi2929/e15fffcccc11302058391a595e247251 to your computer and use it in GitHub Desktop.
A bookmarklet to store text snippets (ex, a python code). Its obfuscated to fit avoid getting truncated due to bookmarklet size issues.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(function(){function utf8_to_b64(str){return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,function(match,p1){return String.fromCharCode('0x'+p1);}));}function b64_to_utf8(str){return decodeURIComponent(Array.prototype.map.call(atob(str),function(c){return'%'+('00'+c.charCodeAt(0).toString(16)).slice(-2);}).join(''));}var initialCode="print('Hello World')";var modal=document.createElement('div');modal.style='position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);width:80%;max-width:800px;max-height:80vh;background:#fff;border-radius:8px;box-shadow:0 0 20px rgba(0,0,0,0.5);z-index:9999;display:flex;flex-direction:column;overflow:hidden;font-family:Arial,sans-serif;';var header=document.createElement('div');header.style='background:#333;color:#fff;padding:10px 15px;font-weight:bold;';header.textContent='Code Snippet Manager';modal.appendChild(header);var content=document.createElement('div');content.style='padding:15px;flex-grow:1;overflow-y:auto;';var textarea=document.createElement('textarea');textarea.style='width:100%;height:200px;font-family:monospace;margin-bottom:10px;border:1px solid #ddd;padding:8px;border-radius:4px;resize:vertical;';textarea.value=localStorage.getItem('snippet')?b64_to_utf8(localStorage.getItem('snippet')):initialCode;content.appendChild(textarea);var statusBox=document.createElement('textarea');statusBox.readOnly=true;statusBox.style='width:100%;height:80px;font-family:monospace;margin-bottom:10px;border:1px solid #ddd;padding:8px;border-radius:4px;resize:none;background:#f8f8f8;';statusBox.value='Ready. '+(localStorage.getItem('snippet')?'Loaded saved snippet.':'Using default snippet.');content.appendChild(statusBox);var buttonRow=document.createElement('div');buttonRow.style='display:flex;gap:10px;margin-top:10px;';var saveBtn=document.createElement('button');saveBtn.textContent='Save';saveBtn.style='padding:8px 15px;background:#4CAF50;color:white;border:none;border-radius:4px;cursor:pointer;flex:1;';saveBtn.onclick=function(){try{localStorage.setItem('snippet',utf8_to_b64(textarea.value));statusBox.style.color='green';statusBox.value='✔ Snippet saved at '+new Date().toLocaleTimeString();}catch(e){statusBox.style.color='red';statusBox.value='✖ Error saving: '+e.message;}statusBox.scrollTop=statusBox.scrollHeight;};var clearBtn=document.createElement('button');clearBtn.textContent='Clear';clearBtn.style='padding:8px 15px;background:#f44336;color:white;border:none;border-radius:4px;cursor:pointer;flex:1;';clearBtn.onclick=function(){if(confirm('Clear current snippet?')){textarea.value='';statusBox.style.color='orange';statusBox.value='✏ Snippet cleared at '+new Date().toLocaleTimeString();statusBox.scrollTop=statusBox.scrollHeight;}};var closeBtn=document.createElement('button');closeBtn.textContent='Close';closeBtn.style='padding:8px 15px;background:#555;color:white;border:none;border-radius:4px;cursor:pointer;flex:1;';closeBtn.onclick=function(){document.body.removeChild(modal);};buttonRow.appendChild(saveBtn);buttonRow.appendChild(clearBtn);buttonRow.appendChild(closeBtn);content.appendChild(buttonRow);modal.appendChild(content);document.body.appendChild(modal);window.addEventListener('scroll',function(){modal.style.top='50%';modal.style.transform='translate(-50%,-50%)';});})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Create a normal bookmark in chrome, and in URL field, enter the above code. You should see something like below, a basic editor.