Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert: defer+gdonready #2009

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions src/dict/mdx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,7 @@ QString & MdxDictionary::filterResource( QString & article )
void MdxDictionary::replaceLinks( QString & id, QString & article )
{
QString articleNewText;
qsizetype linkPos = 0;

int linkPos = 0;
QRegularExpressionMatchIterator it = RX::Mdx::allLinksRe.globalMatch( article );
while ( it.hasNext() ) {
QRegularExpressionMatch allLinksMatch = it.next();
Expand Down Expand Up @@ -954,14 +953,13 @@ void MdxDictionary::replaceLinks( QString & id, QString & article )
articleNewText += linkTxt;
match = RX::Mdx::closeScriptTagRe.match( article, linkPos );
if ( match.hasMatch() ) {
articleNewText += QString( QStringLiteral( "gdOnReady(()=>{%1});</script>" ) )
.arg( article.mid( linkPos, match.capturedStart() - linkPos ) );
articleNewText += article.mid( linkPos, match.capturedEnd() - linkPos );
linkPos = match.capturedEnd();
}
continue;
}
else {
//audio ,script,video ,html5 tags fall here.
//audio ,video ,html5 tags fall here.
match = RX::Mdx::srcRe.match( linkTxt );
if ( match.hasMatch() ) {
QString newText;
Expand All @@ -973,15 +971,9 @@ void MdxDictionary::replaceLinks( QString & id, QString & article )
else {
scheme = "bres://";
}

newText =
match.captured( 1 ) + match.captured( 2 ) + scheme + id + "/" + match.captured( 3 ) + match.captured( 2 );

//add defer to script tag
if ( linkType.compare( "script" ) == 0 ) {
newText = newText + " defer ";
}

newLink = linkTxt.replace( match.capturedStart(), match.capturedLength(), newText );
}
else {
Expand Down
8 changes: 0 additions & 8 deletions src/scripts/gd-builtin.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
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
Loading