mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
fix: website dictionary base tag (#1038)
* fix: website dictionary base tag * [autofix.ci] apply automated fixes * fix: request header origin --------- Co-authored-by: YiFang Xiao <yifang.xiao@noreply.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
bea926bdd9
commit
ac8e79358c
|
@ -61,10 +61,15 @@ void IframeSchemeHandler::requestStarted( QWebEngineUrlRequestJob * requestJob )
|
|||
QString root = reply->url().scheme() + "://" + reply->url().host();
|
||||
QString base = root + reply->url().path();
|
||||
|
||||
QRegularExpression baseTag( R"(<base\s+.*?>)",
|
||||
QRegularExpression baseTag( R"EOF(<base\s+href=["'](.*?)["'].*?>)EOF",
|
||||
QRegularExpression::CaseInsensitiveOption
|
||||
| QRegularExpression::DotMatchesEverythingOption );
|
||||
|
||||
|
||||
if ( const auto match = baseTag.match( articleString ); match.hasMatch() ) {
|
||||
base = reply->url().resolved( match.captured( 1 ) ).url();
|
||||
}
|
||||
|
||||
QString baseTagHtml = QString( R"(<base href="%1">)" ).arg( base );
|
||||
|
||||
QString depressionFocus =
|
||||
|
@ -72,14 +77,14 @@ void IframeSchemeHandler::requestStarted( QWebEngineUrlRequestJob * requestJob )
|
|||
<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.replace( "window.location", "window.location;_window_location" );
|
||||
|
||||
QRegularExpression headTag( R"(<head\b.*?>)",
|
||||
QRegularExpression::CaseInsensitiveOption
|
||||
| QRegularExpression::DotMatchesEverythingOption );
|
||||
auto match = headTag.match( articleString, 0 );
|
||||
auto match = headTag.match( articleString );
|
||||
if ( match.hasMatch() ) {
|
||||
articleString.insert( match.capturedEnd(), baseTagHtml );
|
||||
articleString.insert( match.capturedEnd(), depressionFocus );
|
||||
|
|
|
@ -9,8 +9,7 @@ WebUrlRequestInterceptor::WebUrlRequestInterceptor( QObject * p ):
|
|||
}
|
||||
void WebUrlRequestInterceptor::interceptRequest( QWebEngineUrlRequestInfo & info )
|
||||
{
|
||||
|
||||
info.setHttpHeader( "origin", "*" );
|
||||
info.setHttpHeader( "origin", info.requestUrl().url().toUtf8() );
|
||||
info.setHttpHeader( "referer", info.requestUrl().url().toUtf8() );
|
||||
if ( GlobalBroadcaster::instance()->getPreference()->disallowContentFromOtherSites
|
||||
&& Utils::isExternalLink( info.requestUrl() ) ) {
|
||||
|
|
Loading…
Reference in a new issue