<aside> 🚨 Want more notes like this? Subscribe to weekly strategy emails: seonotebook.com

</aside>

In order to create a bookmarklet follow these steps:

  1. bookmark any page

  2. rename the bookmark

  3. paste the JavaScript you created with ChatGPT into the URL field of the bookmark.

  4. Save it and click the bookmark on the page you want to create the action with. That’s it!

Here are several prompts and the code ChatGPT generated. Follow the steps above to to create each bookmarklet and please do experiment with creating your own!

—

Prompt: Provide a JavaScript bookmarklet that copies all the links on a page to the clipboard, then separates them by internal links and external links

javascript:(function(){
  var links = document.getElementsByTagName('a');
  var externalLinks = [];
  var internalLinks = [];
  for(var i = 0; i < links.length; i++){
    var link = links[i];
    var href = link.href;
    if(href.startsWith('http') && !href.startsWith(location.origin)){
      externalLinks.push(link.textContent.trim() + ' - ' + href);
    } else {
      internalLinks.push(link.textContent.trim() + ' - ' + href);
    }
  }
  var output = 'External Links:\\n\\n' + externalLinks.join('\\n') + '\\n\\nInternal Links:\\n\\n' + internalLinks.join('\\n');
  var temp = document.createElement('textarea');
  temp.value = output;
  document.body.appendChild(temp);
  temp.select();
  document.execCommand('copy');
  document.body.removeChild(temp);
  alert('All links have been copied to your clipboard.');
})();

Prompt: Provide a JavaScript bookmarklet that will copy all the headings on a page to your clipboard and marks H1 through H6 in the column A, with the headings in column B.

javascript:(function(){
  var headings = document.querySelectorAll('h1, h2, h3, h4, h5, h6');
  var output = '';
  for(var i = 0; i < headings.length; i++){
    var heading = headings[i];
    var level = parseInt(heading.tagName[1]);
    output += 'H' + level + '\\t' + heading.textContent.trim() + '\\n';
  }
  var temp = document.createElement('textarea');
  temp.value = output;
  document.body.appendChild(temp);
  temp.select();
  document.execCommand('copy');
  document.body.removeChild(temp);
  alert('All headings have been copied to your clipboard.');
})();