fixes #12
This commit is contained in:
parent
5d9b0e6b12
commit
d1b29b805a
4 changed files with 151 additions and 71 deletions
|
@ -156,6 +156,7 @@ select {
|
|||
margin-left: 2px;
|
||||
margin-right: 2px;
|
||||
}
|
||||
[data-cmd="window"],
|
||||
[data-cmd="apply"] {
|
||||
color: #fff;
|
||||
background-color: #3c923c;
|
||||
|
@ -170,6 +171,7 @@ select {
|
|||
border: solid 1px #ec9730;
|
||||
}
|
||||
|
||||
[data-cmd="reload"],
|
||||
[data-cmd="options"],
|
||||
[data-cmd="refresh"] {
|
||||
color: #000;
|
||||
|
@ -177,6 +179,5 @@ select {
|
|||
}
|
||||
|
||||
#explore:not([data-loaded="true"]) {
|
||||
margin-top: -8px;
|
||||
height: 16px;
|
||||
}
|
||||
|
|
|
@ -146,16 +146,18 @@
|
|||
</div>
|
||||
<div hbox>
|
||||
<input type="search" id="custom" placeholder="Filter items">
|
||||
<input type="button" value="Refresh Tab" title="Refresh the current page" data-cmd="refresh">
|
||||
<input type="button" value="Options" title="Open options page" style="margin-left: 2px;" data-cmd="options">
|
||||
<input type="button" value="Refresh Tab" title="Refresh the current page" data-cmd="refresh">
|
||||
<input type="button" value="Restart" title="Click to reload the extension. This will cause all the window-based user-agent strings to be cleared" data-cmd="reload">
|
||||
</div>
|
||||
<div hbox id="agent" pack="center" align="center">
|
||||
User-Agent String:
|
||||
<input id="ua" type="text" placeholder="Your preferred user-agent string">
|
||||
<span id="info"></span>
|
||||
<span id="info">User-Agent String:</span>
|
||||
<span flex="1"></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">
|
||||
<input type="button" value="Window" title="Set this string as this window's User-Agent string" data-cmd="window">
|
||||
<input type="button" value="Reset" title="Reset User-Agent string to the default one. This will not reset window-based UA strings. To reset them, use the 'Restart' button" style="margin-left: 2px;" data-cmd="reset">
|
||||
</div>
|
||||
<input id="ua" type="text" placeholder="Your preferred user-agent string">
|
||||
<div id="explore"></div>
|
||||
<script src="ua-parser.min.js"></script>
|
||||
<script src="index.js"></script>
|
||||
|
|
|
@ -96,6 +96,7 @@ document.addEventListener('change', ({target}) => {
|
|||
}
|
||||
if (target.type === 'radio') {
|
||||
document.getElementById('ua').value = target.closest('tr').querySelector('td:nth-child(4)').textContent;
|
||||
document.getElementById('ua').dispatchEvent(new Event('input'));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -127,6 +128,7 @@ chrome.storage.local.get({
|
|||
chrome.storage.onChanged.addListener(prefs => {
|
||||
if (prefs.ua) {
|
||||
document.getElementById('ua').value = prefs.ua.newValue || navigator.userAgent;
|
||||
document.getElementById('ua').dispatchEvent(new Event('input'));
|
||||
}
|
||||
});
|
||||
window.addEventListener('load', () => {
|
||||
|
@ -145,7 +147,7 @@ window.addEventListener('load', () => {
|
|||
function msg(msg) {
|
||||
const info = document.getElementById('info');
|
||||
info.textContent = msg;
|
||||
window.setTimeout(() => info.textContent = '', 750);
|
||||
window.setTimeout(() => info.textContent = 'User-Agent String:', 2000);
|
||||
}
|
||||
|
||||
// commands
|
||||
|
@ -155,7 +157,7 @@ document.addEventListener('click', ({target}) => {
|
|||
if (cmd === 'apply') {
|
||||
const value = document.getElementById('ua').value;
|
||||
if (value === navigator.userAgent) {
|
||||
msg('Default user-agent');
|
||||
msg('Default UA, press the reset button instead');
|
||||
}
|
||||
else {
|
||||
msg('user-agent is set');
|
||||
|
@ -164,6 +166,13 @@ document.addEventListener('click', ({target}) => {
|
|||
ua: value === navigator.userAgent ? '' : value
|
||||
});
|
||||
}
|
||||
else if (cmd === 'window') {
|
||||
const value = document.getElementById('ua').value;
|
||||
chrome.tabs.query({
|
||||
active: true,
|
||||
currentWindow: true
|
||||
}, ([tab]) => chrome.runtime.getBackgroundPage(bg => bg.ua.update(value, tab.windowId)));
|
||||
}
|
||||
else if (cmd === 'reset') {
|
||||
const input = document.querySelector('#list :checked');
|
||||
if (input) {
|
||||
|
@ -185,5 +194,13 @@ document.addEventListener('click', ({target}) => {
|
|||
else if (cmd === 'options') {
|
||||
chrome.runtime.openOptionsPage();
|
||||
}
|
||||
else if (cmd === 'reload') {
|
||||
chrome.runtime.reload();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('ua').addEventListener('input', e => {
|
||||
document.querySelector('[data-cmd=apply]').disabled = e.target.value === '';
|
||||
document.querySelector('[data-cmd=window]').disabled = e.target.value === '';
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue