How to get the text of H1 tag and copy it to another part of the code with Javascript?

I am in the process of adding “See more” sections to the bottom of some of my web pages. My plan to is to have something like this:

<h1>Unique title</h1>

<h2>See more</h2>
<ul>
<li><a href="/people/YYYY/category1/">More1</a></li>
<li><a href="/people/YYYY/category2/">More2</a></li>
<li><a href="/people/YYYY/category3/">More3</a></li>
<li><a href="/people/YYYY/category4/">More4</a></li>
<ul>

I have many hundreds of these to do so what I’m looking to do is use Javascript to copy the text in the H1 tag and replace ‘YYYY’ in the url with that text within the same page.

I have very limited knowledge of Javascript, I tend to only use WS3 snippets, but I’m struggling to find something for what I need.

Please note: there is more code between the H1 and H2 tags, I just haven’t included it. Also, the urls in the ul are examples only.