feat: load challenge in English by default

pull/73/head
dessant 6 years ago
parent c32a6549eb
commit 3f581bda57

@ -129,6 +129,11 @@
"description": "Title of the options section."
},
"optionTitle_loadEnglishChallenge": {
"message": "Load challenge in English",
"description": "Title of the option."
},
"optionTitle_tryEnglishSpeechModel": {
"message": "Retry speech recognition with English model",
"description": "Title of the option."

@ -4,6 +4,43 @@ import {initStorage} from 'storage/init';
import storage from 'storage/storage';
import {showNotification, showContributePage} from 'utils/app';
function challengeRequestCallback(details) {
const url = new URL(details.url);
if (url.searchParams.get('hl') !== 'en') {
url.searchParams.set('hl', 'en');
return {redirectUrl: url.toString()};
}
}
async function setChallengeLocale() {
const {loadEnglishChallenge} = await storage.get(
'loadEnglishChallenge',
'sync'
);
if (loadEnglishChallenge) {
if (
!browser.webRequest.onBeforeRequest.hasListener(challengeRequestCallback)
) {
browser.webRequest.onBeforeRequest.addListener(
challengeRequestCallback,
{
urls: [
'https://www.google.com/recaptcha/api2/anchor*',
'https://www.google.com/recaptcha/api2/bframe*'
],
types: ['sub_frame']
},
['blocking']
);
}
} else if (
browser.webRequest.onBeforeRequest.hasListener(challengeRequestCallback)
) {
browser.webRequest.onBeforeRequest.removeListener(challengeRequestCallback);
}
}
async function onMessage(request, sender, sendResponse) {
if (request.id === 'notification') {
showNotification({
@ -12,26 +49,32 @@ async function onMessage(request, sender, sendResponse) {
title: request.title,
type: request.type
});
return;
}
if (request.id === 'captchaSolved') {
} else if (request.id === 'captchaSolved') {
let {useCount} = await storage.get('useCount', 'sync');
useCount += 1;
await storage.set({useCount}, 'sync');
if ([30, 100].includes(useCount)) {
await showContributePage('use');
}
return;
}
}
async function onStorageChange(changes, area) {
await setChallengeLocale();
}
function addStorageListener() {
browser.storage.onChanged.addListener(onStorageChange);
}
function addMessageListener() {
browser.runtime.onMessage.addListener(onMessage);
}
async function onLoad() {
await initStorage('sync');
await setChallengeLocale();
addStorageListener();
addMessageListener();
}

@ -21,6 +21,8 @@
"tabs",
"activeTab",
"notifications",
"webRequest",
"webRequestBlocking",
"<all_urls>"
],

@ -78,6 +78,12 @@
{{ getText('optionSectionTitle_misc') }}
</div>
<div class="option-wrap">
<div class="option">
<v-form-field input-id="lec"
:label="getText('optionTitle_loadEnglishChallenge')">
<v-switch id="lec" v-model="options.loadEnglishChallenge"></v-switch>
</v-form-field>
</div>
<div class="option">
<v-form-field input-id="esm"
:label="getText('optionTitle_tryEnglishSpeechModel')">
@ -155,6 +161,7 @@ export default {
microsoftSpeechApiLoc: '',
microsoftSpeechApiKey: '',
witSpeechApiKeys: {},
loadEnglishChallenge: false,
tryEnglishSpeechModel: false
}
};

@ -285,11 +285,12 @@ async function solve() {
config: {
encoding: 'LINEAR16',
languageCode: language,
model: 'default',
model: 'video',
sampleRateHertz: 16000
}
};
if (!['en-US', 'en-GB'].includes(language) && tryEnglishSpeechModel) {
data.config.model = 'default';
data.config.alternativeLanguageCodes = ['en-US'];
}

@ -0,0 +1,27 @@
import browser from 'webextension-polyfill';
const message = 'Add loadEnglishChallenge option';
const revision = 'ZtLMLoh1ag';
const downRevision = 'nOedd0Txqd';
const storage = browser.storage.local;
async function upgrade() {
const changes = {
loadEnglishChallenge: true
};
changes.storageVersion = revision;
return storage.set(changes);
}
async function downgrade() {
const changes = {};
await storage.remove(['loadEnglishChallenge']);
changes.storageVersion = downRevision;
return storage.set(changes);
}
export {message, revision, upgrade, downgrade};

@ -1 +1,9 @@
{"versions": ["UoT3kGyBH", "ONiJBs00o", "UidMDYaYA", "nOedd0Txqd"]}
{
"versions": [
"UoT3kGyBH",
"ONiJBs00o",
"UidMDYaYA",
"nOedd0Txqd",
"ZtLMLoh1ag"
]
}

@ -0,0 +1,27 @@
import browser from 'webextension-polyfill';
const message = 'Add loadEnglishChallenge option';
const revision = 'ZtLMLoh1ag';
const downRevision = 'nOedd0Txqd';
const storage = browser.storage.sync;
async function upgrade() {
const changes = {
loadEnglishChallenge: true
};
changes.storageVersion = revision;
return storage.set(changes);
}
async function downgrade() {
const changes = {};
await storage.remove(['loadEnglishChallenge']);
changes.storageVersion = downRevision;
return storage.set(changes);
}
export {message, revision, upgrade, downgrade};

@ -1 +1,9 @@
{"versions": ["UoT3kGyBH", "ONiJBs00o", "UidMDYaYA", "nOedd0Txqd"]}
{
"versions": [
"UoT3kGyBH",
"ONiJBs00o",
"UidMDYaYA",
"nOedd0Txqd",
"ZtLMLoh1ag"
]
}

@ -6,6 +6,7 @@ const optionKeys = [
'microsoftSpeechApiLoc',
'microsoftSpeechApiKey',
'witSpeechApiKeys',
'loadEnglishChallenge',
'tryEnglishSpeechModel'
];

Loading…
Cancel
Save