ChatGPT tried to write me an Instapaper extension

Aaaaannnnndddd… it didn’t go great. :slight_smile:

Please be kind! I’m not a coder, but took advantage of the recent ChatGPT PopClip extension to get it to write me one for Instapaper (which used to be a thing? But I can’t find it? And the old one doesn’t work? And all of my google/Twitter searches about the matter have not led me to the answer as to why …)

So ANYWAY, here’s where our new robot overlord ended up:

// #popclip
// #title=Save to Instapaper
// #icon=IS
// #author=Your Name
// #description=Save a URL to Instapaper
// #language=javascript
// #entitlements=[network]
function saveToInstapaper() {
  const xhr = new XMLHttpRequest();
  const url = encodeURIComponent(popclip.input.text);
  const username = "your_username";
  const password = "your_password";
  const api_url = `https://www.instapaper.com/api/add?url=${url}&username=${username}&password=${password}`;
  xhr.open('GET', api_url, true);
  xhr.send();
}
popclip.htmlContext(`<div class="popclip-extension"><p>Save to Instapaper</p></div>`, {
  onclick: saveToInstapaper
});

I’m pretty sure this is close-ish? But, as before: I’m a nerd, but not a programming nerd! :slight_smile:

I’m also happy to share the whole chatbot thread, if anyone is interested - just post a reply to this topic, and you too can read through the whole painful experience of one man’s quest to tame the future!

Thanks so much for any advice or help to clean this up and get it working!

Haha. Looks like ChatGPT made a valiant attempt, but it got a few things wrong. A little bit more than I can fix quickly now, but I’ll try and take a proper look later.

But yes, there did use to be an Instapaper extension; something went wrong with it ages ago, and it was too hard to fix it at the time with the old clunky PHP code. Now I have the new Javascript system, it should be a lot easier to make a new one.

Some notes I’ll leave here for now:

1 Like

Very much appreciated. Yeah, ChatGPT gave it a valiant go…

Here’s another version from previously in the chat stream…

// #popclip
// #title: Save to Instapaper
// #icon: IS
// #author: Your Name
// #version: 1.0
// #description: Save a URL to Instapaper
// #javascript

function onCopy() {
    const url = encodeURIComponent(popclip.input.text);
    const requestUrl = `https://www.instapaper.com/api/add?url=${url}`;
    const request = new Request(requestUrl, {
        method: 'GET',
        headers: {
            Authorization: "Basic " + btoa("USERNAME:PASSWORD")
        }
    });

    fetch(request)
        .then(response => {
            if (response.ok) {
                popclip.showResult("Saved to Instapaper!");
            } else {
                popclip.showResult("Error saving to Instapaper.");
            }
        })
        .catch(error => {
            popclip.showResult("Error saving to Instapaper: " + error);
        });
}

popclip.registerCopy(onCopy);

I REALLY appreciate your help! PopClip is my number 1 “first install” on a new Mac… :slight_smile: Can’t live without it! (Or, at least, wouldn’t want to!)

Thanks again…