Would this extension be impossible?

ok i know that there are some people who for reasons best known to themselves :slight_smile: love to solve problems like this which are too hard for me because i am a bear of little brain and i don’t actually think it is possible to do this in popclip but like the white queen i sometimes think of as many as six impossible things before breakfast. so what i would like is an extension which …

ok so i write in markdown and i like footnotes. an inline footnote is easy, you just type a ^ and a [ and then you type the text you want in the footnote and a ] when you’re done.

but endnotes are better because you then no longer have to stare at the footnoted text. so i would like to :

  1. select the text obvs
  2. have popclip cut it onto the clipboard for me
  3. insert [^ref] with ‘ref’ being a reference, say a number, in the same spot
  4. go to the end of the file and put [^ref] and a colon, followed by the text on the clipboard, so it would look like [^ref]:text from the clipboard

to do this once would possible perhaps but if i have more than one endnote in a document the ‘ref’ has to be different from the other refs in the document otherwise the endnotes don’t match.

but how could popclip know what the other refs are? impossible i reckon but what do you think?

if someone knows the answer i would love to hear it. i offer a prize in the form of an idea for a (admittedly pretty lame and infantile) april fool prank to play on popclip users :slight_smile:

It would all be fairly trivial apart from the going to the end of the file bit; I expect the best it could do would be leave the endnote text on the cliboard for you to manually paste at the end of the file.

Regarding the reference, would an a short randomly generate reference do? Like qwS2T or something. With 4 or 5 characters this would be extremely unlikely to clash.

e.g.

[^qwS2T]:text from the clipboard
[^T5x8y]:another text from the clipboard
1 Like

that sounds great @nick

This ought to do it:

// #popclip
// name: Endnote
// icon: E
// lang: js

function generateRandomBase62(n) {
  const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  let result = '';
  for (let i = 0; i < n; i++) {
    result += chars.charAt(Math.floor(Math.random() * chars.length));
  }
  return result;
}

const ref=`[^${generateRandomBase62(5)}]`;
popclip.pasteText(ref)
await sleep(250);
popclip.copyText(ref + ":" + popclip.input.text);

CleanShot 2024-03-01 at 09.41.08

ah thank you so much @nick. weird. unfortunately when i try this, instead of only leaving the reference, it leaves the content of the endnote in place, together with the reference and the colon, instead of only the reference.

is there a gremlin in the code?

i wonder if it needs a short delay to allow the paste to complete for some apps. i’ve added a line, try it again…

that fixed it!
thanks so much @nick.
the admittedly pretty lame and infantile idea for and april fool prank would be to change the name of popclip to poopclip for the day in a few places for the day. (i know, i know.) :slight_smile:

I appreciate the follow-through :slight_smile: