mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
fix: code smells
This commit is contained in:
parent
568efee4c7
commit
eb1963b170
|
@ -15,10 +15,8 @@ QRegularExpression Ftx::setsRegExp( R"(\[[^\]]+\])", QRegularExpression::CaseIns
|
|||
QRegularExpression Ftx::regexRegExp( R"(\\[afnrtvdDwWsSbB]|\\x([0-9A-Fa-f]{4})|\\0([0-7]{3}))",
|
||||
QRegularExpression::CaseInsensitiveOption );
|
||||
|
||||
QRegularExpression Ftx::handleRoundBracket( R"([^\w\(\)\p{M}]+)" ,
|
||||
QRegularExpression::UseUnicodePropertiesOption );
|
||||
QRegularExpression Ftx::noRoundBracket( "[^\\w\\p{M}]+",
|
||||
QRegularExpression::UseUnicodePropertiesOption );
|
||||
QRegularExpression Ftx::handleRoundBracket( R"([^\w\(\)\p{M}]+)", QRegularExpression::UseUnicodePropertiesOption );
|
||||
QRegularExpression Ftx::noRoundBracket( R"([^\w\p{M}]+)", QRegularExpression::UseUnicodePropertiesOption );
|
||||
|
||||
QRegularExpression Ftx::tokenBoundary( R"([\*\?\+]|\bAnd\b|\bOR\b)", QRegularExpression::CaseInsensitiveOption );
|
||||
QRegularExpression Ftx::token(R"((".*?")|([\w\W\+\-]+))",QRegularExpression::DotMatchesEverythingOption|QRegularExpression::CaseInsensitiveOption);
|
||||
|
@ -47,7 +45,7 @@ QRegularExpression Mdx::stylesRe2(
|
|||
QRegularExpression::CaseInsensitiveOption );
|
||||
QRegularExpression Mdx::inlineScriptRe( R"(<\s*script(?:(?=\s)(?:(?![\s"']src\s*=)[^>])+|\s*)>)",
|
||||
QRegularExpression::CaseInsensitiveOption );
|
||||
QRegularExpression Mdx::closeScriptTagRe( "<\\s*/script\\s*>", QRegularExpression::CaseInsensitiveOption );
|
||||
QRegularExpression Mdx::closeScriptTagRe( R"(<\s*/script\s*>)", QRegularExpression::CaseInsensitiveOption );
|
||||
QRegularExpression Mdx::srcRe(
|
||||
R"(([\s"'](?:src|srcset)\s*=)\s*(["'])(?!\s*\b(?:(?:bres|https?|ftp)://|(?:data|javascript):))(?:file://)?[\x00-\x1f\x7f]*\.*/?([^">]+)\2)",
|
||||
QRegularExpression::CaseInsensitiveOption );
|
||||
|
|
|
@ -30,7 +30,7 @@ void IframeSchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob)
|
|||
codecName = ct.mid( index + 8 );
|
||||
}
|
||||
}
|
||||
QBuffer * buffer = new QBuffer( requestJob );
|
||||
auto buffer = new QBuffer( requestJob );
|
||||
|
||||
QByteArray replyData = reply->readAll();
|
||||
QString articleString;
|
||||
|
@ -61,24 +61,25 @@ void IframeSchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob)
|
|||
QString root = reply->url().scheme() + "://" + reply->url().host();
|
||||
QString base = root + reply->url().path();
|
||||
|
||||
QRegularExpression baseTag( "<base\\s+.*?>",
|
||||
QRegularExpression::CaseInsensitiveOption | QRegularExpression::DotMatchesEverythingOption );
|
||||
|
||||
QString baseTagHtml = "<base href=\"" + base + "\">";
|
||||
QRegularExpression baseTag( R"(<base\s+.*?>)",
|
||||
QRegularExpression::CaseInsensitiveOption
|
||||
| QRegularExpression::DotMatchesEverythingOption );
|
||||
|
||||
QString baseTagHtml = QString( R"(<base href="%1">)" ).arg( base );
|
||||
|
||||
QString depressionFocus =
|
||||
R"(<script type="application/javascript"> HTMLElement.prototype.focus=function(){console.log("focus() has been disabled.");}</script>
|
||||
<script type="text/javascript" src="qrc:///scripts/iframeResizer.contentWindow.min.js">
|
||||
</script><script type="text/javascript" src="qrc:///scripts/iframe-defer.js"></script>)";
|
||||
|
||||
QString depressionFocus ="<script type=\"application/javascript\"> HTMLElement.prototype.focus=function(){console.log(\"focus() has been disabled.\");}</script>"
|
||||
"<script type=\"text/javascript\" src=\"qrc:///scripts/iframeResizer.contentWindow.min.js\"></script>"
|
||||
"<script type=\"text/javascript\" src=\"qrc:///scripts/iframe-defer.js\"></script>";
|
||||
|
||||
// remove existed base tag
|
||||
articleString.remove( baseTag ) ;
|
||||
articleString.remove( baseTag );
|
||||
|
||||
QRegularExpression headTag( "<head\\b.*?>",
|
||||
QRegularExpression headTag( R"(<head\b.*?>)",
|
||||
QRegularExpression::CaseInsensitiveOption
|
||||
| QRegularExpression::DotMatchesEverythingOption );
|
||||
auto match = headTag.match( articleString, 0 );
|
||||
if( match.hasMatch() )
|
||||
{
|
||||
if ( match.hasMatch() ) {
|
||||
articleString.insert( match.capturedEnd(), baseTagHtml );
|
||||
articleString.insert( match.capturedEnd(), depressionFocus );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue