Offer ability to skip redirects in strict-blocked page · gorhill/uBlock@20b5418 (original) (raw)
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1193,6 +1193,10 @@ | ||
| 1193 | 1193 | "message": "Proceed", |
| 1194 | 1194 | "description": "Button text to navigate to the blocked page" |
| 1195 | 1195 | }, |
| 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 | + }, | |
| 1196 | 1200 | "cloudPush": { |
| 1197 | 1201 | "message": "Export to cloud storage", |
| 1198 | 1202 | "description": "tooltip" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -28,12 +28,18 @@ body { | ||
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | #rootContainer { |
| 31 | -width: min(100vw, 640px); | |
| 31 | +width: min(100%, 640px); | |
| 32 | 32 | } |
| 33 | 33 | #rootContainer > * { |
| 34 | 34 | margin: 0 0 var(--default-gap-xxlarge) 0; |
| 35 | 35 | } |
| 36 | +:root.mobile #rootContainer > * { | |
| 37 | +margin-bottom: var(--default-gap-xlarge); | |
| 38 | + } | |
| 36 | 39 | |
| 40 | +p { | |
| 41 | +margin: 0.5em 0; | |
| 42 | + } | |
| 37 | 43 | a { |
| 38 | 44 | text-decoration: none; |
| 39 | 45 | } |
| @@ -45,8 +51,12 @@ a { | ||
| 45 | 51 | color: var(--accent-surface-1); |
| 46 | 52 | fill: var(--accent-surface-1); |
| 47 | 53 | font-size: 96px; |
| 54 | +line-height: 1; | |
| 48 | 55 | width: 100%; |
| 49 | 56 | } |
| 57 | +:root.mobile #warningSign { | |
| 58 | +font-size: 64px; | |
| 59 | + } | |
| 50 | 60 | #theURL { |
| 51 | 61 | color: var(--ink-2); |
| 52 | 62 | padding: 0; |
| @@ -120,6 +130,13 @@ body[dir="rtl"] #toggleParse { | ||
| 120 | 130 | padding-inline-start: var(--default-gap-xsmall); |
| 121 | 131 | } |
| 122 | 132 | |
| 133 | +#urlskip a { | |
| 134 | +display: block; | |
| 135 | +overflow-x: hidden; | |
| 136 | +text-overflow: ellipsis; | |
| 137 | +white-space: nowrap; | |
| 138 | + } | |
| 139 | + | |
| 123 | 140 | #actionContainer { |
| 124 | 141 | display: flex; |
| 125 | 142 | justify-content: space-between; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -33,6 +33,9 @@ | ||
| 33 | 33 | </div> |
| 34 | 34 | </div> |
| 35 | 35 | |
| 36 | +<div id="urlskip" hidden> | |
| 37 | +</div> | |
| 38 | + | |
| 36 | 39 | <div class="li"> |
| 37 | 40 | <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> |
| 38 | 41 | </div> |
| @@ -42,13 +45,12 @@ | ||
| 42 | 45 | <button id="bye" data-i18n="docblockedClose" type="button">_<span class="hover"></span></button> |
| 43 | 46 | <button id="proceed" class="preferred" data-i18n="docblockedDisable" type="button"><span class="hover"></span></button> |
| 44 | 47 | </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> <!-- | |
| 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> <!-- | |
| 52 | + --><a class="fa-icon filterListSupport hidden" href="#" target="_blank" rel="noopener noreferrer">home</a> | |
| 53 | +</span> | |
| 52 | 54 | </div> |
| 53 | 55 | |
| 54 | 56 | <script src="lib/hsluv/hsluv-0.1.0.min.js"></script> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -19,10 +19,8 @@ | ||
| 19 | 19 | Home: https://github.com/gorhill/uBlock |
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | -'use strict'; | |
| 23 | - | |
| 24 | -import { i18n, i18n$ } from './i18n.js'; | |
| 25 | 22 | import { dom, qs$ } from './dom.js'; |
| 23 | +import { i18n, i18n$ } from './i18n.js'; | |
| 26 | 24 | |
| 27 | 25 | /******************************************************************************/ |
| 28 | 26 | |
| @@ -47,7 +45,7 @@ let details = {}; | ||
| 47 | 45 | |
| 48 | 46 | let lists; |
| 49 | 47 | for ( const rawFilter in response ) { |
| 50 | -if ( response.hasOwnProperty(rawFilter) ) { | |
| 48 | +if ( Object.prototype.hasOwnProperty.call(response, rawFilter) ) { | |
| 51 | 49 | lists = response[rawFilter]; |
| 52 | 50 | break; |
| 53 | 51 | } |
| @@ -80,6 +78,24 @@ let details = {}; | ||
| 80 | 78 | dom.text('#theURL > p > span:first-of-type', details.url); |
| 81 | 79 | dom.text('#why', details.fs); |
| 82 | 80 | |
| 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 | + | |
| 83 | 99 | /******************************************************************************/ |
| 84 | 100 | |
| 85 | 101 | // https://github.com/gorhill/uBlock/issues/691 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -19,8 +19,6 @@ | ||
| 19 | 19 | Home: https://github.com/gorhill/uBlock |
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | -'use strict'; | |
| 23 | - | |
| 24 | 22 | /******************************************************************************/ |
| 25 | 23 | |
| 26 | 24 | const i18n = |
| @@ -168,14 +166,14 @@ if ( isBackgroundProcess !== true ) { | ||
| 168 | 166 | const re = /\{\{\w+\}\}/g; |
| 169 | 167 | let textout = ''; |
| 170 | 168 | for (;;) { |
| 171 | -let match = re.exec(textin); | |
| 169 | +const match = re.exec(textin); | |
| 172 | 170 | if ( match === null ) { |
| 173 | 171 | textout += textin; |
| 174 | 172 | break; |
| 175 | 173 | } |
| 176 | 174 | textout += textin.slice(0, match.index); |
| 177 | 175 | let prop = match[0].slice(2, -2); |
| 178 | -if ( dict.hasOwnProperty(prop) ) { | |
| 176 | +if ( Object.prototype.hasOwnProperty.call(dict, prop) ) { | |
| 179 | 177 | textout += dict[prop].replace(/</g, '<') |
| 180 | 178 | .replace(/>/g, '>'); |
| 181 | 179 | } else { |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -955,8 +955,8 @@ const PageStore = class { | ||
| 955 | 955 | }); |
| 956 | 956 | } |
| 957 | 957 | |
| 958 | -skipMainDocument(fctxt) { | |
| 959 | -const directives = staticNetFilteringEngine.urlSkip(fctxt); | |
| 958 | +skipMainDocument(fctxt, blocked) { | |
| 959 | +const directives = staticNetFilteringEngine.urlSkip(fctxt, blocked); | |
| 960 | 960 | if ( directives === undefined ) { return; } |
| 961 | 961 | if ( logger.enabled !== true ) { return; } |
| 962 | 962 | fctxt.pushFilters(directives.map(a => a.logData())); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -197,7 +197,7 @@ const onBeforeRootFrameRequest = function(fctxt) { | ||
| 197 | 197 | if ( result !== 1 ) { |
| 198 | 198 | pageStore.redirectNonBlockedRequest(fctxt); |
| 199 | 199 | } else { |
| 200 | -pageStore.skipMainDocument(fctxt); | |
| 200 | +pageStore.skipMainDocument(fctxt, true); | |
| 201 | 201 | } |
| 202 | 202 | } |
| 203 | 203 | |
| @@ -216,16 +216,20 @@ const onBeforeRootFrameRequest = function(fctxt) { | ||
| 216 | 216 | if ( result !== 1 ) { return; } |
| 217 | 217 | |
| 218 | 218 | // No log data means no strict blocking (because we need to report why |
| 219 | -// the blocking occurs. | |
| 219 | +// the blocking occurs | |
| 220 | 220 | if ( logData === undefined ) { return; } |
| 221 | 221 | |
| 222 | 222 | // Blocked |
| 223 | 223 | |
| 224 | +// Find out the URL navigated to should the document not be strict-blocked | |
| 225 | +pageStore.skipMainDocument(fctxt, false); | |
| 226 | + | |
| 224 | 227 | const query = encodeURIComponent(JSON.stringify({ |
| 225 | 228 | url: requestURL, |
| 226 | -hn: requestHostname, | |
| 227 | 229 | dn: fctxt.getDomain() | |
| 228 | -fs: logData.raw | |
| 230 | +fs: logData.raw, | |
| 231 | +hn: requestHostname, | |
| 232 | +to: fctxt.redirectURL | | |
| 229 | 233 | })); |
| 230 | 234 | |
| 231 | 235 | vAPI.tabs.replace( |