Add locale support part 2

This commit is contained in:
Ray Lothian 2020-09-27 08:54:02 +02:00
parent b75902d620
commit c42258beb3
6 changed files with 248 additions and 112 deletions

View file

@ -8,91 +8,183 @@
"description": "Description of the extension." "description": "Description of the extension."
}, },
"testUA": { "testUA": {
"message": "Test UA", "message": "Test UA"
"description": ""
}, },
"userAgentSwitcherandManagerOptions": { "userAgentSwitcherandManagerOptions": {
"message": "User-Agent Switcher and Manager :: Options", "message": "User-Agent Switcher and Manager :: Options"
"description": ""
}, },
"blackListMode": { "blackListMode": {
"message": "Black-List Mode", "message": "Black-List Mode"
"description": ""
}, },
"description": { "description": {
"message": "Description", "message": "Description"
"description": ""
}, },
"blackListModeDescription": { "blackListModeDescription": {
"message": "Apply the custom user-agent string to all tabs except the tabs with the following top-level hostnames (comma-separated list of hostnames). Note that even if a window-based user-agent string is set from the toolbar popup, your browser's default user-agent string is used.", "message": "Apply the custom user-agent string to all tabs except the tabs with the following top-level hostnames (comma-separated list of hostnames). Note that even if a window-based user-agent string is set from the toolbar popup, your browser's default user-agent string is used."
"description": ""
}, },
"whiteListMode": { "whiteListMode": {
"message": "White-List Mode", "message": "White-List Mode"
"description": ""
}, },
"whiteListModeDescription": { "whiteListModeDescription": {
"message": "Only apply the custom user-agent string to the tabs with following top-level hostnames. Note that if a window-based user-agent string is set from the toolbar popup, this user-agent will overwrite the global one.", "message": "Only apply the custom user-agent string to the tabs with following top-level hostnames. Note that if a window-based user-agent string is set from the toolbar popup, this user-agent will overwrite the global one."
"description": ""
}, },
"customMode": { "customMode": {
"message": "Custom Mode", "message": "Custom Mode"
"description": "" },
"customModeDescription": {
"message": "Try to resolve the user-agent string from a JSON object; otherwise either use the default user-agent string or use the one that the user is set from the popup interface. Use \"*\" as the hostname to match all domains. You can randomly select from multiple user-agent strings by providing an array instead of a fixed string. If there is a \"_\" key in your JSON object which refers to an array of hostnames, then the extension only randomly selects the user-agent string once for each hostname inside this list. This is useful if you don't want the random user-agent to change until this browser session is over."
},
"insertSample": {
"message": "Insert a sample"
}, },
"cache": { "cache": {
"message": "Use caching to improve performance (recommended value is true). Uncheck this option only if you are using the custom mode and also you need the user-agent string to be altered from the provided list on every single request.", "message": "Use caching to improve performance (recommended value is true). Uncheck this option only if you are using the custom mode and also you need the user-agent string to be altered from the provided list on every single request."
"description": ""
}, },
"exactMatch": { "exactMatch": {
"message": "Use exact matching (if checked, you will need to insert all sub-domains in the white-list and black-list modes to be considered. If unchecked, all the sub-domains are passing the matching condition (e.g: www.google.com passes the matching if google.com is in the list))", "message": "Use exact matching (if checked, you will need to insert all sub-domains in the white-list and black-list modes to be considered. If unchecked, all the sub-domains are passing the matching condition (e.g: www.google.com passes the matching if google.com is in the list))"
"description": ""
}, },
"faqs": { "faqs": {
"message": "Open FAQs page on updates", "message": "Open FAQs page on updates"
"description": ""
}, },
"log": { "log": {
"message": "Display debugging info in the browser console", "message": "Display debugging info in the browser console"
"description": ""
}, },
"disableSpoofing": { "disableSpoofing": {
"message": "Disable Spoofing", "message": "Disable Spoofing"
"description": ""
}, },
"disableSpoofingDescription": { "disableSpoofingDescription": {
"message": "A comma-separated list of keywords that the extension should not spoof the user-agent header. Use this list to protect URLs that contain these protected keywords. Each keyword need to be at least 5 char long.", "message": "A comma-separated list of keywords that the extension should not spoof the user-agent header. Use this list to protect URLs that contain these protected keywords. Each keyword need to be at least 5 char long."
"description": ""
}, },
"customUserAgentParsing": { "customUserAgentParsing": {
"message": "Custom User-Agent Parsing", "message": "Custom User-Agent Parsing"
"description": "" },
"customUserAgentParsingDescription": {
"message": "A JSON object to bypass the internal user-agent string parsing method. The keys are the actual user-agent strings and the value of each key is an object of the keys that need to be set for the \"navigator\" object. You can use the \"[delete]\" keyword if you want a key in the \"navigator\" object to get deleted."
}, },
"siblingHostnames": { "siblingHostnames": {
"message": "Sibling Hostnames", "message": "Sibling Hostnames"
"description": "" },
"siblingHostnamesDescription": {
"message": "A JSON array that contains one or more groups of hostnames to have a single user-agent string per group. For all hostnames in one group, the user-agent string calculation only occurs once, and all the other members use the same calculated string. This is useful to make sure a group of connected websites only access to the same user-agent string."
}, },
"importSettings": { "importSettings": {
"message": "Import Settings", "message": "Import Settings"
"description": ""
}, },
"exportSettings": { "exportSettings": {
"message": "Export Settings", "message": "Export Settings"
"description": ""
}, },
"help": { "help": {
"message": "FAQs Page (Help)", "message": "FAQs Page (Help)"
"description": ""
}, },
"donate": { "donate": {
"message": "Support Development", "message": "Support Development"
"description": ""
}, },
"reset": { "reset": {
"message": "Reset", "message": "Reset"
"description": ""
}, },
"save": { "save": {
"message": "Save", "message": "Save"
"description": "" },
"managedStorage": {
"message": "This extension supports managed storage so that preferences can be altered automatically or can be pre-configured by a domain administrator. Read the FAQs page for more info."
},
"options": {
"message": "Options"
},
"optionsTitle": {
"message": "Open options page"
},
"restart": {
"message": "Restart"
},
"restartTitle": {
"message": "Click to reload the extension. This will cause all the window-based user-agent strings to be cleared"
},
"refreshTab": {
"message": "Refresh Tab"
},
"refreshTabTitle": {
"message": "Refresh the current page"
},
"reset": {
"message": "Reset"
},
"resetTitle": {
"message": "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"
},
"testUA": {
"message": "Test UA"
},
"testUATitle": {
"message": "Test your user-agent string"
},
"considerContainers": {
"message": "Consider Containers"
},
"considerContainersTitle": {
"message": "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."
},
"applyActiveWindow": {
"message": "Apply (active window)"
},
"applyActiveWindowTitle": {
"message": "Set this user-agent string for all tabs inside the current window"
},
"applyAllWindows": {
"message": "Apply (all windows)"
},
"applyAllWindowsTitle": {
"message": "Set this user-agent string as the browser's User-Agent string"
},
"applyContainer": {
"message": "Apply (container)"
},
"applyContainerTitle": {
"message": "Set this user-agent string as the current container's User-Agent string"
},
"applyContainerWindow": {
"message": "Apply (container on window)"
},
"applyContainerWindowTitle": {
"message": "Set this user-agent string for all tabs inside the current window's container"
},
"resetContainer": {
"message": "Reset (container)"
},
"resetContainerTitle": {
"message": "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"
},
"oscpuTitle": {
"message": "This is a readonly field. Use options page for custom parsing."
},
"appVersionTitle": {
"message": "This is a readonly field. Use options page for custom parsing."
},
"platformTitle": {
"message": "This is a readonly field. Use options page for custom parsing."
},
"vendorTitle": {
"message": "This is a readonly field. Use options page for custom parsing."
},
"productTitle": {
"message": "This is a readonly field. Use options page for custom parsing."
},
"uaTitle": {
"message": "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'"
},
"uaPlaceholder": {
"message": "Your preferred user-agent string"
},
"msgDefaultUA": {
"message": "Default UA, press the reset button instead"
},
"msgUASet": {
"message": "User-Agent is Set"
},
"msgDisabledOnContainer": {
"message": "Disabled on this container. Uses the default user-agent string"
},
"msgDisabled": {
"message": "Disabled. Uses the default user-agent string"
} }
} }

View file

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title data-localize="__MSG_userAgentSwitcherandManagerOptions__">User-Agent Switcher and Manager :: Options</title> <title data-localize="userAgentSwitcherandManagerOptions">User-Agent Switcher and Manager :: Options</title>
<link rel="stylesheet" type="text/css" href="index.css"> <link rel="stylesheet" type="text/css" href="index.css">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
</head> </head>
@ -9,70 +9,70 @@
<body> <body>
<div class="mode"> <div class="mode">
<input type="radio" name="mode" value="blacklist" id="mode-blacklist"> <input type="radio" name="mode" value="blacklist" id="mode-blacklist">
<label for="mode-blacklist"><h1 data-localize="__MSG_blackListMode__">Black-List Mode</h1></label> <label for="mode-blacklist"><h1 data-localize="blackListMode">Black-List Mode</h1></label>
<span id="toggle-blacklist-desc" data-localize="__MSG_description__">Description</span> <span id="toggle-blacklist-desc" data-localize="description">Description</span>
</div> </div>
<p for="toggle-blacklist-desc" class="note hidden" data-localize="__MSG_blackListModeDescription__">Apply the custom user-agent string to all tabs except the tabs with the following top-level hostnames (comma-separated list of hostnames). Note that even if a window-based user-agent string is set from the toolbar popup, your browser's default user-agent string is used.</p> <p for="toggle-blacklist-desc" class="note hidden" data-localize="blackListModeDescription">Apply the custom user-agent string to all tabs except the tabs with the following top-level hostnames (comma-separated list of hostnames). Note that even if a window-based user-agent string is set from the toolbar popup, your browser's default user-agent string is used.</p>
<textarea id="blacklist" rows="3" placeholder="e.g.: www.google.com, www.bing.com"></textarea> <textarea id="blacklist" rows="3" placeholder="e.g.: www.google.com, www.bing.com"></textarea>
<div class="mode"> <div class="mode">
<input type="radio" name="mode" value="whitelist" id="mode-whitelist"> <input type="radio" name="mode" value="whitelist" id="mode-whitelist">
<label for="mode-whitelist"><h1 data-localize="__MSG_whiteListMode__">White-List Mode</h1></label> <label for="mode-whitelist"><h1 data-localize="whiteListMode">White-List Mode</h1></label>
<span id="toggle-whitelist-desc" data-localize="__MSG_description__">Description</span> <span id="toggle-whitelist-desc" data-localize="description">Description</span>
</div> </div>
<p for="toggle-whitelist-desc" class="note hidden" data-localize="__MSG_whiteListModeDescription__">Only apply the custom user-agent string to the tabs with following top-level hostnames. Note that if a window-based user-agent string is set from the toolbar popup, this user-agent will overwrite the global one.</p> <p for="toggle-whitelist-desc" class="note hidden" data-localize="whiteListModeDescription">Only apply the custom user-agent string to the tabs with following top-level hostnames. Note that if a window-based user-agent string is set from the toolbar popup, this user-agent will overwrite the global one.</p>
<textarea id="whitelist" rows="3" placeholder="e.g.: www.google.com, www.bing.com"></textarea> <textarea id="whitelist" rows="3" placeholder="e.g.: www.google.com, www.bing.com"></textarea>
<div class="mode"> <div class="mode">
<input type="radio" name="mode" value="custom" id="mode-custom"> <input type="radio" name="mode" value="custom" id="mode-custom">
<label for="mode-custom"><h1 data-localize="__MSG_customMode__">Custom Mode</h1></label> <label for="mode-custom"><h1 data-localize="customMode">Custom Mode</h1></label>
<span id="toggle-custom-desc" data-localize="__MSG_description__">Description</span> <span id="toggle-custom-desc" data-localize="description">Description</span>
</div> </div>
<p for="toggle-custom-desc" class="note hidden" data-localize="__MSG_customModeDescription__">Try to resolve the user-agent string from a JSON object; otherwise either use the default user-agent string or use the one that the user is set from the popup interface. Use "*" as the hostname to match all domains. You can randomly select from multiple user-agent strings by providing an array instead of a fixed string. If there is a "_" key in your JSON object which refers to an array of hostnames, then the extension only randomly selects the user-agent string once for each hostname inside this list. This is useful if you don't want the random user-agent to change until this browser session is over.</label> Press <a href="#" id="sample">here</a> to insert a sample JSON object.</p> <p for="toggle-custom-desc" class="note hidden"><span data-localize="customModeDescription">Try to resolve the user-agent string from a JSON object; otherwise either use the default user-agent string or use the one that the user is set from the popup interface. Use "*" as the hostname to match all domains. You can randomly select from multiple user-agent strings by providing an array instead of a fixed string. If there is a "_" key in your JSON object which refers to an array of hostnames, then the extension only randomly selects the user-agent string once for each hostname inside this list. This is useful if you don't want the random user-agent to change until this browser session is over.</span> <a href="#" id="sample" data-localize="insertSample">Insert a sample</a>.</p>
<textarea id="custom" rows="8" wrap="off"></textarea> <textarea id="custom" rows="8" wrap="off"></textarea>
<div class="checked"> <div class="checked">
<input type="checkbox" id="cache"> <input type="checkbox" id="cache">
<label for="cache" data-localize="__MSG_cache__">Use caching to improve performance (recommended value is true). Uncheck this option only if you are using the custom mode and also you need the user-agent string to be altered from the provided list on every single request.</label> <label for="cache" data-localize="cache">Use caching to improve performance (recommended value is true). Uncheck this option only if you are using the custom mode and also you need the user-agent string to be altered from the provided list on every single request.</label>
<input type="checkbox" id="exactMatch"> <input type="checkbox" id="exactMatch">
<label for="exactMatch" data-localize="__MSG_exactMatch__">Use exact matching (if checked, you will need to insert all sub-domains in the white-list and black-list modes to be considered. If unchecked, all the sub-domains are passing the matching condition (e.g: www.google.com passes the matching if google.com is in the list))</label> <label for="exactMatch" data-localize="exactMatch">Use exact matching (if checked, you will need to insert all sub-domains in the white-list and black-list modes to be considered. If unchecked, all the sub-domains are passing the matching condition (e.g: www.google.com passes the matching if google.com is in the list))</label>
<input type="checkbox" id="faqs"> <input type="checkbox" id="faqs">
<label for="faqs" data-localize="__MSG_faqs__">Open FAQs page on updates</label> <label for="faqs" data-localize="faqs">Open FAQs page on updates</label>
<input type="checkbox" id="log"> <input type="checkbox" id="log">
<label for="log" data-localize="__MSG_log__">Display debugging info in the browser console</label> <label for="log" data-localize="log">Display debugging info in the browser console</label>
</div> </div>
<div class="mode-2"> <div class="mode-2">
<h1 data-localize="__MSG_disableSpoofing__">Disable Spoofing</h1> <h1 data-localize="disableSpoofing">Disable Spoofing</h1>
<span id="toggle-protected-desc" data-localize="__MSG_description__">Description</span> <span id="toggle-protected-desc" data-localize="description">Description</span>
</div> </div>
<p for="toggle-protected-desc" class="note hidden" data-localize="__MSG_disableSpoofingDescription__">A comma-separated list of keywords that the extension should not spoof the user-agent header. Use this list to protect URLs that contain these protected keywords. Each keyword need to be at least 5 char long.</p> <p for="toggle-protected-desc" class="note hidden" data-localize="disableSpoofingDescription">A comma-separated list of keywords that the extension should not spoof the user-agent header. Use this list to protect URLs that contain these protected keywords. Each keyword need to be at least 5 char long.</p>
<textarea id="protected" rows="3" wrap="off"></textarea> <textarea id="protected" rows="3" wrap="off"></textarea>
<div class="mode-2"> <div class="mode-2">
<h1 data-localize="__MSG_customUserAgentParsing__">Custom User-Agent Parsing</h1> <h1 data-localize="customUserAgentParsing">Custom User-Agent Parsing</h1>
<span id="toggle-parser-desc" data-localize="__MSG_description__">Description</span> <span id="toggle-parser-desc" data-localize="description">Description</span>
</div> </div>
<p for="toggle-parser-desc" class="note hidden" data-localize="__MSG_customUserAgentParsingDescription__">A JSON object to bypass the internal user-agent string parsing method. The keys are the actual user-agent strings and the value of each key is an object of the keys that need to be set for the "navigator" object. You can use the "[delete]" keyword if you want a key in the "navigator" object to get deleted. Press <a href="#" id="sample-2">here</a> to insert a sample JSON object.</p> <p for="toggle-parser-desc" class="note hidden"><span data-localize="customUserAgentParsingDescription">A JSON object to bypass the internal user-agent string parsing method. The keys are the actual user-agent strings and the value of each key is an object of the keys that need to be set for the "navigator" object. You can use the "[delete]" keyword if you want a key in the "navigator" object to get deleted.</span> <a href="#" id="sample-2" data-localize="insertSample">Insert a sample</a>.</p>
<textarea id="parser" rows="5" wrap="off"></textarea> <textarea id="parser" rows="5" wrap="off"></textarea>
<div class="mode-2"> <div class="mode-2">
<h1 data-localize="__MSG_siblingHostnames__">Sibling Hostnames</h1> <h1 data-localize="siblingHostnames">Sibling Hostnames</h1>
<span id="toggle-sibling-desc" data-localize="__MSG_description__">Description</span> <span id="toggle-sibling-desc" data-localize="description">Description</span>
</div> </div>
<p for="toggle-sibling-desc" class="note hidden" data-localize="__MSG_siblingHostnamesDescription__">A JSON array that contains one or more groups of hostnames to have a single user-agent string per group. For all hostnames in one group, the user-agent string calculation only occurs once, and all the other members use the same calculated string. This is useful to make sure a group of connected websites only access to the same user-agent string. Press <a href="#" id="sample-3">here</a> to insert a sample JSON array.</p> <p for="toggle-sibling-desc" class="note hidden"><span data-localize="siblingHostnamesDescription">A JSON array that contains one or more groups of hostnames to have a single user-agent string per group. For all hostnames in one group, the user-agent string calculation only occurs once, and all the other members use the same calculated string. This is useful to make sure a group of connected websites only access to the same user-agent string.</span> <a href="#" id="sample-3" data-localize="insertSample">Insert a sample</a></p>
<textarea id="siblings" rows="5" wrap="off"></textarea> <textarea id="siblings" rows="5" wrap="off"></textarea>
<div class="admin">This extension supports managed storage. All the preferences can be pre-configured by <a href="https://add0n.com/useragent-switcher.html#faq20">the domain administrator</a></div> <div class="admin" data-localize="managedStorage">This extension supports managed storage. All the preferences can be pre-configured by the domain administrator</div>
<div id="backup"> <div id="backup">
<button id="import" data-localize="__MSG_importSettings__">Import Settings</button> <button id="import" data-localize="importSettings">Import Settings</button>
<button title="to generate minified version, press Shift key while pressing this button" id="export" data-localize="__MSG_exportSettings__">Export Settings</button> <button title="to generate minified version, press Shift key while pressing this button" id="export" data-localize="exportSettings">Export Settings</button>
</div> </div>
<div id="tools"> <div id="tools">
<button id="help" data-localize="__MSG_help__">FAQs Page (Help)</button> <button id="help" data-localize="help">FAQs Page (Help)</button>
<button id="donate" data-localize="__MSG_donate__">Support Development</button> <button id="donate" data-localize="donate">Support Development</button>
<button id="reset" data-localize="__MSG_reset__">Reset</button> <button id="reset" data-localize="reset">Reset</button>
<button id="save" data-localize="__MSG_save__">Save</button> <button id="save" data-localize="save">Save</button>
<span id="status"></span> <span id="status"></span>
</div> </div>

View file

@ -1,5 +1,14 @@
'use strict'; 'use strict';
// localization
document.querySelectorAll('[data-localize]').forEach(e => {
const ref = e.dataset.localize;
const translated = chrome.i18n.getMessage(ref);
if (translated) {
e.textContent = translated;
}
});
function notify(msg, period = 750) { function notify(msg, period = 750) {
// Update status to let user know options were saved. // Update status to let user know options were saved.
const status = document.getElementById('status'); const status = document.getElementById('status');
@ -258,15 +267,3 @@ document.getElementById('toggle-parser-desc').addEventListener('click', () => {
document.getElementById('toggle-sibling-desc').addEventListener('click', () => { document.getElementById('toggle-sibling-desc').addEventListener('click', () => {
document.querySelector('[for="toggle-sibling-desc"]').classList.toggle('hidden'); document.querySelector('[for="toggle-sibling-desc"]').classList.toggle('hidden');
}); });
const textElements = document.querySelectorAll('[data-localize]');
textElements.forEach((e) => {
const ref = e.dataset.localize;
if (ref) {
const translated= ref.replace(/__MSG_(\w+)__/g, (match, theGroup) => chrome.i18n.getMessage(theGroup));
if (translated) {
e.innerText = translated;
}
}
});

View file

@ -78,7 +78,7 @@
<td>userAgent</td> <td>userAgent</td>
<td colspan="3"> <td colspan="3">
<div hbox> <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> </div>
</td> </td>
</tr> </tr>
@ -86,7 +86,7 @@
<td>appVersion</td> <td>appVersion</td>
<td colspan="3"> <td colspan="3">
<div hbox> <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> </div>
</td> </td>
</tr> </tr>
@ -94,13 +94,13 @@
<td>platform</td> <td>platform</td>
<td> <td>
<div hbox> <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> </div>
</td> </td>
<td>vendor</td> <td>vendor</td>
<td> <td>
<div hbox> <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> </div>
</td> </td>
</tr> </tr>
@ -108,13 +108,13 @@
<td>product</td> <td>product</td>
<td> <td>
<div hbox> <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> </div>
</td> </td>
<td>oscpu</td> <td>oscpu</td>
<td> <td>
<div hbox> <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> </div>
</td> </td>
</tr> </tr>
@ -122,14 +122,14 @@
</div> </div>
<div id="explore" data-cols=4></div> <div id="explore" data-cols=4></div>
<div 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" data-localized-value="options" value="Options" data-localized-title="optionsTitle" 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" 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" value="Refresh Tab" title="Refresh the current page" data-cmd="refresh"> <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" 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" 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" value="Test UA" title="Test your user-agent string" data-cmd="test"> <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" 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" 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" value="Apply (active window)" title="Set this user-agent string for all tabs inside the current window" data-cmd="window"> <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" 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="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> </div>
<script src="index.js"></script> <script src="index.js"></script>
<script async src="matched.js"></script> <script async src="matched.js"></script>

View file

@ -1,5 +1,22 @@
'use strict'; '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'; const DCSI = 'firefox-default';
document.body.dataset.android = navigator.userAgent.indexOf('Android') !== -1; document.body.dataset.android = navigator.userAgent.indexOf('Android') !== -1;
@ -14,16 +31,16 @@ chrome.tabs.query({
tab = tbs[0]; tab = tbs[0];
if ('cookieStoreId' in tab) { if ('cookieStoreId' in tab) {
const apply = document.querySelector('[data-cmd="apply"]'); const apply = document.querySelector('[data-cmd="apply"]');
apply.value = 'Apply (container)'; apply.value = chrome.i18n.getMessage('applyContainer');
apply.title = 'Set this user-agent string as the current container\'s User-Agent string'; apply.title = chrome.i18n.getMessage('applyContainerTitle');
const w = document.querySelector('[data-cmd="window"]'); const w = document.querySelector('[data-cmd="window"]');
w.value = 'Apply (container on window)'; w.value = chrome.i18n.getMessage('applyContainerWindow');
w.title = 'Set this user-agent string for all tabs inside the current window\'s container'; w.title = chrome.i18n.getMessage('applyContainerWindowTitle');
const reset = document.querySelector('[data-cmd="reset"]'); const reset = document.querySelector('[data-cmd="reset"]');
reset.value = 'Reset (container)'; reset.value = chrome.i18n.getMessage('resetContainer');
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.title = chrome.i18n.getMessage('resetContainerTitle');
} }
} }
}); });
@ -251,10 +268,10 @@ document.addEventListener('click', ({target}) => {
if (cmd === 'apply') { if (cmd === 'apply') {
const value = document.getElementById('ua').value; const value = document.getElementById('ua').value;
if (value === navigator.userAgent) { if (value === navigator.userAgent) {
msg('Default UA, press the reset button instead'); msg(chrome.i18n.getMessage('msgDefaultUA'));
} }
else { else {
msg('User-Agent is Set'); msg(chrome.i18n.getMessage('msgUASet'));
} }
if (value !== navigator.userAgent) { if (value !== navigator.userAgent) {
// prevent a container ua string from overwriting the default one // prevent a container ua string from overwriting the default one
@ -296,13 +313,13 @@ document.addEventListener('click', ({target}) => {
chrome.storage.local.set(prefs); chrome.storage.local.set(prefs);
}); });
msg('Disabled on this container. Uses the default user-agent string'); msg(chrome.i18n.getMessage('msgDisabledOnContainer'));
} }
else { else {
chrome.storage.local.set({ chrome.storage.local.set({
ua: '' ua: ''
}); });
msg('Disabled. Uses the default user-agent string'); msg(chrome.i18n.getMessage('msgDisabled'));
} }
} }
else if (cmd === 'refresh') { else if (cmd === 'refresh') {
@ -357,7 +374,7 @@ document.getElementById('ua').addEventListener('keyup', e => {
}); });
/* container support */ /* container support */
document.querySelector('[data-cmd="container"]').addEventListener('click', e => { document.querySelector('[data-cmd="container"]').addEventListener('click', () => {
chrome.permissions.request({ chrome.permissions.request({
permissions: ['cookies'] permissions: ['cookies']
}, granted => { }, granted => {

30
store/store.txt Normal file
View file

@ -0,0 +1,30 @@
Usage example: You can alter your user-agent string to indicate youre on a mobile device if you prefer seeing mobile versions of sites so they load quicker.
--
This extension allows you to spoof your browser "user-agent" string to a custom designation, making it impossible for websites to know specific details about your browsing arrangement.
Overview:
https://www.youtube.com/watch?v=4M6_Zc4o1MQ
Notes:
1. You can easily set custom "user-agent" strings from the toolbar popup
2. The extension uses a two-factor technique to mimic your default "user-agent" string, which is the most reliable method
3. The extension does not use any resources when it is not spoofing the user-agent
4. The extension enables user-agent spoofing on specific domains only; it is conversely possible to exclude certain domains from spoofing. Check the Options page for more info.
5. You can set per-site user-agent strings
6. There is an option to randomize user-agent strings.
7. It is possible to set the user-agent string for a single-window; you can have a separate user-agent string for each browser window
8. This extension supports managed storage so that preferences can be altered automatically or can be pre-configured by a domain administrator
Supported operating systems:
Windows, Mac OS, Linux, Chromium OS, Ubuntu, Debian, Android, iOS, AmigaOS, OpenBSD, BeOS, Haiku, Solaris, NetBSD, FreeBSD, Slackware, SUSE, gentoo, Fedora, Gentoo, Mageia, CentOS, Mint, DragonFly, Kubuntu, Mandriva, Zenwalk, Unix, GNU, OS/2, AIX, QNX, BEOS, RISC OS, Symbian, Nintendo, OpenSolaris, Kubuntu
Supported browsers:
Internet Explorer, Safari, Chrome, Firefox, Opera, Edge, WebKit, Avant, Maxthon, Arora, Mozilla, Epiphany, Camino, Chimera, Chromium, Dragon, conkeror, Conkeror, Dillo, Links, Firebird, Swiftfox, Netscape, Flock, iCab, Iceape, icecat, IceCat, IceWeasel, Iron, Meleon, Konqueror, Lunascape, Lynx, MAXTHON, midori, Midori, KHTML, Mosaic, NetSurf, OmniWeb, Tablet, Mini, Phoenix, RockMelt, Safari, Browser, SeaMonkey, Slim, Webkit, w3m
For more info and general bug reports please use:
https://add0n.com/useragent-switcher.html
For technical bug reports please use:
https://github.com/ray-lothian/UserAgent-Switcher/