Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Handle non-script version of DDG when blocked at filtering level #3293

Merged
merged 1 commit into from
Aug 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,16 @@ function registerForBeforeRequest (session) {
return
}
}
cb({})
// Redirect to non-script version of DDG when it's blocked
let url = details.url
if (details.resourceType === 'mainFrame' &&
url.startsWith('https://duckduckgo.com/?q') &&
module.exports.isResourceEnabled('noScript', url)) {
url = url.replace('?q=', 'html?q=')
cb({redirectURL: url})
} else {
cb({})
}
})
}

Expand Down
1 change: 0 additions & 1 deletion js/components/navigationBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ class NavigationBar extends ImmutableComponent {
endLoadTime={this.props.endLoadTime}
titleMode={this.titleMode}
urlbar={this.props.navbar.get('urlbar')}
enableNoScript={this.props.enableNoScript}
/>
{
isSourceAboutUrl(this.props.location)
Expand Down
12 changes: 2 additions & 10 deletions js/components/urlBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,13 @@ class UrlBar extends ImmutableComponent {
// load the selected suggestion
this.urlBarSuggestions.clickSelected(e)
} else {
const defaultEngine = getSetting(settings.DEFAULT_SEARCH_ENGINE)
let searchUrl = this.props.searchDetail.get('searchURL').replace('{searchTerms}', encodeURIComponent(location))
if (this.activateSearchEngine && this.searchSelectEntry !== null &&
this.searchSelectEntry.name !== defaultEngine && !isLocationUrl) {
if (this.activateSearchEngine && this.searchSelectEntry !== null && !isLocationUrl) {
const replaceRE = new RegExp('^' + this.searchSelectEntry.shortcut + ' ', 'g')
location = location.replace(replaceRE, '')
searchUrl = this.searchSelectEntry.search.replace('{searchTerms}', encodeURIComponent(location))
}

if ((defaultEngine === 'DuckDuckGo' ||
(this.searchSelectEntry && this.searchSelectEntry.name === 'DuckDuckGo')) &&
this.props.enableNoScript) {
searchUrl = searchUrl.replace('?q=', 'html?q=')
}
location = isLocationUrl ? location : searchUrl
// do search.
if (e.altKey) {
Expand Down Expand Up @@ -460,8 +453,7 @@ class UrlBar extends ImmutableComponent {
urlLocation={this.props.urlbar.get('location')}
urlPreview={this.props.urlbar.get('urlPreview')}
searchSelectEntry={this.searchSelectEntry}
previewActiveIndex={this.props.previewActiveIndex || 0}
enableNoScript={this.props.enableNoScript} />
previewActiveIndex={this.props.previewActiveIndex || 0} />
: null
}
</form>
Expand Down
4 changes: 0 additions & 4 deletions js/components/urlBarSuggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,6 @@ class UrlBarSuggestions extends ImmutableComponent {
clickHandler: navigateClickHandler((searchTerms) => {
let searchURL = this.props.searchSelectEntry
? this.props.searchSelectEntry.search : this.props.searchDetail.get('searchURL')
if (getSetting(settings.DEFAULT_SEARCH_ENGINE) === 'DuckDuckGo' &&
this.props.enableNoScript) {
searchURL = searchURL.replace('?q=', 'html?q=')
}
return searchURL.replace('{searchTerms}', encodeURIComponent(searchTerms))
})
}))
Expand Down