Skip to content
This repository was archived by the owner on Jul 21, 2021. It is now read-only.

Commit 3f8168c

Browse files
committed
fix #502
1 parent 773fe2d commit 3f8168c

File tree

2 files changed

+174
-8
lines changed

2 files changed

+174
-8
lines changed

src/js/main-blocked.js

+107-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*******************************************************************************
22
3-
µMatrix - a browser extension to block requests.
4-
Copyright (C) 2015 Raymond Hill
3+
uMatrix - a browser extension to block requests.
4+
Copyright (C) 2015-2017 Raymond Hill
55
66
This program is free software: you can redistribute it and/or modify
77
it under the terms of the GNU General Public License as published by
@@ -33,16 +33,117 @@ var details = {};
3333

3434
(function() {
3535
var matches = /details=([^&]+)/.exec(window.location.search);
36-
if ( matches === null ) {
37-
return;
36+
if ( matches === null ) { return; }
37+
try {
38+
details = JSON.parse(atob(matches[1]));
39+
} catch(ex) {
3840
}
39-
details = JSON.parse(atob(matches[1]));
4041
})();
4142

4243
/******************************************************************************/
4344

4445
uDom('.what').text(details.url);
45-
uDom('#why').text(details.why.slice(3));
46+
// uDom('#why').text(details.why.slice(3));
47+
48+
/******************************************************************************/
49+
50+
// https://github.com/gorhill/uMatrix/issues/502
51+
// Code below originally imported from:
52+
// https://github.com/gorhill/uBlock/blob/master/src/js/document-blocked.js
53+
54+
(function() {
55+
if ( typeof URL !== 'function' ) { return; }
56+
57+
var reURL = /^https?:\/\//;
58+
59+
var liFromParam = function(name, value) {
60+
if ( value === '' ) {
61+
value = name;
62+
name = '';
63+
}
64+
var li = document.createElement('li');
65+
var span = document.createElement('span');
66+
span.textContent = name;
67+
li.appendChild(span);
68+
if ( name !== '' && value !== '' ) {
69+
li.appendChild(document.createTextNode(' = '));
70+
}
71+
span = document.createElement('span');
72+
if ( reURL.test(value) ) {
73+
var a = document.createElement('a');
74+
a.href = a.textContent = value;
75+
span.appendChild(a);
76+
} else {
77+
span.textContent = value;
78+
}
79+
li.appendChild(span);
80+
return li;
81+
};
82+
83+
var safeDecodeURIComponent = function(s) {
84+
try {
85+
s = decodeURIComponent(s);
86+
} catch (ex) {
87+
}
88+
return s;
89+
};
90+
91+
var renderParams = function(parentNode, rawURL) {
92+
var a = document.createElement('a');
93+
a.href = rawURL;
94+
if ( a.search.length === 0 ) { return false; }
95+
96+
var pos = rawURL.indexOf('?');
97+
var li = liFromParam(
98+
vAPI.i18n('docblockedNoParamsPrompt'),
99+
rawURL.slice(0, pos)
100+
);
101+
parentNode.appendChild(li);
102+
103+
var params = a.search.slice(1).split('&');
104+
var param, name, value, ul;
105+
for ( var i = 0; i < params.length; i++ ) {
106+
param = params[i];
107+
pos = param.indexOf('=');
108+
if ( pos === -1 ) {
109+
pos = param.length;
110+
}
111+
name = safeDecodeURIComponent(param.slice(0, pos));
112+
value = safeDecodeURIComponent(param.slice(pos + 1));
113+
li = liFromParam(name, value);
114+
if ( reURL.test(value) ) {
115+
ul = document.createElement('ul');
116+
renderParams(ul, value);
117+
li.appendChild(ul);
118+
}
119+
parentNode.appendChild(li);
120+
}
121+
return true;
122+
};
123+
124+
if ( renderParams(uDom.nodeFromId('parsed'), details.url) === false ) {
125+
return;
126+
}
127+
128+
var toggler = document.createElement('span');
129+
toggler.className = 'fa';
130+
uDom('#theURL > p').append(toggler);
131+
132+
uDom(toggler).on('click', function() {
133+
var collapsed = uDom.nodeFromId('theURL').classList.toggle('collapsed');
134+
vAPI.localStorage.setItem(
135+
'document-blocked-collapse-url',
136+
collapsed.toString()
137+
);
138+
});
139+
140+
uDom.nodeFromId('theURL').classList.toggle(
141+
'collapsed',
142+
vAPI.localStorage.getItem('document-blocked-collapse-url') === 'true'
143+
);
144+
})();
145+
146+
/******************************************************************************/
46147

47148
if ( window.history.length > 1 ) {
48149
uDom('#back').on('click', function() { window.history.back(); });

src/main-blocked.html

+67-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
display: inline-block;
2525
font-family: monospace;
2626
font-size: large;
27-
line-height: 1;
27+
line-height: 1.2;
2828
padding: 2px 4px;
2929
word-break: break-all;
3030
}
@@ -34,6 +34,68 @@
3434
padding: 0.25em 0.5em;
3535
font-size: inherit;
3636
}
37+
#theURL {
38+
margin: 0.25em 0;
39+
padding: 0;
40+
}
41+
#theURL > * {
42+
margin: 0;
43+
}
44+
#theURL > p {
45+
position: relative;
46+
z-index: 10;
47+
}
48+
#theURL > p > span {
49+
background-color: transparent;
50+
top: 100%;
51+
box-sizing: border-box;
52+
cursor: pointer;
53+
opacity: 0.5;
54+
padding: 0.2em;
55+
position: absolute;
56+
transform: translate(0, -50%);
57+
}
58+
body[dir="ltr"] #theURL > p > span {
59+
right: 0;
60+
}
61+
body[dir="rtl"] #theURL > p > span {
62+
left: 0;
63+
}
64+
#theURL > p:hover > span {
65+
opacity: 1;
66+
}
67+
#theURL > p > span:before {
68+
content: '\f010';
69+
}
70+
#theURL.collapsed > p > span:before {
71+
content: '\f00e';
72+
}
73+
#parsed {
74+
background-color: #f8f8f8;
75+
border: 1px solid rgba(0, 0, 0, 0.1);
76+
border-top: none;
77+
color: gray;
78+
font-size: small;
79+
overflow-x: hidden;
80+
padding: 4px;
81+
text-align: initial;
82+
text-overflow: ellipsis;
83+
}
84+
#theURL.collapsed > #parsed {
85+
display: none;
86+
}
87+
#parsed ul, #parsed li {
88+
list-style-type: none;
89+
}
90+
#parsed li {
91+
white-space: nowrap;
92+
}
93+
#parsed span {
94+
display: inline-block;
95+
}
96+
#parsed span:first-of-type {
97+
font-weight: bold;
98+
}
3799
#warningSign {
38100
margin: 1e, 0;
39101
opacity: 1;
@@ -50,7 +112,10 @@
50112
<div id="warningSign"><span class="fa">&#xf071;</span></div>
51113
<div>
52114
<p data-i18n="mainBlockedPrompt1"></p>
53-
<p class="what code"></p>
115+
<div id="theURL" class="collapsed">
116+
<p class="what code"></p>
117+
<ul id="parsed"></ul>
118+
</div>
54119
</div>
55120

56121
<!-- <div>

0 commit comments

Comments
 (0)