Ray Lothian 2017-11-22 16:05:22 +03:30
parent 96b13e4b7f
commit 846dc6f8a4
7 changed files with 175 additions and 10 deletions

View file

@ -110,3 +110,10 @@ input[type=button]:disabled {
padding: 10px 0;
white-space: nowrap;
}
#info {
padding: 0 5px;
}
#info:empty {
display: none;
}

View file

@ -152,6 +152,7 @@
<div hbox id="agent" pack="center" align="center">
User-Agent String:&nbsp;
<input id="ua" type="text" name="">
<span id="info"></span>
<input type="button" value="Apply" title="Set this string as the browser's User-Agent string" data-cmd="apply">
<input type="button" value="Reset" title="Reset User-Agent string to the default one" style="margin-left: 2px;" data-cmd="reset">
</div>

View file

@ -142,13 +142,26 @@ window.addEventListener('load', () => {
}, 100);
});
function msg(msg) {
const info = document.getElementById('info');
info.textContent = msg;
window.setTimeout(() => info.textContent = '', 750);
}
// commands
document.addEventListener('click', ({target}) => {
const cmd = target.dataset.cmd;
if (cmd) {
if (cmd === 'apply') {
const value = document.getElementById('ua').value;
if (value === navigator.userAgent) {
msg('Default user-agent');
}
else {
msg('user-agent is set');
}
chrome.storage.local.set({
ua: document.getElementById('ua').value
ua: value === navigator.userAgent ? '' : value
});
}
else if (cmd === 'reset') {
@ -159,6 +172,7 @@ document.addEventListener('click', ({target}) => {
chrome.storage.local.set({
ua: ''
});
msg('reset to default');
}
else if (cmd === 'refresh') {
chrome.tabs.query({