Last active
October 28, 2024 01:01
-
-
Save andrewpomeroy/899fcf8ead9059579c44e27b6211bb18 to your computer and use it in GitHub Desktop.
Bookmarklet: OneTab export ➡️ Markdown links
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:(()%3D%3E%7Bfunction%20copyToClipboard(e)%7Bvar%20t%3Do%3D%3E%7Bdocument.removeEventListener(%22copy%22%2Ct%2C!0)%2Co.preventDefault()%3Blet%20n%3Do.clipboardData%3Bn.clearData()%2Cn.setData(%22text%2Fplain%22%2Ce)%7D%3Bdocument.addEventListener(%22copy%22%2Ct%2C!0)%2Cdocument.execCommand(%22copy%22)%7Dfunction%20main()%7Blet%20e%3Ddocument.querySelectorAll(%22.tabGroup%20.tabLink%22)%3Bif(!e.length)return%20void%20alert(%22No%20tabs%20found%22)%3Bconst%20t%3DArray.from(e).map((e%3D%3E%60%5B%24%7Be.textContent%7D%5D(%24%7Be.href%7D)%60)).join(%22%5Cn%5Cn%22)%3Bconsole.log(t)%2CcopyToClipboard(t)%7Dmain()%3B%7D)()%3B |
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
| function copyToClipboard(data) { | |
| var copyListener = event => { | |
| document.removeEventListener("copy", copyListener, true); | |
| event.preventDefault(); | |
| let clipboardData = event.clipboardData; | |
| clipboardData.clearData(); | |
| clipboardData.setData("text/plain", data); | |
| }; | |
| document.addEventListener("copy", copyListener, true); | |
| document.execCommand("copy"); | |
| } | |
| function main() { | |
| let tabs = document.querySelectorAll('.tabGroup .tabLink') | |
| if (!tabs.length) { | |
| alert('No tabs found'); | |
| return; | |
| } | |
| const markdownLinks = Array.from(tabs).map(tab => { | |
| debugger; | |
| const text = tab.textContent; | |
| const href = tab.href; | |
| const markdownLink = `[${text}](${href})`; | |
| return markdownLink; | |
| }); | |
| const result = markdownLinks.join('\n\n'); | |
| console.log(result); | |
| copyToClipboard(result); | |
| } | |
| main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment