├── .gitignore ├── README.md ├── background.js ├── popup.js ├── icon.svg ├── manifest.json ├── LICENSE └── popup.html /.gitignore: -------------------------------------------------------------------------------- 1 | web-ext-artifacts/ 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Quick Accept-Language Switcher 2 | 3 | Provides a quick way of changing the HTTP Accept-Language header so you can view and test websites with a different locale. 4 | 5 | Released under the terms of the [MIT license](https://opensource.org/licenses/MIT). 6 | -------------------------------------------------------------------------------- /background.js: -------------------------------------------------------------------------------- 1 | let locale = ""; 2 | 3 | chrome.webRequest.onBeforeSendHeaders.addListener( 4 | details => { 5 | if (locale) { 6 | for (var header of details.requestHeaders) { 7 | if (header.name.toLowerCase() == "accept-language") { 8 | header.value = locale; 9 | } 10 | } 11 | } 12 | return { requestHeaders: details.requestHeaders }; 13 | }, 14 | { urls: ["http://*/*", "https://*/*"] }, 15 | [ "blocking", "requestHeaders" ] 16 | ); 17 | 18 | function setLocaleString(s) { 19 | locale = s.trim(); 20 | } 21 | 22 | function getLocaleString() { 23 | return locale; 24 | } 25 | -------------------------------------------------------------------------------- /popup.js: -------------------------------------------------------------------------------- 1 | { 2 | let input = document.getElementById('locale-input'); 3 | 4 | let backgroundPage = chrome.extension.getBackgroundPage(); 5 | 6 | let updateBadge = (text) => { 7 | let label = /[^-,]*/.exec(text.trim())[0].toLowerCase(); 8 | chrome.browserAction.setBadgeText( { text: label }); 9 | } 10 | 11 | input.value = backgroundPage.getLocaleString(); 12 | 13 | input.select(); 14 | 15 | input.addEventListener('input', e => { 16 | updateBadge(e.target.value) 17 | }); 18 | 19 | input.addEventListener('input', e => { 20 | backgroundPage.setLocaleString(e.target.value); 21 | }); 22 | 23 | input.addEventListener('keydown', e => { 24 | if (e.key === "Enter") { window.close(); } 25 | }); 26 | } 27 | -------------------------------------------------------------------------------- /icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "Provides a quick way of changing the HTTP Accept-Language header so you can view and test websites with a different locale.", 3 | "manifest_version": 2, 4 | "name": "Quick Accept-Language Switcher", 5 | "version": "1.1", 6 | "homepage_url": "https://github.com/callahad/quick-accept-language-switcher", 7 | "icons": { 8 | "128": "icon.svg" 9 | }, 10 | 11 | "applications": { 12 | "gecko": { 13 | "id": "jid0-NcwayVfS7QQXyCTUSrues9dvdMs@jetpack", 14 | "strict_min_version": "45.0" 15 | } 16 | }, 17 | 18 | "permissions": [ 19 | "webRequest", "webRequestBlocking", "http://*/*", "https://*/*" 20 | ], 21 | 22 | "background": { 23 | "scripts": ["background.js"] 24 | }, 25 | 26 | "browser_action": { 27 | "default_icon": "icon.svg", 28 | "default_title": "Change Accept-Language header", 29 | "default_popup": "popup.html" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2016, Dan Callahan 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | the Software, and to permit persons to whom the Software is furnished to do so, 9 | subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /popup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Quick Accept-Language Switcher 6 | 14 | 15 | 16 | 17 | Accept-Language: 18 | 19 | 20 | 290 | 291 | 292 | --------------------------------------------------------------------------------