Last active
May 4, 2020 13:17
-
-
Save jackbaty/bc6d8e5fe4d25a94206c4b7b6db0d7d0 to your computer and use it in GitHub Desktop.
Bookmarklet for adding quotes to org-mode
This file contains 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
Copied and modified from someone's (Anne-Laure Le Cunff?) Roam bookmarklet | |
javascript:(function(){let sel=document.getSelection();let selText="";const reference=`[[${location.href}][${document.title}]] `;const%20selectedRanges=[];if(sel.rangeCount>1){selText=reference+"\n";for(let%20i=0;i<sel.rangeCount;i+=1){selText+=`\t/${sel.getRangeAt(i).toString().trim()}/%20\n`;selectedRanges.push(sel.getRangeAt(i))}}else{selText=sel.toString().trim();if(selText.length){selectedRanges.push(sel.getRangeAt(0));selText=`/${%20selText%20}/%20via%20`}selText+=reference}const%20ta=document.createElement("textarea");ta.textContent=`${%20selText%20}`;document.body.appendChild(ta);const%20docSel=document.getSelection();docSel.removeAllRanges();ta.select();document.execCommand("copy");docSel.removeAllRanges();document.body.removeChild(ta);let%20newSel=document.getSelection();for(let%20i=0;i<selectedRanges.length;i+=1){newSel.addRange(selectedRanges[i])}let%20toaster=document.createElement("div");toaster.innerHTML=`Copied!`;toaster.style.position="fixed";toaster.style.display="block";toaster.style.right="10px";toaster.style.top="10px";toaster.style.backgroundColor="red";toaster.style.color="#FFFFFF";toaster.style.padding="5px";toaster.style.borderRadius="5px";toaster.style.zIndex="99999";document.body.appendChild(toaster);setTimeout(function(){toaster.style.opacity=0;toaster.style.transition="opacity%202s"},2000);setTimeout(function(){document.body.removeChild(toaster)},4000)})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated with improved version from Ryan Gaul