Skip to content

Added random select button. #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions v3/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@
"testUATitle": {
"message": "Test your user-agent string"
},
"considerContainers": {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This removal is irrelevant to the merge request.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting was done by vscode. Also some changes may have been mistake from my side sorry for that

"message": "Consider Containers"
"selectRandom": {
"message": "Select Random"
},
"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."
"selectRandomTitle": {
"message": "Select a random User-Agent."
},
"applyActiveTab": {
"message": "Apply (this tab)"
Expand Down
8 changes: 4 additions & 4 deletions v3/_locales/ru/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@
"testUATitle": {
"message": "Тестировать вашу строку User-Agent"
},
"considerContainers": {
"message": "Учитывать контейнеры"
"selectRandom": {
"message": "Выбрать случайный"
},
"considerContainersTitle": {
"message": "Позволять расширению иметь доступ к контейнерам вашего браузера. При наличии доступа вкладки внутри изолированных контейнеров не используют строку User-Agent контейнера по умолчанию. Вам нужно устанавливать эту строку для каждого нового контейнера."
"selectRandomTitle": {
"message": "Выберите случайный пользовательский агент."
},
"applyActiveWindow": {
"message": "Применить (активное окно)"
Expand Down
19 changes: 18 additions & 1 deletion v3/data/popup/browsers/android browser-windows.json
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
[{"ua":"Mozilla/5.0 (Windows; U; Windows CE; Mobile; like Android; ko-kr) AppleWebKit/533.3 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.3 Dorothy","browser":{"name":"Android Browser","version":"4.0","major":"4"},"engine":{"name":"WebKit","version":"533.3"},"os":{"name":"Windows","version":"CE"},"device":{"type":"mobile"},"cpu":{}},{"ua":"Mozilla/5.0 (Android 2.2; Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.19.4 (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4","browser":{"name":"Android Browser","version":"5.0.3","major":"5"},"engine":{"name":"WebKit","version":"533.19.4"},"os":{"name":"Windows","version":"7"},"device":{"model":"en-US","type":"tablet"},"cpu":{}}]
[
{
"ua": "Mozilla/5.0 (Windows; U; Windows CE; Mobile; like Android; ko-kr) AppleWebKit/533.3 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.3 Dorothy",
"browser": { "name": "Android Browser", "version": "4.0", "major": "4" },
"engine": { "name": "WebKit", "version": "533.3" },
"os": { "name": "Windows", "version": "CE" },
"device": { "type": "mobile" },
"cpu": {}
},
{
"ua": "Mozilla/5.0 (Android 2.2; Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.19.4 (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4",
"browser": { "name": "Android Browser", "version": "5.0.3", "major": "5" },
"engine": { "name": "WebKit", "version": "533.19.4" },
"os": { "name": "Windows", "version": "7" },
"device": { "model": "en-US", "type": "tablet" },
"cpu": {}
}
]
123 changes: 122 additions & 1 deletion v3/data/popup/browsers/arora-windows.json
Original file line number Diff line number Diff line change
@@ -1 +1,122 @@
[{"ua":"Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.6 (Change: )","browser":{"name":"Arora","version":"0.6","major":"0"},"engine":{"name":"WebKit","version":"527"},"os":{"name":"Windows","version":"Vista"},"device":{},"cpu":{}},{"ua":"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.6 (Change: )","browser":{"name":"Arora","version":"0.6","major":"0"},"engine":{"name":"WebKit","version":"527"},"os":{"name":"Windows","version":"XP"},"device":{},"cpu":{}},{"ua":"Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.4 (Change: )","browser":{"name":"Arora","version":"0.4","major":"0"},"engine":{"name":"WebKit","version":"527"},"os":{"name":"Windows","version":"Vista"},"device":{},"cpu":{}},{"ua":"Mozilla/5.0 (Windows; U; Windows NT 6.0; de-DE) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.4 (Change: )","browser":{"name":"Arora","version":"0.4","major":"0"},"engine":{"name":"WebKit","version":"527"},"os":{"name":"Windows","version":"Vista"},"device":{},"cpu":{}},{"ua":"Mozilla/5.0 (Windows; U; Windows NT 5.2; pt-BR) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.4 (Change: )","browser":{"name":"Arora","version":"0.4","major":"0"},"engine":{"name":"WebKit","version":"527"},"os":{"name":"Windows","version":"XP"},"device":{},"cpu":{}},{"ua":"Mozilla/5.0 (Windows; U; Windows NT 5.1; de-DE) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.4 (Change: )","browser":{"name":"Arora","version":"0.4","major":"0"},"engine":{"name":"WebKit","version":"527"},"os":{"name":"Windows","version":"XP"},"device":{},"cpu":{}},{"ua":"Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.3 (Change: 287 c9dfb30)","browser":{"name":"Arora","version":"0.3","major":"0"},"engine":{"name":"WebKit","version":"523.15"},"os":{"name":"Windows","version":"XP"},"device":{},"cpu":{}},{"ua":"Mozilla/5.0 (Windows; U; Windows NT 5.1; fr-BE) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.3 (Change: 287 c9dfb30)","browser":{"name":"Arora","version":"0.3","major":"0"},"engine":{"name":"WebKit","version":"523.15"},"os":{"name":"Windows","version":"XP"},"device":{},"cpu":{}},{"ua":"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.3 (Change: 287 c9dfb30)","browser":{"name":"Arora","version":"0.3","major":"0"},"engine":{"name":"WebKit","version":"523.15"},"os":{"name":"Windows","version":"XP"},"device":{},"cpu":{}},{"ua":"Mozilla/5.0 (Windows; U; Windows NT 6.0; de-DE) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.2","browser":{"name":"Arora","version":"0.2","major":"0"},"engine":{"name":"WebKit","version":"523.15"},"os":{"name":"Windows","version":"Vista"},"device":{},"cpu":{}},{"ua":"Mozilla/5.0 (Windows; U; Windows NT 5.1; nl-NL) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.2","browser":{"name":"Arora","version":"0.2","major":"0"},"engine":{"name":"WebKit","version":"523.15"},"os":{"name":"Windows","version":"XP"},"device":{},"cpu":{}},{"ua":"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.2","browser":{"name":"Arora","version":"0.2","major":"0"},"engine":{"name":"WebKit","version":"523.15"},"os":{"name":"Windows","version":"XP"},"device":{},"cpu":{}},{"ua":"Mozilla/5.0 (Windows; U; Windows NT 5.1; de-CH) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.2","browser":{"name":"Arora","version":"0.2","major":"0"},"engine":{"name":"WebKit","version":"523.15"},"os":{"name":"Windows","version":"XP"},"device":{},"cpu":{}},{"ua":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.34 (KHTML, like Gecko) Arora/0.11.0 Safari/534.34","browser":{"name":"Arora","version":"0.11.0","major":"0"},"engine":{"name":"WebKit","version":"534.34"},"os":{"name":"Windows","version":"7"},"device":{},"cpu":{"architecture":"amd64"}},{"ua":"Mozilla/5.0 (Windows; U; Windows NT 6.0; en-MY) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.10.0","browser":{"name":"Arora","version":"0.10.0","major":"0"},"engine":{"name":"WebKit","version":"527"},"os":{"name":"Windows","version":"Vista"},"device":{},"cpu":{}}]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These JSON files are created by an script. Do not modify them.

[
{
"ua": "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.6 (Change: )",
"browser": { "name": "Arora", "version": "0.6", "major": "0" },
"engine": { "name": "WebKit", "version": "527" },
"os": { "name": "Windows", "version": "Vista" },
"device": {},
"cpu": {}
},
{
"ua": "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.6 (Change: )",
"browser": { "name": "Arora", "version": "0.6", "major": "0" },
"engine": { "name": "WebKit", "version": "527" },
"os": { "name": "Windows", "version": "XP" },
"device": {},
"cpu": {}
},
{
"ua": "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.4 (Change: )",
"browser": { "name": "Arora", "version": "0.4", "major": "0" },
"engine": { "name": "WebKit", "version": "527" },
"os": { "name": "Windows", "version": "Vista" },
"device": {},
"cpu": {}
},
{
"ua": "Mozilla/5.0 (Windows; U; Windows NT 6.0; de-DE) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.4 (Change: )",
"browser": { "name": "Arora", "version": "0.4", "major": "0" },
"engine": { "name": "WebKit", "version": "527" },
"os": { "name": "Windows", "version": "Vista" },
"device": {},
"cpu": {}
},
{
"ua": "Mozilla/5.0 (Windows; U; Windows NT 5.2; pt-BR) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.4 (Change: )",
"browser": { "name": "Arora", "version": "0.4", "major": "0" },
"engine": { "name": "WebKit", "version": "527" },
"os": { "name": "Windows", "version": "XP" },
"device": {},
"cpu": {}
},
{
"ua": "Mozilla/5.0 (Windows; U; Windows NT 5.1; de-DE) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.4 (Change: )",
"browser": { "name": "Arora", "version": "0.4", "major": "0" },
"engine": { "name": "WebKit", "version": "527" },
"os": { "name": "Windows", "version": "XP" },
"device": {},
"cpu": {}
},
{
"ua": "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.3 (Change: 287 c9dfb30)",
"browser": { "name": "Arora", "version": "0.3", "major": "0" },
"engine": { "name": "WebKit", "version": "523.15" },
"os": { "name": "Windows", "version": "XP" },
"device": {},
"cpu": {}
},
{
"ua": "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr-BE) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.3 (Change: 287 c9dfb30)",
"browser": { "name": "Arora", "version": "0.3", "major": "0" },
"engine": { "name": "WebKit", "version": "523.15" },
"os": { "name": "Windows", "version": "XP" },
"device": {},
"cpu": {}
},
{
"ua": "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.3 (Change: 287 c9dfb30)",
"browser": { "name": "Arora", "version": "0.3", "major": "0" },
"engine": { "name": "WebKit", "version": "523.15" },
"os": { "name": "Windows", "version": "XP" },
"device": {},
"cpu": {}
},
{
"ua": "Mozilla/5.0 (Windows; U; Windows NT 6.0; de-DE) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.2",
"browser": { "name": "Arora", "version": "0.2", "major": "0" },
"engine": { "name": "WebKit", "version": "523.15" },
"os": { "name": "Windows", "version": "Vista" },
"device": {},
"cpu": {}
},
{
"ua": "Mozilla/5.0 (Windows; U; Windows NT 5.1; nl-NL) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.2",
"browser": { "name": "Arora", "version": "0.2", "major": "0" },
"engine": { "name": "WebKit", "version": "523.15" },
"os": { "name": "Windows", "version": "XP" },
"device": {},
"cpu": {}
},
{
"ua": "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.2",
"browser": { "name": "Arora", "version": "0.2", "major": "0" },
"engine": { "name": "WebKit", "version": "523.15" },
"os": { "name": "Windows", "version": "XP" },
"device": {},
"cpu": {}
},
{
"ua": "Mozilla/5.0 (Windows; U; Windows NT 5.1; de-CH) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.2",
"browser": { "name": "Arora", "version": "0.2", "major": "0" },
"engine": { "name": "WebKit", "version": "523.15" },
"os": { "name": "Windows", "version": "XP" },
"device": {},
"cpu": {}
},
{
"ua": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.34 (KHTML, like Gecko) Arora/0.11.0 Safari/534.34",
"browser": { "name": "Arora", "version": "0.11.0", "major": "0" },
"engine": { "name": "WebKit", "version": "534.34" },
"os": { "name": "Windows", "version": "7" },
"device": {},
"cpu": { "architecture": "amd64" }
},
{
"ua": "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-MY) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.10.0",
"browser": { "name": "Arora", "version": "0.10.0", "major": "0" },
"engine": { "name": "WebKit", "version": "527" },
"os": { "name": "Windows", "version": "Vista" },
"device": {},
"cpu": {}
}
]
2 changes: 1 addition & 1 deletion v3/data/popup/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
<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 tab-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-title="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="selectRandom" value="Select Random" data-localized-title="selectRandomTitle" title="Select a random User-Agent." data-cmd="random">
<input type="button" data-localized-value="applyActiveTab" value="Apply (this tab)" data-localized-title="applyActiveTabTitle" title="Set this user-agent string for the current tab" data-cmd="tab">
<input type="button" data-localized-value="applyAllWindows" value="Apply (all tabs)" data-localized-title="applyAllWindowsTitle" title="Set this user-agent string as the browser's User-Agent string" data-cmd="apply">
</div>
Expand Down
51 changes: 45 additions & 6 deletions v3/data/popup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ function update(ua) {
else {
throw Error('OS is not found');
}
// FF 55.0 does not support finally
}).catch(() => {}).then(() => {
// FF 55.0 does not support finally
}).catch(() => { }).then(() => {
parent.dataset.loading = false;
});
}
Expand All @@ -203,7 +203,7 @@ document.getElementById('sort').addEventListener('change', e => chrome.storage.l
'popup-sort': e.target.value
}));

document.addEventListener('change', ({target}) => {
document.addEventListener('change', ({ target }) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not change formatting of files.

if (target.closest('#filter')) {
chrome.storage.local.get({
ua: ''
Expand Down Expand Up @@ -250,7 +250,7 @@ document.addEventListener('DOMContentLoaded', () => fetch('./map.json').then(r =
});
}));

document.getElementById('list').addEventListener('click', ({target}) => {
document.getElementById('list').addEventListener('click', ({ target }) => {
const tr = target.closest('tbody tr');
if (tr) {
const input = tr.querySelector('input');
Expand All @@ -263,7 +263,7 @@ document.getElementById('list').addEventListener('click', ({target}) => {
}
});

document.getElementById('custom').addEventListener('keyup', ({target}) => {
document.getElementById('custom').addEventListener('keyup', ({ target }) => {
const value = target.value;
[...document.querySelectorAll('#list tbody tr')]
.forEach(tr => tr.dataset.matched = tr.textContent.toLowerCase().indexOf(value.toLowerCase()) !== -1);
Expand All @@ -281,9 +281,37 @@ function msg(msg) {
toast.textContent = msg;
window.setTimeout(() => toast.textContent = '', 2000);
}
// get random elements
function getRandomElement(array) {
console.log(array);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the debugging logs.

return array[Math.floor(Math.random() * array.length)];
}

// gets random browser and os
function getRandomBrowserAndOS() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The random UA, must be selected from well-known OS and browsers. Selecting a random OS breaks many websites.

return fetch('./map.json')
.then(response => response.json())
.then(map => {
const randomBrowser = getRandomElement(map.browser);
console.log(randomBrowser);
const randomOS = getRandomElement(map.matching[randomBrowser.toLowerCase()]);
return { randomBrowser, randomOS };
});
}

// getRandomUserAgent: uses random browser and os to get random user agent
function getRandomUserAgent() {
return getRandomBrowserAndOS().then(({ randomBrowser, randomOS }) => {
const path = `browsers/${randomBrowser.toLowerCase()}-${randomOS.toLowerCase().replace(/\//g, '-')}.json`;
return get(path).then(response => response.json()).then(list => {
const randomUserAgent = getRandomElement(list);
return randomUserAgent;
});
});
}

// commands
document.addEventListener('click', ({target}) => {
document.addEventListener('click', ({ target }) => {
const cmd = target.dataset.cmd;
if (cmd) {
if (cmd === 'apply') {
Expand Down Expand Up @@ -325,6 +353,17 @@ document.addEventListener('click', ({target}) => {
}
});
}
else if (cmd === 'random') {
getRandomUserAgent().then(randomUA => {
document.getElementById('ua').value = randomUA.ua;
document.getElementById('browser').value = randomUA.browser.name;
document.getElementById('os').value = randomUA.os.name;
document.getElementById('ua').dispatchEvent(new Event('input'));

// document.getElementById('sort').value = randomUA['popup-sort'];
msg(chrome.i18n.getMessage('msgRandomUASet'));
});
}
else if (cmd === 'reset') {
const input = document.querySelector('#list :checked');
if (input) {
Expand Down
Loading