Skip to content

Commit 20b5418

Browse files
committed
Offer ability to skip redirects in strict-blocked page
Related discussion: uBlockOrigin/uBlock-issues#3206 (comment) If a strict-blocked page matches a `urlskip=` filter, the page will show the user the destination URL as a result of applying the `urlskip` filter should they choose to proceed with the navigation.
1 parent 6aa9391 commit 20b5418

File tree

7 files changed

+63
-22
lines changed

7 files changed

+63
-22
lines changed

src/_locales/en/messages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,10 @@
11931193
"message": "Proceed",
11941194
"description": "Button text to navigate to the blocked page"
11951195
},
1196+
"docblockedRedirectPrompt": {
1197+
"message": "The blocked page wants to redirect to another site. If you choose to proceed, you will navigate directly to: {{url}}",
1198+
"description": "Text warning about an incoming redirect"
1199+
},
11961200
"cloudPush": {
11971201
"message": "Export to cloud storage",
11981202
"description": "tooltip"

src/css/document-blocked.css

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,18 @@ body {
2828
}
2929

3030
#rootContainer {
31-
width: min(100vw, 640px);
31+
width: min(100%, 640px);
3232
}
3333
#rootContainer > * {
3434
margin: 0 0 var(--default-gap-xxlarge) 0;
3535
}
36+
:root.mobile #rootContainer > * {
37+
margin-bottom: var(--default-gap-xlarge);
38+
}
3639

40+
p {
41+
margin: 0.5em 0;
42+
}
3743
a {
3844
text-decoration: none;
3945
}
@@ -45,8 +51,12 @@ a {
4551
color: var(--accent-surface-1);
4652
fill: var(--accent-surface-1);
4753
font-size: 96px;
54+
line-height: 1;
4855
width: 100%;
4956
}
57+
:root.mobile #warningSign {
58+
font-size: 64px;
59+
}
5060
#theURL {
5161
color: var(--ink-2);
5262
padding: 0;
@@ -120,6 +130,13 @@ body[dir="rtl"] #toggleParse {
120130
padding-inline-start: var(--default-gap-xsmall);
121131
}
122132

133+
#urlskip a {
134+
display: block;
135+
overflow-x: hidden;
136+
text-overflow: ellipsis;
137+
white-space: nowrap;
138+
}
139+
123140
#actionContainer {
124141
display: flex;
125142
justify-content: space-between;

src/document-blocked.html

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
</div>
3434
</div>
3535

36+
<div id="urlskip" hidden>
37+
</div>
38+
3639
<div class="li">
3740
<label><span class="input checkbox"><input type="checkbox" id="disableWarning"><svg viewBox="0 0 24 24"><path d="M1.73,12.91 8.1,19.28 22.79,4.59"/></svg></span><span data-i18n="docblockedDontWarn">_</span></label>
3841
</div>
@@ -42,13 +45,12 @@
4245
<button id="bye" data-i18n="docblockedClose" type="button">_<span class="hover"></span></button>
4346
<button id="proceed" class="preferred" data-i18n="docblockedDisable" type="button"><span class="hover"></span></button>
4447
</div>
45-
46-
<div id="templates" style="display: none;">
47-
<li class="filterList">
48-
<a class="filterListSource" href="asset-viewer.html?url=" target="_blank"></a>&nbsp;<!--
49-
--><a class="fa-icon filterListSupport hidden" href="#" target="_blank" rel="noopener noreferrer">home</a>
50-
</span>
51-
</div>
48+
</div>
49+
<div id="templates" style="display: none;">
50+
<li class="filterList">
51+
<a class="filterListSource" href="asset-viewer.html?url=" target="_blank"></a>&nbsp;<!--
52+
--><a class="fa-icon filterListSupport hidden" href="#" target="_blank" rel="noopener noreferrer">home</a>
53+
</span>
5254
</div>
5355

5456
<script src="lib/hsluv/hsluv-0.1.0.min.js"></script>

src/js/document-blocked.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919
Home: https://github.com/gorhill/uBlock
2020
*/
2121

22-
'use strict';
23-
24-
import { i18n, i18n$ } from './i18n.js';
2522
import { dom, qs$ } from './dom.js';
23+
import { i18n, i18n$ } from './i18n.js';
2624

2725
/******************************************************************************/
2826

@@ -47,7 +45,7 @@ let details = {};
4745

4846
let lists;
4947
for ( const rawFilter in response ) {
50-
if ( response.hasOwnProperty(rawFilter) ) {
48+
if ( Object.prototype.hasOwnProperty.call(response, rawFilter) ) {
5149
lists = response[rawFilter];
5250
break;
5351
}
@@ -80,6 +78,24 @@ let details = {};
8078
dom.text('#theURL > p > span:first-of-type', details.url);
8179
dom.text('#why', details.fs);
8280

81+
if ( typeof details.to === 'string' && details.to.length !== 0 ) {
82+
const fragment = new DocumentFragment();
83+
const text = i18n$('docblockedRedirectPrompt');
84+
const linkPlaceholder = '{{url}}';
85+
let pos = text.indexOf(linkPlaceholder);
86+
if ( pos !== -1 ) {
87+
const link = document.createElement('a');
88+
link.href = link.textContent = details.to;
89+
fragment.append(
90+
text.slice(0, pos),
91+
link,
92+
text.slice(pos + linkPlaceholder.length)
93+
);
94+
qs$('#urlskip').append(fragment);
95+
dom.attr('#urlskip', 'hidden', null);
96+
}
97+
}
98+
8399
/******************************************************************************/
84100

85101
// https://github.com/gorhill/uBlock/issues/691

src/js/i18n.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
Home: https://github.com/gorhill/uBlock
2020
*/
2121

22-
'use strict';
23-
2422
/******************************************************************************/
2523

2624
const i18n =
@@ -168,14 +166,14 @@ if ( isBackgroundProcess !== true ) {
168166
const re = /\{\{\w+\}\}/g;
169167
let textout = '';
170168
for (;;) {
171-
let match = re.exec(textin);
169+
const match = re.exec(textin);
172170
if ( match === null ) {
173171
textout += textin;
174172
break;
175173
}
176174
textout += textin.slice(0, match.index);
177175
let prop = match[0].slice(2, -2);
178-
if ( dict.hasOwnProperty(prop) ) {
176+
if ( Object.prototype.hasOwnProperty.call(dict, prop) ) {
179177
textout += dict[prop].replace(/</g, '&lt;')
180178
.replace(/>/g, '&gt;');
181179
} else {

src/js/pagestore.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -955,8 +955,8 @@ const PageStore = class {
955955
});
956956
}
957957

958-
skipMainDocument(fctxt) {
959-
const directives = staticNetFilteringEngine.urlSkip(fctxt);
958+
skipMainDocument(fctxt, blocked) {
959+
const directives = staticNetFilteringEngine.urlSkip(fctxt, blocked);
960960
if ( directives === undefined ) { return; }
961961
if ( logger.enabled !== true ) { return; }
962962
fctxt.pushFilters(directives.map(a => a.logData()));

src/js/traffic.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ const onBeforeRootFrameRequest = function(fctxt) {
197197
if ( result !== 1 ) {
198198
pageStore.redirectNonBlockedRequest(fctxt);
199199
} else {
200-
pageStore.skipMainDocument(fctxt);
200+
pageStore.skipMainDocument(fctxt, true);
201201
}
202202
}
203203

@@ -216,16 +216,20 @@ const onBeforeRootFrameRequest = function(fctxt) {
216216
if ( result !== 1 ) { return; }
217217

218218
// No log data means no strict blocking (because we need to report why
219-
// the blocking occurs.
219+
// the blocking occurs
220220
if ( logData === undefined ) { return; }
221221

222222
// Blocked
223223

224+
// Find out the URL navigated to should the document not be strict-blocked
225+
pageStore.skipMainDocument(fctxt, false);
226+
224227
const query = encodeURIComponent(JSON.stringify({
225228
url: requestURL,
226-
hn: requestHostname,
227229
dn: fctxt.getDomain() || requestHostname,
228-
fs: logData.raw
230+
fs: logData.raw,
231+
hn: requestHostname,
232+
to: fctxt.redirectURL || '',
229233
}));
230234

231235
vAPI.tabs.replace(

0 commit comments

Comments
 (0)