N00b to scripting so apologies in advance...
I am looking use TamperMonkey to create a link from text on a page where it will take the result and search for it against another website.
I'm looking to take the Trade Register Number, turn it into a link that takes that number and runs it against a UK HMRC website. The final link looking something like this: https://find-and-update.company-information.service.gov.uk/company/12345678/officers
Detailed Seller Information:
Business Name:Fake Name Ltd
Business Type:Privately-owned business
Trade Register Number:1234578
VAT Number:GB123456789
I've spend a couple of hours butchering snippets taken from here and everywhere else, and am no closer than when I started.
Any help would be greatly appreciated.
<div >
<div >
<hr aria-hidden="true" >
<h3 id="-component-heading" >
Detailed Seller Information
</h3>
<ul >
<li><span ><span >Business Name:</span>Fake Name Ltd</span>
</li>
<li><span ><span >Business Type:</span>Privately-owned business</span>
</li>
<li><span ><span >Trade Register Number:</span>12354678</span>
</li>
<li><span ><span >VAT Number:</span>GB123456789</span>
</li>
<li><span ><span >Phone number:</span>01234 567890</span>
</li>
CodePudding user response:
I haven't messed around with Greasemonkey or Tampermonkey too much, but as far as a simple script to convert those Trade Register Number values into URLs (following the format you provided), this should do the trick.
document.querySelector(".a-unordered-list.a-nostyle.a-vertical").querySelectorAll("li").forEach(el => {
if(el.textContent.split(":")[0] == "Trade Register Number") {
el.innerHTML = `<span >Trade Register Number:</span><a href="https://find-and-update.company-information.service.gov.uk/company/${el.textContent.split(":")[1]}/officers" target="_blank">${el.textContent.split(":")[1]}</a>`;
}
});
<div >
<div >
<hr aria-hidden="true" >
<h3 id="-component-heading" >
Detailed Seller Information
</h3>
<ul >
<li><span ><span >Business Name:</span>Fake Name Ltd</span>
</li>
<li><span ><span >Business Type:</span>Privately-owned business</span>
</li>
<li><span ><span >Trade Register Number:</span>12354678</span>
</li>
<li><span ><span >VAT Number:</span>GB123456789</span>
</li>
<li><span ><span >Phone number:</span>01234 567890</span>
</li>
</ul>
</div>
</div>
This will only run for 1 set of seller information. If there are multiple listed on the page, I would need to see the HTML for that to properly make it loop through all records on the page.