-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Blocking from popup did not trigger sync
Change: Move HTML from popup.js to popup.html
- Loading branch information
Showing
5 changed files
with
145 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
body { | ||
#blockPopup, #unblockPopup { | ||
display: none; | ||
font-size: 13px; | ||
margin: 0; | ||
} | ||
|
||
#ubBlockForm, #ubUnblockForm { | ||
#blockForm, #unblockForm { | ||
padding: 20px 12px; | ||
white-space: nowrap; | ||
} | ||
|
||
#ubBlockInput, #ubUnblockSelect { | ||
#blockInput, #unblockSelect { | ||
margin: 0 6px; | ||
width: 280px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,46 @@ | ||
loadBlockRules(blockRules => { | ||
chrome.tabs.query({ active: true, currentWindow: true }, activeTabs => { | ||
const url = activeTabs[0].url; | ||
if (!/^(https?|ftp):$/.test(new URL(url).protocol) || | ||
!blockRules.some(rule => rule.compiled && rule.compiled.test(url))) { | ||
document.body.insertAdjacentHTML('beforeend', String.raw` | ||
<form id="ubBlockForm"> | ||
<label> | ||
${_('blockThisSite')}: | ||
<input id="ubBlockInput" type="text" autofocus spellcheck="false"> | ||
</label> | ||
<button type="submit">${_('ok')}</button> | ||
</form> | ||
`); | ||
$('ubBlockInput').value = deriveBlockRule(url) || ''; | ||
$('ubBlockForm').addEventListener('submit', event => { | ||
event.preventDefault(); | ||
const raw = $('ubBlockInput').value; | ||
const compiled = compileBlockRule(raw); | ||
if (compiled) { | ||
blockRules.push({ raw, compiled }); | ||
for (const element of document.querySelectorAll('[data-i18n]')) { | ||
element.insertAdjacentHTML('beforeend', _(element.dataset.i18n)); | ||
} | ||
|
||
(async () => { | ||
const blockRules = await loadBlockRules(); | ||
const url = (await queryTabs({ active: true, currentWindow: true }))[0].url; | ||
const blocked = /^(https?|ftp):$/.test(new URL(url).protocol) && | ||
blockRules.some(rule => rule.compiled && rule.compiled.test(url)); | ||
if (!blocked) { | ||
$('blockInput').value = deriveBlockRule(url) || ''; | ||
$('blockForm').addEventListener('submit', event => { | ||
event.preventDefault(); | ||
const raw = $('blockInput').value; | ||
const compiled = compileBlockRule(raw); | ||
if (compiled) { | ||
blockRules.push({ raw, compiled }); | ||
(async () => { | ||
saveBlockRules(blockRules); | ||
} | ||
window.close(); | ||
})(); | ||
} else { | ||
window.close(); | ||
}); | ||
} else { | ||
document.body.insertAdjacentHTML('beforeend', String.raw` | ||
<form id="ubUnblockForm"> | ||
<label> | ||
${_('unblockThisSite')}: | ||
<select id="ubUnblockSelect" autofocus> | ||
</select> | ||
</label> | ||
<button type="submit">${_('ok')}</button> | ||
</form> | ||
`); | ||
blockRules.forEach((rule, index) => { | ||
if (rule.compiled && rule.compiled.test(url)) { | ||
const option = document.createElement('option'); | ||
option.textContent = rule.raw; | ||
option.value = String(index); | ||
$('ubUnblockSelect').appendChild(option); | ||
} | ||
}); | ||
$('ubUnblockForm').addEventListener('submit', event => { | ||
event.preventDefault(); | ||
blockRules.splice(Number($('ubUnblockSelect').value), 1); | ||
} | ||
}); | ||
$('blockPopup').style.display = 'block'; | ||
} else { | ||
blockRules.forEach((rule, index) => { | ||
if (rule.compiled && rule.compiled.test(url)) { | ||
const option = document.createElement('option'); | ||
option.textContent = rule.raw; | ||
option.value = String(index); | ||
$('unblockSelect').appendChild(option); | ||
} | ||
}); | ||
$('unblockForm').addEventListener('submit', event => { | ||
event.preventDefault(); | ||
blockRules.splice(Number($('unblockSelect').value), 1); | ||
(async () => { | ||
saveBlockRules(blockRules); | ||
window.close(); | ||
}); | ||
} | ||
}); | ||
}); | ||
})(); | ||
}); | ||
$('unblockPopup').style.display = 'block'; | ||
} | ||
})(); |