Change: drop excludeStyleByUrlRedundant

This commit is contained in:
eight 2019-03-09 16:58:50 +08:00
parent 629d017d94
commit 76129e125c
2 changed files with 9 additions and 15 deletions

View File

@ -321,9 +321,6 @@
"excludeStyleByUrlLabel": { "excludeStyleByUrlLabel": {
"message": "Exclude the current URL" "message": "Exclude the current URL"
}, },
"excludeStyleByUrlRedundant": {
"message": "The current URL is the domain page"
},
"exportLabel": { "exportLabel": {
"message": "Export", "message": "Export",
"description": "Label for the button to export a style ('edit' page) or all styles ('manage' page)" "description": "Label for the button to export a style ('edit' page) or all styles ('manage' page)"

View File

@ -335,16 +335,7 @@ function createStyleElement(style) {
entry.classList.toggle('regexp-partial', style.sloppy); entry.classList.toggle('regexp-partial', style.sloppy);
$('.exclude-by-domain-checkbox', entry).checked = styleExcluded(style, 'domain'); $('.exclude-by-domain-checkbox', entry).checked = styleExcluded(style, 'domain');
$('.exclude-by-url-checkbox', entry).checked = styleExcluded(style, 'url');
const excludeByUrlCheckbox = $('.exclude-by-url-checkbox', entry);
const isRedundant = getExcludeRule('domain') === getExcludeRule('url');
excludeByUrlCheckbox.checked = !isRedundant && styleExcluded(style, 'url');
excludeByUrlCheckbox.disabled = isRedundant;
const excludeByUrlLabel = $('.exclude-by-url', entry);
excludeByUrlLabel.classList.toggle('disabled', isRedundant);
excludeByUrlLabel.title = isRedundant ?
chrome.i18n.getMessage('excludeStyleByUrlRedundant') : '';
return entry; return entry;
} }
@ -358,10 +349,16 @@ function styleExcluded({exclusions}, type) {
} }
function getExcludeRule(type) { function getExcludeRule(type) {
const u = new URL(tabURL);
if (type === 'domain') { if (type === 'domain') {
return new URL(tabURL).origin + '/*'; return u.origin + '/*';
} }
return tabURL + '*'; // current page
return escapeGlob(u.origin + u.pathname);
}
function escapeGlob(text) {
return text.replace(/\*/g, '\\*');
} }
Object.assign(handleEvent, { Object.assign(handleEvent, {