code review re. 8e9fe020b5

This commit is contained in:
Raymond Hill 2018-07-22 08:14:50 -04:00
parent d5f40b90f6
commit 80fedd4647
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
4 changed files with 172 additions and 28 deletions

View file

@ -0,0 +1,147 @@
/**
uBlock Origin - a browser extension to block requests.
Copyright (C) 2018-present Raymond Hill
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see {http://www.gnu.org/licenses/}.
Home: https://github.com/gorhill/uBlock
*/
body {
font-size: large;
text-align: center;
}
body > div {
margin: 1.5em 0;
}
body > div > p,
body > div > div {
margin: 4px 0;
}
body > div > p:first-child {
margin: 1.5em 0 0 0;
}
a {
text-decoration: none;
}
button {
cursor: pointer;
margin: 0 1em 0.25em 1em;
padding: 0.25em 0.5em;
font-size: inherit;
}
select {
font: inherit;
padding: 2px;
}
.code {
background-color: rgba(0, 0, 0, 0.1);
font-family: monospace;
font-size: large;
line-height: 1;
padding: 4px;
word-break: break-all;
}
#warningSign {
opacity: 1;
pointer-events: none;
width: 100%;
}
#warningSign > span {
color: #f2a500;
font-size: 10em;
}
#theURL {
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;
}
#whyex {
font-size: smaller;
}
#whyex a {
white-space: nowrap;
}
.proceedChoice {
text-align: left;
}
.filterList a {
opacity: 0.8;
}
.filterList a:hover {
opacity: 1;
}
.filterList:first-child .filterListSeparator {
display: none;
}
.filterList .filterListSupport[href=""] {
display: none;
}

View file

@ -47,7 +47,7 @@
</span> </span>
<span class="filterList"> <span class="filterList">
<span class="filterListSeparator">&#x2022;</span> <span class="filterListSeparator">&#x2022;</span>
<a class="filterListSource" href="" target="_blank"></a>&nbsp;<!-- <a class="filterListSource" href="asset-viewer.html?url=" target="_blank"></a>&nbsp;<!--
--><a class="fa filterListSupport" href="" target="_blank">&#xf015;</a> --><a class="fa filterListSupport" href="" target="_blank">&#xf015;</a>
</span> </span>
</div> </div>

View file

@ -21,12 +21,12 @@
/* global uDom */ /* global uDom */
'use strict';
/******************************************************************************/ /******************************************************************************/
(function() { (function() {
'use strict';
/******************************************************************************/ /******************************************************************************/
var messaging = vAPI.messaging; var messaging = vAPI.messaging;
@ -44,14 +44,11 @@ var details = {};
(function() { (function() {
var onReponseReady = function(response) { var onReponseReady = function(response) {
if ( typeof response !== 'object' ) { if ( response instanceof Object === false ) { return; }
return;
} let lists;
var lists; for ( let rawFilter in response ) {
for ( var rawFilter in response ) { if ( response.hasOwnProperty(rawFilter) === false ) { continue; }
if ( response.hasOwnProperty(rawFilter) === false ) {
continue;
}
lists = response[rawFilter]; lists = response[rawFilter];
break; break;
} }
@ -59,19 +56,20 @@ var details = {};
if ( Array.isArray(lists) === false || lists.length === 0 ) { if ( Array.isArray(lists) === false || lists.length === 0 ) {
return; return;
} }
let parent = uDom.nodeFromSelector('#whyex > span:nth-of-type(2)'); let parent = uDom.nodeFromSelector('#whyex > span:nth-of-type(2)');
for ( let i = 0; i < lists.length; i++ ) { for ( let list of lists ) {
let entry = lists[i]; let elem = document.querySelector('#templates .filterList')
let elem = document.querySelector('#templates .filterList').cloneNode(true); .cloneNode(true);
let source = elem.querySelector('.filterListSource'); let source = elem.querySelector('.filterListSource');
source.href = 'asset-viewer.html?url=' + entry.assetKey; source.href += encodeURIComponent(list.assetKey);
source.textContent = entry.title; source.textContent = list.title;
if ( if (
typeof entry.supportURL === 'string' && typeof list.supportURL === 'string' &&
entry.supportURL !== '' list.supportURL !== ''
) { ) {
elem.querySelector('.filterListSupport') elem.querySelector('.filterListSupport')
.setAttribute('href', entry.supportURL); .setAttribute('href', list.supportURL);
} }
parent.appendChild(elem); parent.appendChild(elem);
} }

View file

@ -24,10 +24,9 @@
(function() { (function() {
// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json/commands#Shortcut_values // https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json/commands#Shortcut_values
let validStatus0Codes = new Map([ let validStatus0Keys = new Map([
[ 'AltLeft', 'Alt' ], [ 'alt', 'Alt' ],
[ 'ControlLeft', 'Ctrl' ], [ 'control', 'Ctrl' ],
[ 'ControlRight', 'Ctrl' ],
]); ]);
let validStatus1Keys = new Map([ let validStatus1Keys = new Map([
[ 'a', 'A' ], [ 'a', 'A' ],
@ -137,9 +136,9 @@
return; return;
} }
if ( status === 0 ) { if ( status === 0 ) {
let key = validStatus0Codes.get(ev.code); let keyName = validStatus0Keys.get(ev.key.toLowerCase());
if ( key !== undefined ) { if ( keyName !== undefined ) {
after.add(key); after.add(keyName);
updateCapturedShortcut(); updateCapturedShortcut();
status = 1; status = 1;
} }
@ -166,8 +165,8 @@
ev.preventDefault(); ev.preventDefault();
ev.stopImmediatePropagation(); ev.stopImmediatePropagation();
if ( status !== 1 ) { return; } if ( status !== 1 ) { return; }
let key = validStatus0Codes.get(ev.code); let keyName = validStatus0Keys.get(ev.key.toLowerCase());
if ( key !== undefined && after.has(key) ) { if ( keyName !== undefined && after.has(keyName) ) {
after.clear(); after.clear();
updateCapturedShortcut(); updateCapturedShortcut();
status = 0; status = 0;