Skip to content

Commit

Permalink
fix: <script> without src is not delayed like <script src="..." defer>
Browse files Browse the repository at this point in the history
  • Loading branch information
shenlebantongying authored Nov 27, 2024
1 parent ad19263 commit 00dbc74
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/dict/mdx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,8 @@ QString & MdxDictionary::filterResource( QString & article )
void MdxDictionary::replaceLinks( QString & id, QString & article )
{
QString articleNewText;
int linkPos = 0;
qsizetype linkPos = 0;

QRegularExpressionMatchIterator it = RX::Mdx::allLinksRe.globalMatch( article );
while ( it.hasNext() ) {
QRegularExpressionMatch allLinksMatch = it.next();
Expand Down Expand Up @@ -953,7 +954,8 @@ void MdxDictionary::replaceLinks( QString & id, QString & article )
articleNewText += linkTxt;
match = RX::Mdx::closeScriptTagRe.match( article, linkPos );
if ( match.hasMatch() ) {
articleNewText += article.mid( linkPos, match.capturedEnd() - linkPos );
articleNewText += QString( QStringLiteral( "gdOnReady(()=>{%1});</script>" ) )
.arg( article.mid( linkPos, match.capturedStart() - linkPos ) );
linkPos = match.capturedEnd();
}
continue;
Expand Down
8 changes: 8 additions & 0 deletions src/scripts/gd-builtin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
function gdOnReady(func) {
if (document.readyState !== "loading") {
func();
} else {
document.addEventListener("DOMContentLoaded", func);
}
}

function gdMakeArticleActive(newId, noEvent) {
const gdCurrentArticle =
document.querySelector(".gdactivearticle").attributes.id;
Expand Down

0 comments on commit 00dbc74

Please sign in to comment.