Markdown Link Capturer
Prompt to GPT used to create this plugin:
This plugin is generated by the following prompt with minor edit of adding count
. Hence the prompt captures its functionality well:
I want tamper monkey plugin in chrome that would allow me to easily snapshot links towards my markdown.
Here is what I want:
- What I open any link the plugin will save the title of the open page to some local storage of the plugin. in the markdown format as
- [<title>](url)
.- Then there should be a way to quickly access these links such as dumping them to clipboard.
- Once the links are dumped to clipboard, they are cleared.
Can we make this happen with Tamper monkey on chrome?
Notes on usage
- Open the links as new tabs.
- Wait for the pages to load prior to exporting the links of newly opened pages
Plugin:
// ==UserScript==
// @name Markdown Link Capturer
// @namespace http://tampermonkey.net/
// @version 0.3
// @description Capture page titles and URLs for markdown usage
// @author Your Name
// @match *://*/*
// @grant GM_setClipboard
// @grant GM_registerMenuCommand
// ==/UserScript==
(function() {
'use strict';
// Function to store the current page title and URL in local storage
function storeLink() {
const title = document.title;
const url = window.location.href;
const markdownLink = `- [${title}](${url})`;
let storedLinks = JSON.parse(localStorage.getItem('markdownLinks')) || [];
storedLinks.push(markdownLink);
localStorage.setItem('markdownLinks', JSON.stringify(storedLinks));
}
// Function to copy links to clipboard and clear local storage
function copyLinksToClipboard() {
const storedLinks = JSON.parse(localStorage.getItem('markdownLinks')) || [];
const count = storedLinks.length;
const linksText = storedLinks.join('\n');
if (linksText) {
GM_setClipboard(linksText);
localStorage.removeItem('markdownLinks');
alert(`${count} Links copied to clipboard and storage cleared!`);
} else {
alert('No links to copy.');
}
}
// Store the current link on page load
storeLink();
// Register the menu command to copy links
GM_registerMenuCommand('Copy Markdown Links to Clipboard', copyLinksToClipboard);
})();