Add locale support part 2
This commit is contained in:
parent
b75902d620
commit
c42258beb3
6 changed files with 248 additions and 112 deletions
|
@ -78,7 +78,7 @@
|
|||
<td>userAgent</td>
|
||||
<td colspan="3">
|
||||
<div hbox>
|
||||
<input id="ua" type="text" autofocus placeholder="Your preferred user-agent string" title="To set a blank user-agent string, use the 'empty' keyword. To construct a custom user-agent string based on the current browser's navigator object, use ${} notation. Whatever is inside this notation is read from the 'navigator' object. For instance, to append a string to the default user-agent, use '${userAgent} THIS IS THE APPENDED STRING'">
|
||||
<input id="ua" type="text" autofocus data-localized-placeholder="uaPlaceholder" placeholder="Your preferred user-agent string" data-localized-title="uaTitle" title="To set a blank user-agent string, use the 'empty' keyword. To construct a custom user-agent string based on the current browser's navigator object, use ${} notation. Whatever is inside this notation is read from the 'navigator' object. For instance, to append a string to the default user-agent, use '${userAgent} THIS IS THE APPENDED STRING'">
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -86,7 +86,7 @@
|
|||
<td>appVersion</td>
|
||||
<td colspan="3">
|
||||
<div hbox>
|
||||
<input readonly value="-" id="appVersion" type="text" title="This is a readonly field. Use options page for custom parsing.">
|
||||
<input readonly value="-" id="appVersion" type="text" data-localized-title="appVersionTitle" title="This is a readonly field. Use options page for custom parsing.">
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -94,13 +94,13 @@
|
|||
<td>platform</td>
|
||||
<td>
|
||||
<div hbox>
|
||||
<input readonly value="-" id="platform" type="text" title="This is a readonly field. Use options page for custom parsing.">
|
||||
<input readonly value="-" id="platform" type="text" data-localized-title="platformTitle" title="This is a readonly field. Use options page for custom parsing.">
|
||||
</div>
|
||||
</td>
|
||||
<td>vendor</td>
|
||||
<td>
|
||||
<div hbox>
|
||||
<input readonly value="-" id="vendor" type="text" title="This is a readonly field. Use options page for custom parsing.">
|
||||
<input readonly value="-" id="vendor" type="text" data-localized-title="vendorTitle" title="This is a readonly field. Use options page for custom parsing.">
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -108,13 +108,13 @@
|
|||
<td>product</td>
|
||||
<td>
|
||||
<div hbox>
|
||||
<input readonly value="-" id="product" type="text" title="This is a readonly field. Use options page for custom parsing.">
|
||||
<input readonly value="-" id="product" type="text" data-localized-title="productTitle" title="This is a readonly field. Use options page for custom parsing.">
|
||||
</div>
|
||||
</td>
|
||||
<td>oscpu</td>
|
||||
<td>
|
||||
<div hbox>
|
||||
<input readonly value="-" id="oscpu" type="text" title="This is a readonly field. Use options page for custom parsing.">
|
||||
<input readonly value="-" id="oscpu" type="text" data-localized-title="oscpuTitle" title="This is a readonly field. Use options page for custom parsing.">
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -122,14 +122,14 @@
|
|||
</div>
|
||||
<div id="explore" data-cols=4></div>
|
||||
<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="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="Reset" title="Reset browser's 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 UA" title="Test your user-agent string" data-cmd="test">
|
||||
<input type="button" value="Consider Containers" title="Allow the extension to access your browser's containers. If this permission is granted, tabs inside isolated containers do not follow the default container's user-agent string. You need to set this string for each new container." data-cmd="container" class="hide">
|
||||
<input type="button" value="Apply (active window)" title="Set this user-agent string for all tabs inside the current window" data-cmd="window">
|
||||
<input type="button" value="Apply (all windows)" title="Set this user-agent string as the browser's User-Agent string" data-cmd="apply">
|
||||
<input type="button" data-localized-value="options" value="Options" data-localized-title="optionsTitle" title="Open options page" style="margin-left: 2px;" data-cmd="options">
|
||||
<input type="button" data-localized-value="restart" value="Restart" data-localized-title="restartTitle" 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" data-localized-value="refreshTab" value="Refresh Tab" data-localized-title="refreshTabTitle" title="Refresh the current page" data-cmd="refresh">
|
||||
<input type="button" data-localized-value="reset" value="Reset" data-localized-title="resetTitle" title="Reset browser's 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" data-localized-value="testUA" value="Test UA" data-localized-value="testUATitle" title="Test your user-agent string" data-cmd="test">
|
||||
<input type="button" data-localized-value="considerContainers" value="Consider Containers" data-localized-title="considerContainersTitle" title="Allow the extension to access your browser's containers. If this permission is granted, tabs inside isolated containers do not follow the default container's user-agent string. You need to set this string for each new container." data-cmd="container" class="hide">
|
||||
<input type="button" data-localized-value="applyActiveWindow" value="Apply (active window)" data-localized-title="applyActiveWindowTitle" title="Set this user-agent string for all tabs inside the current window" data-cmd="window">
|
||||
<input type="button" data-localized-value="applyAllWindows" value="Apply (all windows)" data-localized-title="applyAllWindowsTitle" title="Set this user-agent string as the browser's User-Agent string" data-cmd="apply">
|
||||
</div>
|
||||
<script src="index.js"></script>
|
||||
<script async src="matched.js"></script>
|
||||
|
|
|
@ -1,5 +1,22 @@
|
|||
'use strict';
|
||||
|
||||
// localization
|
||||
document.querySelectorAll('[data-localized-value]').forEach(e => {
|
||||
const ref = e.dataset.localizedValue;
|
||||
const translated = chrome.i18n.getMessage(ref);
|
||||
if (translated) {
|
||||
e.value = translated;
|
||||
}
|
||||
});
|
||||
|
||||
document.querySelectorAll('[data-localized-title]').forEach(e => {
|
||||
const ref = e.dataset.localizedTitle;
|
||||
const translated = chrome.i18n.getMessage(ref);
|
||||
if (translated) {
|
||||
e.title = translated;
|
||||
}
|
||||
});
|
||||
|
||||
const DCSI = 'firefox-default';
|
||||
|
||||
document.body.dataset.android = navigator.userAgent.indexOf('Android') !== -1;
|
||||
|
@ -14,16 +31,16 @@ chrome.tabs.query({
|
|||
tab = tbs[0];
|
||||
if ('cookieStoreId' in tab) {
|
||||
const apply = document.querySelector('[data-cmd="apply"]');
|
||||
apply.value = 'Apply (container)';
|
||||
apply.title = 'Set this user-agent string as the current container\'s User-Agent string';
|
||||
apply.value = chrome.i18n.getMessage('applyContainer');
|
||||
apply.title = chrome.i18n.getMessage('applyContainerTitle');
|
||||
|
||||
const w = document.querySelector('[data-cmd="window"]');
|
||||
w.value = 'Apply (container on window)';
|
||||
w.title = 'Set this user-agent string for all tabs inside the current window\'s container';
|
||||
w.value = chrome.i18n.getMessage('applyContainerWindow');
|
||||
w.title = chrome.i18n.getMessage('applyContainerWindowTitle');
|
||||
|
||||
const reset = document.querySelector('[data-cmd="reset"]');
|
||||
reset.value = 'Reset (container)';
|
||||
reset.title = 'Reset the container\'s user-agent string to the default one. This will not reset window-based UA strings. To reset them, use the \'Restart\' button';
|
||||
reset.value = chrome.i18n.getMessage('resetContainer');
|
||||
reset.title = chrome.i18n.getMessage('resetContainerTitle');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -251,10 +268,10 @@ document.addEventListener('click', ({target}) => {
|
|||
if (cmd === 'apply') {
|
||||
const value = document.getElementById('ua').value;
|
||||
if (value === navigator.userAgent) {
|
||||
msg('Default UA, press the reset button instead');
|
||||
msg(chrome.i18n.getMessage('msgDefaultUA'));
|
||||
}
|
||||
else {
|
||||
msg('User-Agent is Set');
|
||||
msg(chrome.i18n.getMessage('msgUASet'));
|
||||
}
|
||||
if (value !== navigator.userAgent) {
|
||||
// prevent a container ua string from overwriting the default one
|
||||
|
@ -296,13 +313,13 @@ document.addEventListener('click', ({target}) => {
|
|||
chrome.storage.local.set(prefs);
|
||||
});
|
||||
|
||||
msg('Disabled on this container. Uses the default user-agent string');
|
||||
msg(chrome.i18n.getMessage('msgDisabledOnContainer'));
|
||||
}
|
||||
else {
|
||||
chrome.storage.local.set({
|
||||
ua: ''
|
||||
});
|
||||
msg('Disabled. Uses the default user-agent string');
|
||||
msg(chrome.i18n.getMessage('msgDisabled'));
|
||||
}
|
||||
}
|
||||
else if (cmd === 'refresh') {
|
||||
|
@ -357,7 +374,7 @@ document.getElementById('ua').addEventListener('keyup', e => {
|
|||
});
|
||||
|
||||
/* container support */
|
||||
document.querySelector('[data-cmd="container"]').addEventListener('click', e => {
|
||||
document.querySelector('[data-cmd="container"]').addEventListener('click', () => {
|
||||
chrome.permissions.request({
|
||||
permissions: ['cookies']
|
||||
}, granted => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue