This commit is contained in:
Ray Lothian 2020-08-04 06:47:39 +02:00
parent 400ca5ae66
commit 80823ddf65
4 changed files with 49 additions and 50 deletions

View file

@ -416,28 +416,26 @@ chrome.contextMenus.onClicked.addListener(info => chrome.storage.local.set({
/* FAQs & Feedback */ /* FAQs & Feedback */
{ {
const {onInstalled, setUninstallURL, getManifest} = chrome.runtime; const {management, runtime: {onInstalled, setUninstallURL, getManifest}, storage, tabs} = chrome;
const {name, version} = getManifest();
const page = getManifest().homepage_url;
if (navigator.webdriver !== true) { if (navigator.webdriver !== true) {
const page = getManifest().homepage_url;
const {name, version} = getManifest();
onInstalled.addListener(({reason, previousVersion}) => { onInstalled.addListener(({reason, previousVersion}) => {
chrome.storage.local.get({ management.getSelf(({installType}) => installType === 'normal' && storage.local.get({
'faqs': true, 'faqs': true,
'last-update': 0 'last-update': 0
}, prefs => { }, prefs => {
if (reason === 'install' || (prefs.faqs && reason === 'update')) { if (reason === 'install' || (prefs.faqs && reason === 'update')) {
const doUpdate = (Date.now() - prefs['last-update']) / 1000 / 60 / 60 / 24 > 45; const doUpdate = (Date.now() - prefs['last-update']) / 1000 / 60 / 60 / 24 > 45;
if (doUpdate && previousVersion !== version) { if (doUpdate && previousVersion !== version) {
chrome.tabs.create({ tabs.create({
url: page + '?version=' + version + url: page + '?version=' + version + (previousVersion ? '&p=' + previousVersion : '') + '&type=' + reason,
(previousVersion ? '&p=' + previousVersion : '') +
'&type=' + reason,
active: reason === 'install' active: reason === 'install'
}); });
chrome.storage.local.set({'last-update': Date.now()}); storage.local.set({'last-update': Date.now()});
} }
} }
}); }));
}); });
setUninstallURL(page + '?rd=feedback&name=' + encodeURIComponent(name) + '&version=' + version); setUninstallURL(page + '?rd=feedback&name=' + encodeURIComponent(name) + '&version=' + version);
} }

View file

@ -93,8 +93,7 @@ select {
} }
#list { #list {
overflow: auto; overflow: auto;
height: 268px; height: 240px;
margin-bottom: 16px;
color: #000; color: #000;
background-position: top 120px center; background-position: top 120px center;
background-repeat: no-repeat; background-repeat: no-repeat;
@ -177,7 +176,7 @@ select {
#agent { #agent {
white-space: nowrap; white-space: nowrap;
display: grid; display: grid;
grid-template-columns: repeat(7, 1fr); grid-template-columns: repeat(4, 1fr);
grid-gap: 1px; grid-gap: 1px;
} }

View file

@ -121,12 +121,13 @@
</table> </table>
</div> </div>
<div id="explore" data-cols=4></div> <div id="explore" data-cols=4></div>
<div hbox id="agent" align="center"> <div id="agent" align="center">
<input type="button" value="Options" title="Open options page" style="margin-left: 2px;" data-cmd="options"> <input type="button" value="Options" title="Open options page" style="margin-left: 2px;" data-cmd="options">
<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"> <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">
<input type="button" value="Refresh Tab" title="Refresh the current page" data-cmd="refresh"> <input type="button" value="Refresh Tab" title="Refresh the current page" data-cmd="refresh">
<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" data-cmd="reset"> <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" data-cmd="reset">
<input type="button" value="Test" title="Test your user-agent string" data-cmd="test"> <input type="button" value="Test" title="Test your user-agent string" data-cmd="test">
<span></span>
<input type="button" value="Window" title="Set this string as this window's User-Agent string" data-cmd="window"> <input type="button" value="Window" title="Set this string as this window's User-Agent string" data-cmd="window">
<input type="button" value="Apply" title="Set this string as the browser's User-Agent string" data-cmd="apply"> <input type="button" value="Apply" title="Set this string as the browser's User-Agent string" data-cmd="apply">
</div> </div>

View file

@ -43,45 +43,46 @@ function update(ua) {
tbody.textContent = ''; tbody.textContent = '';
parent.dataset.loading = true; parent.dataset.loading = true;
fetch('browsers/' + browser.toLowerCase() + '-' + os.toLowerCase().replace(/\//g, '-') + '.json').then(r => r.json()).catch(e => { fetch('browsers/' + browser.toLowerCase() + '-' + os.toLowerCase().replace(/\//g, '-') + '.json')
console.error(e); .then(r => r.json()).catch(e => {
return []; console.error(e);
}).then(list => { return [];
if (list) { }).then(list => {
const fragment = document.createDocumentFragment(); if (list) {
let radio; const fragment = document.createDocumentFragment();
for (const o of sort(list)) { let radio;
const clone = document.importNode(t.content, true); for (const o of sort(list)) {
const second = clone.querySelector('td:nth-child(2)'); const clone = document.importNode(t.content, true);
second.title = second.textContent = o.browser.name + ' ' + (o.browser.version || ' '); const second = clone.querySelector('td:nth-child(2)');
const third = clone.querySelector('td:nth-child(3)'); second.title = second.textContent = o.browser.name + ' ' + (o.browser.version || ' ');
third.title = third.textContent = o.os.name + ' ' + (o.os.version || ' '); const third = clone.querySelector('td:nth-child(3)');
const forth = clone.querySelector('td:nth-child(4)'); third.title = third.textContent = o.os.name + ' ' + (o.os.version || ' ');
forth.title = forth.textContent = o.ua; const forth = clone.querySelector('td:nth-child(4)');
if (o.ua === ua) { forth.title = forth.textContent = o.ua;
radio = clone.querySelector('input[type=radio]'); if (o.ua === ua) {
radio = clone.querySelector('input[type=radio]');
}
fragment.appendChild(clone);
} }
fragment.appendChild(clone); tbody.appendChild(fragment);
} if (radio) {
tbody.appendChild(fragment); radio.checked = true;
if (radio) { radio.scrollIntoView({
radio.checked = true; block: 'center',
radio.scrollIntoView({ inline: 'nearest'
block: 'center', });
inline: 'nearest' }
document.getElementById('custom').placeholder = `Filter among ${list.length}`;
[...document.getElementById('os').querySelectorAll('option')].forEach(option => {
option.disabled = (map.matching[browser.toLowerCase()] || []).indexOf(option.value.toLowerCase()) === -1;
}); });
} }
document.getElementById('custom').placeholder = `Filter among ${list.length}`; else {
[...document.getElementById('os').querySelectorAll('option')].forEach(option => { throw Error('OS is not found');
option.disabled = (map.matching[browser.toLowerCase()] || []).indexOf(option.value.toLowerCase()) === -1; }
}); }).finally(() => {
} parent.dataset.loading = false;
else { });
throw Error('OS is not found');
}
}).finally(() => {
parent.dataset.loading = false;
});
} }
document.getElementById('browser').addEventListener('change', e => chrome.storage.local.set({ document.getElementById('browser').addEventListener('change', e => chrome.storage.local.set({