mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-12-18 11:34:05 +00:00
Merge pull request #2009 from xiaoyifang/fix/defer+gdonready
Some checks failed
SonarCloud / Build and analyze (push) Has been cancelled
Some checks failed
SonarCloud / Build and analyze (push) Has been cancelled
revert: defer+gdonready
This commit is contained in:
commit
853700afab
|
@ -877,8 +877,7 @@ QString & MdxDictionary::filterResource( QString & article )
|
||||||
void MdxDictionary::replaceLinks( QString & id, QString & article )
|
void MdxDictionary::replaceLinks( QString & id, QString & article )
|
||||||
{
|
{
|
||||||
QString articleNewText;
|
QString articleNewText;
|
||||||
qsizetype linkPos = 0;
|
int linkPos = 0;
|
||||||
|
|
||||||
QRegularExpressionMatchIterator it = RX::Mdx::allLinksRe.globalMatch( article );
|
QRegularExpressionMatchIterator it = RX::Mdx::allLinksRe.globalMatch( article );
|
||||||
while ( it.hasNext() ) {
|
while ( it.hasNext() ) {
|
||||||
QRegularExpressionMatch allLinksMatch = it.next();
|
QRegularExpressionMatch allLinksMatch = it.next();
|
||||||
|
@ -954,14 +953,13 @@ void MdxDictionary::replaceLinks( QString & id, QString & article )
|
||||||
articleNewText += linkTxt;
|
articleNewText += linkTxt;
|
||||||
match = RX::Mdx::closeScriptTagRe.match( article, linkPos );
|
match = RX::Mdx::closeScriptTagRe.match( article, linkPos );
|
||||||
if ( match.hasMatch() ) {
|
if ( match.hasMatch() ) {
|
||||||
articleNewText += QString( QStringLiteral( "gdOnReady(()=>{%1});</script>" ) )
|
articleNewText += article.mid( linkPos, match.capturedEnd() - linkPos );
|
||||||
.arg( article.mid( linkPos, match.capturedStart() - linkPos ) );
|
|
||||||
linkPos = match.capturedEnd();
|
linkPos = match.capturedEnd();
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//audio ,script,video ,html5 tags fall here.
|
//audio ,video ,html5 tags fall here.
|
||||||
match = RX::Mdx::srcRe.match( linkTxt );
|
match = RX::Mdx::srcRe.match( linkTxt );
|
||||||
if ( match.hasMatch() ) {
|
if ( match.hasMatch() ) {
|
||||||
QString newText;
|
QString newText;
|
||||||
|
@ -973,15 +971,9 @@ void MdxDictionary::replaceLinks( QString & id, QString & article )
|
||||||
else {
|
else {
|
||||||
scheme = "bres://";
|
scheme = "bres://";
|
||||||
}
|
}
|
||||||
|
|
||||||
newText =
|
newText =
|
||||||
match.captured( 1 ) + match.captured( 2 ) + scheme + id + "/" + match.captured( 3 ) + match.captured( 2 );
|
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 );
|
newLink = linkTxt.replace( match.capturedStart(), match.capturedLength(), newText );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -1,11 +1,3 @@
|
||||||
function gdOnReady(func) {
|
|
||||||
if (document.readyState !== "loading") {
|
|
||||||
func();
|
|
||||||
} else {
|
|
||||||
document.addEventListener("DOMContentLoaded", func);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function gdMakeArticleActive(newId, noEvent) {
|
function gdMakeArticleActive(newId, noEvent) {
|
||||||
const gdCurrentArticle =
|
const gdCurrentArticle =
|
||||||
document.querySelector(".gdactivearticle").attributes.id;
|
document.querySelector(".gdactivearticle").attributes.id;
|
||||||
|
|
Loading…
Reference in a new issue