mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +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 )
|
||||
GlobalBroadcaster::GlobalBroadcaster( QObject * parent ) : QObject( parent )
|
||||
{
|
||||
QStringList whiteUrlHosts = { "ajax.googleapis.com" };
|
||||
|
||||
for( auto host : whiteUrlHosts )
|
||||
{
|
||||
addWhitelist( host );
|
||||
}
|
||||
}
|
||||
|
||||
GlobalBroadcaster * GlobalBroadcaster::instance()
|
||||
|
|
|
@ -46,16 +46,22 @@ void IframeSchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob)
|
|||
while( !base.isEmpty() && !base.endsWith( "/" ) )
|
||||
base.chop( 1 );
|
||||
|
||||
QRegularExpression tags( "<base\\s+.*?>",
|
||||
QRegularExpression baseTag( "<base\\s+.*?>",
|
||||
QRegularExpression::CaseInsensitiveOption | QRegularExpression::DotMatchesEverythingOption );
|
||||
|
||||
QString baseTagHtml = "<base href=\"" + base + "\">";
|
||||
|
||||
// remove existed base tag
|
||||
articleString.remove( tags ) ;
|
||||
qsizetype pos = articleString.indexOf( "<head>" );
|
||||
if( pos > -1 )
|
||||
articleString.insert( pos + 6, baseTagHtml );
|
||||
articleString.remove( baseTag ) ;
|
||||
|
||||
QRegularExpression headTag( "<head\\s+.*?>",
|
||||
QRegularExpression::CaseInsensitiveOption
|
||||
| QRegularExpression::DotMatchesEverythingOption );
|
||||
auto match = headTag.match( articleString, 0 );
|
||||
if( match.hasMatch() )
|
||||
{
|
||||
articleString.insert( match.capturedEnd(), baseTagHtml );
|
||||
}
|
||||
|
||||
buffer->setData(codec->fromUnicode(articleString));
|
||||
|
||||
|
|
Loading…
Reference in a new issue