Browse Source

fix #502

pull/2/head
gorhill 7 years ago
parent
commit
3f8168ce0b
No known key found for this signature in database GPG Key ID: 25E1490B761470C2
  1. 113
      src/js/main-blocked.js
  2. 69
      src/main-blocked.html

113
src/js/main-blocked.js

@ -1,7 +1,7 @@
/******************************************************************************* /*******************************************************************************
µMatrix - a browser extension to block requests.
Copyright (C) 2015 Raymond Hill
uMatrix - a browser extension to block requests.
Copyright (C) 2015-2017 Raymond Hill
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -33,16 +33,117 @@ var details = {};
(function() { (function() {
var matches = /details=([^&]+)/.exec(window.location.search); var matches = /details=([^&]+)/.exec(window.location.search);
if ( matches === null ) {
return;
if ( matches === null ) { return; }
try {
details = JSON.parse(atob(matches[1]));
} catch(ex) {
} }
details = JSON.parse(atob(matches[1]));
})(); })();
/******************************************************************************/ /******************************************************************************/
uDom('.what').text(details.url); uDom('.what').text(details.url);
uDom('#why').text(details.why.slice(3));
// uDom('#why').text(details.why.slice(3));
/******************************************************************************/
// https://github.com/gorhill/uMatrix/issues/502
// Code below originally imported from:
// https://github.com/gorhill/uBlock/blob/master/src/js/document-blocked.js
(function() {
if ( typeof URL !== 'function' ) { return; }
var reURL = /^https?:\/\//;
var liFromParam = function(name, value) {
if ( value === '' ) {
value = name;
name = '';
}
var li = document.createElement('li');
var span = document.createElement('span');
span.textContent = name;
li.appendChild(span);
if ( name !== '' && value !== '' ) {
li.appendChild(document.createTextNode(' = '));
}
span = document.createElement('span');
if ( reURL.test(value) ) {
var a = document.createElement('a');
a.href = a.textContent = value;
span.appendChild(a);
} else {
span.textContent = value;
}
li.appendChild(span);
return li;
};
var safeDecodeURIComponent = function(s) {
try {
s = decodeURIComponent(s);
} catch (ex) {
}
return s;
};
var renderParams = function(parentNode, rawURL) {
var a = document.createElement('a');
a.href = rawURL;
if ( a.search.length === 0 ) { return false; }
var pos = rawURL.indexOf('?');
var li = liFromParam(
vAPI.i18n('docblockedNoParamsPrompt'),
rawURL.slice(0, pos)
);
parentNode.appendChild(li);
var params = a.search.slice(1).split('&');
var param, name, value, ul;
for ( var i = 0; i < params.length; i++ ) {
param = params[i];
pos = param.indexOf('=');
if ( pos === -1 ) {
pos = param.length;
}
name = safeDecodeURIComponent(param.slice(0, pos));
value = safeDecodeURIComponent(param.slice(pos + 1));
li = liFromParam(name, value);
if ( reURL.test(value) ) {
ul = document.createElement('ul');
renderParams(ul, value);
li.appendChild(ul);
}
parentNode.appendChild(li);
}
return true;
};
if ( renderParams(uDom.nodeFromId('parsed'), details.url) === false ) {
return;
}
var toggler = document.createElement('span');
toggler.className = 'fa';
uDom('#theURL > p').append(toggler);
uDom(toggler).on('click', function() {
var collapsed = uDom.nodeFromId('theURL').classList.toggle('collapsed');
vAPI.localStorage.setItem(
'document-blocked-collapse-url',
collapsed.toString()
);
});
uDom.nodeFromId('theURL').classList.toggle(
'collapsed',
vAPI.localStorage.getItem('document-blocked-collapse-url') === 'true'
);
})();
/******************************************************************************/
if ( window.history.length > 1 ) { if ( window.history.length > 1 ) {
uDom('#back').on('click', function() { window.history.back(); }); uDom('#back').on('click', function() { window.history.back(); });

69
src/main-blocked.html

@ -24,7 +24,7 @@ body > div > p:first-child {
display: inline-block; display: inline-block;
font-family: monospace; font-family: monospace;
font-size: large; font-size: large;
line-height: 1;
line-height: 1.2;
padding: 2px 4px; padding: 2px 4px;
word-break: break-all; word-break: break-all;
} }
@ -34,6 +34,68 @@ button {
padding: 0.25em 0.5em; padding: 0.25em 0.5em;
font-size: inherit; font-size: inherit;
} }
#theURL {
margin: 0.25em 0;
padding: 0;
}
#theURL > * {
margin: 0;
}
#theURL > p {
position: relative;
z-index: 10;
}
#theURL > p > span {
background-color: transparent;
top: 100%;
box-sizing: border-box;
cursor: pointer;
opacity: 0.5;
padding: 0.2em;
position: absolute;
transform: translate(0, -50%);
}
body[dir="ltr"] #theURL > p > span {
right: 0;
}
body[dir="rtl"] #theURL > p > span {
left: 0;
}
#theURL > p:hover > span {
opacity: 1;
}
#theURL > p > span:before {
content: '\f010';
}
#theURL.collapsed > p > span:before {
content: '\f00e';
}
#parsed {
background-color: #f8f8f8;
border: 1px solid rgba(0, 0, 0, 0.1);
border-top: none;
color: gray;
font-size: small;
overflow-x: hidden;
padding: 4px;
text-align: initial;
text-overflow: ellipsis;
}
#theURL.collapsed > #parsed {
display: none;
}
#parsed ul, #parsed li {
list-style-type: none;
}
#parsed li {
white-space: nowrap;
}
#parsed span {
display: inline-block;
}
#parsed span:first-of-type {
font-weight: bold;
}
#warningSign { #warningSign {
margin: 1e, 0; margin: 1e, 0;
opacity: 1; opacity: 1;
@ -50,7 +112,10 @@ button {
<div id="warningSign"><span class="fa">&#xf071;</span></div> <div id="warningSign"><span class="fa">&#xf071;</span></div>
<div> <div>
<p data-i18n="mainBlockedPrompt1"></p> <p data-i18n="mainBlockedPrompt1"></p>
<p class="what code"></p>
<div id="theURL" class="collapsed">
<p class="what code"></p>
<ul id="parsed"></ul>
</div>
</div> </div>
<!-- <div> <!-- <div>

Loading…
Cancel
Save