I managed to achieve it reading the extend.php from fancybox extension which I've seen on extiverse.com and it's GitHub repository. Here is the result, which you can use to make an extension or put in your extend.php in your Flarum's installation root directory (this way it both runs on opening the post directly or via the posts listing):
<?php
use Flarum\Extend;
use Flarum\Frontend\Document;
return [
(new Extend\Frontend('forum'))
->content(function (Document $document) {
$document->head[] = '<link rel="preload" as="style" href="https://cdn.domain/iframely/style.css" onload="this.onload=null;this.rel=\'stylesheet\'">';
$document->foot[] = <<<HTML
<script>
flarum.core.compat.extend.extend(flarum.core.compat['components/CommentPost'].prototype, 'oncreate', function (output, vnode) {
const self = this;
this.$('div.Post-body a').each(function () {
href = $(this).attr('href');
$(this).closest('.Post-body').css( "background", "yellow" ).append("<span>"+href+"</span>");
try {
$().ready(function(){
// execute code here
})
} catch (e) {
console.error(e.name);
console.error(e.message);
}
});
</script>
HTML;
})
];