Skip to content

Instantly share code, notes, and snippets.

@titangene
Last active July 14, 2023 15:05
Show Gist options
  • Save titangene/e167d6ab66edc1e3a6487f0a5fe03e4c to your computer and use it in GitHub Desktop.
Save titangene/e167d6ab66edc1e3a6487f0a5fe03e4c to your computer and use it in GitHub Desktop.
Convert chrome tab link to footnote link format and copy
(function() {
class MarkdownSyntax {
static getFootNote({ identifier, content }) {
return `${identifier}: ${content}`;
}
static getLink({ title, url }) {
return `[${title}](${url})`;
}
}
function copy(text) {
const textArea = document.createElement('textarea');
textArea.value = text;
document.body.appendChild(textArea);
textArea.select();
document.execCommand('Copy');
textArea.remove();
}
function main() {
const title = document.title;
const titleWithoutSpace = title.replaceAll(/\s/g, '');
const url = decodeURI(location.href);
const targetPath = location.pathname
.split('/')
.at(-1)
.replace('.html', '');
const siteName = location.hostname
.replace(/(.+)\.\w+$/, '$1')
.replaceAll('.', '_');
const footnoteLinkByUrlPath = MarkdownSyntax.getFootNote({
identifier: `[^${targetPath}_${siteName}]`,
content: MarkdownSyntax.getLink({ title, url })
});
const footnoteLinkByTitle = MarkdownSyntax.getFootNote({
identifier: `[^${titleWithoutSpace}_${siteName}]`,
content: MarkdownSyntax.getLink({ title, url })
});
// copy(`${footnoteLinkByUrlPath}\n${footnoteLinkByTitle}`);
copy(footnoteLinkByTitle);
}
main();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment