mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 00:14:06 +00:00
opt: website dictionary ,add whitelist of host url.
This commit is contained in:
parent
34796ce8ed
commit
6ed7fda315
|
@ -5,6 +5,12 @@
|
||||||
Q_GLOBAL_STATIC( GlobalBroadcaster, bdcaster )
|
Q_GLOBAL_STATIC( GlobalBroadcaster, bdcaster )
|
||||||
GlobalBroadcaster::GlobalBroadcaster( QObject * parent ) : QObject( parent )
|
GlobalBroadcaster::GlobalBroadcaster( QObject * parent ) : QObject( parent )
|
||||||
{
|
{
|
||||||
|
QStringList whiteUrlHosts = { "ajax.googleapis.com" };
|
||||||
|
|
||||||
|
for( auto host : whiteUrlHosts )
|
||||||
|
{
|
||||||
|
addWhitelist( host );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalBroadcaster * GlobalBroadcaster::instance()
|
GlobalBroadcaster * GlobalBroadcaster::instance()
|
||||||
|
|
|
@ -46,16 +46,22 @@ void IframeSchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob)
|
||||||
while( !base.isEmpty() && !base.endsWith( "/" ) )
|
while( !base.isEmpty() && !base.endsWith( "/" ) )
|
||||||
base.chop( 1 );
|
base.chop( 1 );
|
||||||
|
|
||||||
QRegularExpression tags( "<base\\s+.*?>",
|
QRegularExpression baseTag( "<base\\s+.*?>",
|
||||||
QRegularExpression::CaseInsensitiveOption | QRegularExpression::DotMatchesEverythingOption );
|
QRegularExpression::CaseInsensitiveOption | QRegularExpression::DotMatchesEverythingOption );
|
||||||
|
|
||||||
QString baseTagHtml = "<base href=\"" + base + "\">";
|
QString baseTagHtml = "<base href=\"" + base + "\">";
|
||||||
|
|
||||||
// remove existed base tag
|
// remove existed base tag
|
||||||
articleString.remove( tags ) ;
|
articleString.remove( baseTag ) ;
|
||||||
qsizetype pos = articleString.indexOf( "<head>" );
|
|
||||||
if( pos > -1 )
|
QRegularExpression headTag( "<head\\s+.*?>",
|
||||||
articleString.insert( pos + 6, baseTagHtml );
|
QRegularExpression::CaseInsensitiveOption
|
||||||
|
| QRegularExpression::DotMatchesEverythingOption );
|
||||||
|
auto match = headTag.match( articleString, 0 );
|
||||||
|
if( match.hasMatch() )
|
||||||
|
{
|
||||||
|
articleString.insert( match.capturedEnd(), baseTagHtml );
|
||||||
|
}
|
||||||
|
|
||||||
buffer->setData(codec->fromUnicode(articleString));
|
buffer->setData(codec->fromUnicode(articleString));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue