2020-09-20 15:33:12 +00:00
|
|
|
|
/*
|
2021-01-01 19:50:41 +00:00
|
|
|
|
* Copyright (C) 2020-2021 Yomichan Authors
|
2020-09-20 15:33:12 +00:00
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
const fs = require('fs');
|
|
|
|
|
const url = require('url');
|
|
|
|
|
const path = require('path');
|
|
|
|
|
const assert = require('assert');
|
2020-11-07 16:34:14 +00:00
|
|
|
|
const {testMain} = require('../dev/util');
|
2020-09-20 15:33:12 +00:00
|
|
|
|
const {VM} = require('../dev/vm');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function createVM(extDir) {
|
|
|
|
|
const chrome = {
|
|
|
|
|
runtime: {
|
|
|
|
|
getURL(path2) {
|
|
|
|
|
return url.pathToFileURL(path.join(extDir, path2.replace(/^\//, ''))).href;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
async function fetch(url2) {
|
|
|
|
|
const filePath = url.fileURLToPath(url2);
|
|
|
|
|
await Promise.resolve();
|
|
|
|
|
const content = fs.readFileSync(filePath, {encoding: null});
|
|
|
|
|
return {
|
|
|
|
|
ok: true,
|
|
|
|
|
status: 200,
|
|
|
|
|
statusText: 'OK',
|
|
|
|
|
text: async () => Promise.resolve(content.toString('utf8')),
|
|
|
|
|
json: async () => Promise.resolve(JSON.parse(content.toString('utf8')))
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const vm = new VM({chrome, fetch});
|
|
|
|
|
vm.execute([
|
|
|
|
|
'mixed/js/core.js',
|
|
|
|
|
'mixed/js/cache-map.js',
|
|
|
|
|
'bg/js/json-schema.js',
|
|
|
|
|
'bg/js/options.js'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return vm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function clone(value) {
|
|
|
|
|
return JSON.parse(JSON.stringify(value));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function createProfileOptionsTestData1() {
|
|
|
|
|
return {
|
2020-10-27 23:26:30 +00:00
|
|
|
|
version: 14,
|
2020-09-20 15:33:12 +00:00
|
|
|
|
general: {
|
|
|
|
|
enable: true,
|
|
|
|
|
enableClipboardPopups: false,
|
|
|
|
|
resultOutputMode: 'group',
|
|
|
|
|
debugInfo: false,
|
|
|
|
|
maxResults: 32,
|
|
|
|
|
showAdvanced: false,
|
|
|
|
|
popupDisplayMode: 'default',
|
|
|
|
|
popupWidth: 400,
|
|
|
|
|
popupHeight: 250,
|
|
|
|
|
popupHorizontalOffset: 0,
|
|
|
|
|
popupVerticalOffset: 10,
|
|
|
|
|
popupHorizontalOffset2: 10,
|
|
|
|
|
popupVerticalOffset2: 0,
|
|
|
|
|
popupHorizontalTextPosition: 'below',
|
|
|
|
|
popupVerticalTextPosition: 'before',
|
|
|
|
|
popupScalingFactor: 1,
|
|
|
|
|
popupScaleRelativeToPageZoom: false,
|
|
|
|
|
popupScaleRelativeToVisualViewport: true,
|
|
|
|
|
showGuide: true,
|
|
|
|
|
compactTags: false,
|
|
|
|
|
compactGlossaries: false,
|
|
|
|
|
mainDictionary: '',
|
|
|
|
|
popupTheme: 'default',
|
|
|
|
|
popupOuterTheme: 'default',
|
|
|
|
|
customPopupCss: '',
|
|
|
|
|
customPopupOuterCss: '',
|
|
|
|
|
enableWanakana: true,
|
|
|
|
|
enableClipboardMonitor: false,
|
|
|
|
|
showPitchAccentDownstepNotation: true,
|
|
|
|
|
showPitchAccentPositionNotation: true,
|
|
|
|
|
showPitchAccentGraph: false,
|
|
|
|
|
showIframePopupsInRootFrame: false,
|
|
|
|
|
useSecurePopupFrameUrl: true,
|
|
|
|
|
usePopupShadowDom: true
|
|
|
|
|
},
|
|
|
|
|
audio: {
|
|
|
|
|
enabled: true,
|
|
|
|
|
sources: ['jpod101'],
|
|
|
|
|
volume: 100,
|
|
|
|
|
autoPlay: false,
|
|
|
|
|
customSourceUrl: '',
|
|
|
|
|
textToSpeechVoice: ''
|
|
|
|
|
},
|
|
|
|
|
scanning: {
|
|
|
|
|
middleMouse: true,
|
|
|
|
|
touchInputEnabled: true,
|
|
|
|
|
selectText: true,
|
|
|
|
|
alphanumeric: true,
|
|
|
|
|
autoHideResults: false,
|
|
|
|
|
delay: 20,
|
|
|
|
|
length: 10,
|
|
|
|
|
modifier: 'shift',
|
|
|
|
|
deepDomScan: false,
|
|
|
|
|
popupNestingMaxDepth: 0,
|
|
|
|
|
enablePopupSearch: false,
|
|
|
|
|
enableOnPopupExpressions: false,
|
|
|
|
|
enableOnSearchPage: true,
|
|
|
|
|
enableSearchTags: false,
|
|
|
|
|
layoutAwareScan: false
|
|
|
|
|
},
|
|
|
|
|
translation: {
|
|
|
|
|
convertHalfWidthCharacters: 'false',
|
|
|
|
|
convertNumericCharacters: 'false',
|
|
|
|
|
convertAlphabeticCharacters: 'false',
|
|
|
|
|
convertHiraganaToKatakana: 'false',
|
|
|
|
|
convertKatakanaToHiragana: 'variant',
|
|
|
|
|
collapseEmphaticSequences: 'false'
|
|
|
|
|
},
|
|
|
|
|
dictionaries: {},
|
|
|
|
|
parsing: {
|
|
|
|
|
enableScanningParser: true,
|
|
|
|
|
enableMecabParser: false,
|
|
|
|
|
selectedParser: null,
|
|
|
|
|
termSpacing: true,
|
|
|
|
|
readingMode: 'hiragana'
|
|
|
|
|
},
|
|
|
|
|
anki: {
|
|
|
|
|
enable: false,
|
|
|
|
|
server: 'http://127.0.0.1:8765',
|
|
|
|
|
tags: ['yomichan'],
|
|
|
|
|
sentenceExt: 200,
|
|
|
|
|
screenshot: {format: 'png', quality: 92},
|
|
|
|
|
terms: {deck: '', model: '', fields: {}},
|
|
|
|
|
kanji: {deck: '', model: '', fields: {}},
|
|
|
|
|
duplicateScope: 'collection',
|
|
|
|
|
fieldTemplates: null
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createOptionsTestData1() {
|
|
|
|
|
return {
|
|
|
|
|
profiles: [
|
|
|
|
|
{
|
|
|
|
|
name: 'Default',
|
|
|
|
|
options: createProfileOptionsTestData1(),
|
|
|
|
|
conditionGroups: [
|
|
|
|
|
{
|
|
|
|
|
conditions: [
|
|
|
|
|
{
|
|
|
|
|
type: 'popupLevel',
|
|
|
|
|
operator: 'equal',
|
|
|
|
|
value: 1
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'popupLevel',
|
|
|
|
|
operator: 'notEqual',
|
|
|
|
|
value: 0
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'popupLevel',
|
|
|
|
|
operator: 'lessThan',
|
|
|
|
|
value: 3
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'popupLevel',
|
|
|
|
|
operator: 'greaterThan',
|
|
|
|
|
value: 0
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'popupLevel',
|
|
|
|
|
operator: 'lessThanOrEqual',
|
|
|
|
|
value: 2
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'popupLevel',
|
|
|
|
|
operator: 'greaterThanOrEqual',
|
|
|
|
|
value: 1
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
conditions: [
|
|
|
|
|
{
|
|
|
|
|
type: 'url',
|
|
|
|
|
operator: 'matchDomain',
|
|
|
|
|
value: 'example.com'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'url',
|
|
|
|
|
operator: 'matchRegExp',
|
|
|
|
|
value: 'example\\.com'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
conditions: [
|
|
|
|
|
{
|
|
|
|
|
type: 'modifierKeys',
|
|
|
|
|
operator: 'are',
|
|
|
|
|
value: [
|
|
|
|
|
'ctrl',
|
|
|
|
|
'shift'
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'modifierKeys',
|
|
|
|
|
operator: 'areNot',
|
|
|
|
|
value: [
|
|
|
|
|
'alt',
|
|
|
|
|
'shift'
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'modifierKeys',
|
|
|
|
|
operator: 'include',
|
|
|
|
|
value: 'alt'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'modifierKeys',
|
|
|
|
|
operator: 'notInclude',
|
|
|
|
|
value: 'ctrl'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
profileCurrent: 0,
|
|
|
|
|
version: 2,
|
|
|
|
|
global: {
|
|
|
|
|
database: {
|
|
|
|
|
prefixWildcardsSupported: false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function createProfileOptionsUpdatedTestData1() {
|
|
|
|
|
return {
|
|
|
|
|
general: {
|
|
|
|
|
enable: true,
|
|
|
|
|
enableClipboardPopups: false,
|
|
|
|
|
resultOutputMode: 'group',
|
|
|
|
|
debugInfo: false,
|
|
|
|
|
maxResults: 32,
|
|
|
|
|
showAdvanced: false,
|
|
|
|
|
popupDisplayMode: 'default',
|
|
|
|
|
popupWidth: 400,
|
|
|
|
|
popupHeight: 250,
|
|
|
|
|
popupHorizontalOffset: 0,
|
|
|
|
|
popupVerticalOffset: 10,
|
|
|
|
|
popupHorizontalOffset2: 10,
|
|
|
|
|
popupVerticalOffset2: 0,
|
|
|
|
|
popupHorizontalTextPosition: 'below',
|
|
|
|
|
popupVerticalTextPosition: 'before',
|
|
|
|
|
popupScalingFactor: 1,
|
|
|
|
|
popupScaleRelativeToPageZoom: false,
|
|
|
|
|
popupScaleRelativeToVisualViewport: true,
|
|
|
|
|
showGuide: true,
|
|
|
|
|
compactTags: false,
|
2020-11-26 04:22:05 +00:00
|
|
|
|
glossaryLayoutMode: 'default',
|
2020-09-20 15:33:12 +00:00
|
|
|
|
mainDictionary: '',
|
|
|
|
|
popupTheme: 'default',
|
|
|
|
|
popupOuterTheme: 'default',
|
|
|
|
|
customPopupCss: '',
|
|
|
|
|
customPopupOuterCss: '',
|
|
|
|
|
enableWanakana: true,
|
|
|
|
|
enableClipboardMonitor: false,
|
|
|
|
|
showPitchAccentDownstepNotation: true,
|
|
|
|
|
showPitchAccentPositionNotation: true,
|
|
|
|
|
showPitchAccentGraph: false,
|
|
|
|
|
showIframePopupsInRootFrame: false,
|
|
|
|
|
useSecurePopupFrameUrl: true,
|
|
|
|
|
usePopupShadowDom: true,
|
2020-12-18 16:24:43 +00:00
|
|
|
|
usePopupWindow: false,
|
2020-12-19 20:42:44 +00:00
|
|
|
|
maximumClipboardSearchLength: 1000,
|
2020-12-22 23:22:14 +00:00
|
|
|
|
popupCurrentIndicatorMode: 'triangle',
|
2020-12-20 01:07:55 +00:00
|
|
|
|
popupActionBarVisibility: 'auto',
|
2021-01-10 21:49:40 +00:00
|
|
|
|
popupActionBarLocation: 'top'
|
2020-09-20 15:33:12 +00:00
|
|
|
|
},
|
|
|
|
|
audio: {
|
|
|
|
|
enabled: true,
|
|
|
|
|
sources: ['jpod101'],
|
|
|
|
|
volume: 100,
|
|
|
|
|
autoPlay: false,
|
|
|
|
|
customSourceUrl: '',
|
|
|
|
|
textToSpeechVoice: ''
|
|
|
|
|
},
|
|
|
|
|
scanning: {
|
|
|
|
|
touchInputEnabled: true,
|
|
|
|
|
selectText: true,
|
|
|
|
|
alphanumeric: true,
|
|
|
|
|
autoHideResults: false,
|
|
|
|
|
delay: 20,
|
|
|
|
|
length: 10,
|
|
|
|
|
deepDomScan: false,
|
|
|
|
|
popupNestingMaxDepth: 0,
|
|
|
|
|
enablePopupSearch: false,
|
|
|
|
|
enableOnPopupExpressions: false,
|
|
|
|
|
enableOnSearchPage: true,
|
|
|
|
|
enableSearchTags: false,
|
|
|
|
|
layoutAwareScan: false,
|
|
|
|
|
hideDelay: 0,
|
|
|
|
|
pointerEventsEnabled: false,
|
2020-09-26 23:24:21 +00:00
|
|
|
|
preventMiddleMouse: {
|
|
|
|
|
onWebPages: false,
|
|
|
|
|
onPopupPages: false,
|
|
|
|
|
onSearchPages: false,
|
|
|
|
|
onSearchQuery: false
|
|
|
|
|
},
|
2020-09-20 15:33:12 +00:00
|
|
|
|
inputs: [
|
|
|
|
|
{
|
|
|
|
|
include: 'shift',
|
2020-09-26 21:51:52 +00:00
|
|
|
|
exclude: 'mouse0',
|
2020-09-20 15:33:12 +00:00
|
|
|
|
types: {
|
|
|
|
|
mouse: true,
|
|
|
|
|
touch: false,
|
|
|
|
|
pen: false
|
|
|
|
|
},
|
|
|
|
|
options: {
|
|
|
|
|
showAdvanced: false,
|
2020-09-27 15:53:07 +00:00
|
|
|
|
searchTerms: true,
|
|
|
|
|
searchKanji: true,
|
2020-09-27 15:46:37 +00:00
|
|
|
|
scanOnTouchMove: true,
|
2020-09-20 15:33:12 +00:00
|
|
|
|
scanOnPenHover: true,
|
|
|
|
|
scanOnPenPress: true,
|
|
|
|
|
scanOnPenRelease: false,
|
2020-09-27 15:46:37 +00:00
|
|
|
|
preventTouchScrolling: true
|
2020-09-20 15:33:12 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
include: 'mouse2',
|
|
|
|
|
exclude: '',
|
|
|
|
|
types: {
|
|
|
|
|
mouse: true,
|
|
|
|
|
touch: false,
|
|
|
|
|
pen: false
|
|
|
|
|
},
|
|
|
|
|
options: {
|
|
|
|
|
showAdvanced: false,
|
2020-09-27 15:53:07 +00:00
|
|
|
|
searchTerms: true,
|
|
|
|
|
searchKanji: true,
|
2020-09-27 15:46:37 +00:00
|
|
|
|
scanOnTouchMove: true,
|
2020-09-20 15:33:12 +00:00
|
|
|
|
scanOnPenHover: true,
|
|
|
|
|
scanOnPenPress: true,
|
|
|
|
|
scanOnPenRelease: false,
|
2020-09-27 15:46:37 +00:00
|
|
|
|
preventTouchScrolling: true
|
2020-09-20 15:33:12 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
include: '',
|
|
|
|
|
exclude: '',
|
|
|
|
|
types: {
|
|
|
|
|
mouse: false,
|
|
|
|
|
touch: true,
|
|
|
|
|
pen: true
|
|
|
|
|
},
|
|
|
|
|
options: {
|
|
|
|
|
showAdvanced: false,
|
2020-09-27 15:53:07 +00:00
|
|
|
|
searchTerms: true,
|
|
|
|
|
searchKanji: true,
|
2020-09-27 15:46:37 +00:00
|
|
|
|
scanOnTouchMove: true,
|
2020-09-20 15:33:12 +00:00
|
|
|
|
scanOnPenHover: true,
|
|
|
|
|
scanOnPenPress: true,
|
|
|
|
|
scanOnPenRelease: false,
|
2020-09-27 15:46:37 +00:00
|
|
|
|
preventTouchScrolling: true
|
2020-09-20 15:33:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
translation: {
|
|
|
|
|
convertHalfWidthCharacters: 'false',
|
|
|
|
|
convertNumericCharacters: 'false',
|
|
|
|
|
convertAlphabeticCharacters: 'false',
|
|
|
|
|
convertHiraganaToKatakana: 'false',
|
|
|
|
|
convertKatakanaToHiragana: 'variant',
|
2021-01-03 17:12:55 +00:00
|
|
|
|
collapseEmphaticSequences: 'false',
|
|
|
|
|
textReplacements: {
|
|
|
|
|
searchOriginal: true,
|
|
|
|
|
groups: []
|
|
|
|
|
}
|
2020-09-20 15:33:12 +00:00
|
|
|
|
},
|
|
|
|
|
dictionaries: {},
|
|
|
|
|
parsing: {
|
|
|
|
|
enableScanningParser: true,
|
|
|
|
|
enableMecabParser: false,
|
|
|
|
|
selectedParser: null,
|
|
|
|
|
termSpacing: true,
|
|
|
|
|
readingMode: 'hiragana'
|
|
|
|
|
},
|
|
|
|
|
anki: {
|
|
|
|
|
enable: false,
|
|
|
|
|
server: 'http://127.0.0.1:8765',
|
|
|
|
|
tags: ['yomichan'],
|
|
|
|
|
screenshot: {format: 'png', quality: 92},
|
|
|
|
|
terms: {deck: '', model: '', fields: {}},
|
|
|
|
|
kanji: {deck: '', model: '', fields: {}},
|
|
|
|
|
duplicateScope: 'collection',
|
2020-11-08 21:25:07 +00:00
|
|
|
|
checkForDuplicates: true,
|
2021-01-15 03:42:11 +00:00
|
|
|
|
fieldTemplates: null,
|
|
|
|
|
suspendNewCards: false
|
2021-01-10 02:25:04 +00:00
|
|
|
|
},
|
|
|
|
|
sentenceParsing: {
|
2021-01-10 19:43:06 +00:00
|
|
|
|
scanExtent: 200,
|
|
|
|
|
enableTerminationCharacters: true,
|
|
|
|
|
terminationCharacters: [
|
|
|
|
|
{enabled: true, character1: '「', character2: '」', includeCharacterAtStart: false, includeCharacterAtEnd: false},
|
|
|
|
|
{enabled: true, character1: '『', character2: '』', includeCharacterAtStart: false, includeCharacterAtEnd: false},
|
|
|
|
|
{enabled: true, character1: '"', character2: '"', includeCharacterAtStart: false, includeCharacterAtEnd: false},
|
|
|
|
|
{enabled: true, character1: '\'', character2: '\'', includeCharacterAtStart: false, includeCharacterAtEnd: false},
|
|
|
|
|
{enabled: true, character1: '.', character2: null, includeCharacterAtStart: false, includeCharacterAtEnd: true},
|
|
|
|
|
{enabled: true, character1: '!', character2: null, includeCharacterAtStart: false, includeCharacterAtEnd: true},
|
|
|
|
|
{enabled: true, character1: '?', character2: null, includeCharacterAtStart: false, includeCharacterAtEnd: true},
|
|
|
|
|
{enabled: true, character1: '.', character2: null, includeCharacterAtStart: false, includeCharacterAtEnd: true},
|
|
|
|
|
{enabled: true, character1: '。', character2: null, includeCharacterAtStart: false, includeCharacterAtEnd: true},
|
|
|
|
|
{enabled: true, character1: '!', character2: null, includeCharacterAtStart: false, includeCharacterAtEnd: true},
|
|
|
|
|
{enabled: true, character1: '?', character2: null, includeCharacterAtStart: false, includeCharacterAtEnd: true},
|
|
|
|
|
{enabled: true, character1: '…', character2: null, includeCharacterAtStart: false, includeCharacterAtEnd: true}
|
|
|
|
|
]
|
2021-01-15 01:56:18 +00:00
|
|
|
|
},
|
|
|
|
|
inputs: {
|
|
|
|
|
hotkeys: [
|
2021-01-16 01:19:56 +00:00
|
|
|
|
{action: 'close', key: 'Escape', modifiers: [], scopes: ['popup'], enabled: true},
|
|
|
|
|
{action: 'focusSearchBox', key: 'Escape', modifiers: [], scopes: ['search'], enabled: true},
|
2021-01-15 01:56:18 +00:00
|
|
|
|
{action: 'previousEntry3', key: 'PageUp', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
|
|
|
|
|
{action: 'nextEntry3', key: 'PageDown', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
|
|
|
|
|
{action: 'lastEntry', key: 'End', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
|
|
|
|
|
{action: 'firstEntry', key: 'Home', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
|
|
|
|
|
{action: 'previousEntry', key: 'ArrowUp', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
|
|
|
|
|
{action: 'nextEntry', key: 'ArrowDown', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
|
|
|
|
|
{action: 'historyBackward', key: 'KeyB', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
|
|
|
|
|
{action: 'historyForward', key: 'KeyF', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
|
|
|
|
|
{action: 'addNoteKanji', key: 'KeyK', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
|
|
|
|
|
{action: 'addNoteTermKanji', key: 'KeyE', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
|
|
|
|
|
{action: 'addNoteTermKana', key: 'KeyR', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
|
|
|
|
|
{action: 'playAudio', key: 'KeyP', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
|
|
|
|
|
{action: 'viewNote', key: 'KeyV', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
|
|
|
|
|
{action: 'copyHostSelection', key: 'KeyC', modifiers: ['ctrl'], scopes: ['popup', 'search'], enabled: true}
|
|
|
|
|
]
|
2021-01-16 15:22:24 +00:00
|
|
|
|
},
|
|
|
|
|
popupWindow: {
|
|
|
|
|
width: 400,
|
|
|
|
|
height: 250,
|
|
|
|
|
left: 0,
|
|
|
|
|
top: 0,
|
|
|
|
|
useLeft: false,
|
|
|
|
|
useTop: false,
|
|
|
|
|
windowType: 'popup',
|
|
|
|
|
windowState: 'normal'
|
2020-09-20 15:33:12 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createOptionsUpdatedTestData1() {
|
|
|
|
|
return {
|
|
|
|
|
profiles: [
|
|
|
|
|
{
|
|
|
|
|
name: 'Default',
|
|
|
|
|
options: createProfileOptionsUpdatedTestData1(),
|
|
|
|
|
conditionGroups: [
|
|
|
|
|
{
|
|
|
|
|
conditions: [
|
|
|
|
|
{
|
|
|
|
|
type: 'popupLevel',
|
|
|
|
|
operator: 'equal',
|
|
|
|
|
value: '1'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'popupLevel',
|
|
|
|
|
operator: 'notEqual',
|
|
|
|
|
value: '0'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'popupLevel',
|
|
|
|
|
operator: 'lessThan',
|
|
|
|
|
value: '3'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'popupLevel',
|
|
|
|
|
operator: 'greaterThan',
|
|
|
|
|
value: '0'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'popupLevel',
|
|
|
|
|
operator: 'lessThanOrEqual',
|
|
|
|
|
value: '2'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'popupLevel',
|
|
|
|
|
operator: 'greaterThanOrEqual',
|
|
|
|
|
value: '1'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
conditions: [
|
|
|
|
|
{
|
|
|
|
|
type: 'url',
|
|
|
|
|
operator: 'matchDomain',
|
|
|
|
|
value: 'example.com'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'url',
|
|
|
|
|
operator: 'matchRegExp',
|
|
|
|
|
value: 'example\\.com'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
conditions: [
|
|
|
|
|
{
|
|
|
|
|
type: 'modifierKeys',
|
|
|
|
|
operator: 'are',
|
|
|
|
|
value: 'ctrl, shift'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'modifierKeys',
|
|
|
|
|
operator: 'areNot',
|
|
|
|
|
value: 'alt, shift'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'modifierKeys',
|
|
|
|
|
operator: 'include',
|
|
|
|
|
value: 'alt'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'modifierKeys',
|
|
|
|
|
operator: 'notInclude',
|
|
|
|
|
value: 'ctrl'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
profileCurrent: 0,
|
2021-01-03 17:12:55 +00:00
|
|
|
|
version: 8,
|
2020-09-20 15:33:12 +00:00
|
|
|
|
global: {
|
|
|
|
|
database: {
|
|
|
|
|
prefixWildcardsSupported: false
|
2020-11-07 16:31:38 +00:00
|
|
|
|
},
|
2021-01-16 21:55:40 +00:00
|
|
|
|
useSettingsV2: true
|
2020-09-20 15:33:12 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function testUpdate(extDir) {
|
|
|
|
|
const vm = createVM(extDir);
|
|
|
|
|
const [OptionsUtil] = vm.get(['OptionsUtil']);
|
|
|
|
|
const optionsUtil = new OptionsUtil();
|
|
|
|
|
await optionsUtil.prepare();
|
|
|
|
|
|
|
|
|
|
const options = createOptionsTestData1();
|
|
|
|
|
const optionsUpdated = clone(await optionsUtil.update(options));
|
|
|
|
|
const optionsExpected = createOptionsUpdatedTestData1();
|
|
|
|
|
assert.deepStrictEqual(optionsUpdated, optionsExpected);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-27 23:26:30 +00:00
|
|
|
|
async function testDefault(extDir) {
|
|
|
|
|
const data = [
|
|
|
|
|
(options) => options,
|
|
|
|
|
(options) => {
|
|
|
|
|
delete options.profiles[0].options.audio.autoPlay;
|
|
|
|
|
},
|
|
|
|
|
(options) => {
|
|
|
|
|
options.profiles[0].options.audio.autoPlay = void 0;
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const vm = createVM(extDir);
|
|
|
|
|
const [OptionsUtil] = vm.get(['OptionsUtil']);
|
|
|
|
|
const optionsUtil = new OptionsUtil();
|
|
|
|
|
await optionsUtil.prepare();
|
|
|
|
|
|
|
|
|
|
for (const modify of data) {
|
|
|
|
|
const options = optionsUtil.getDefault();
|
|
|
|
|
|
|
|
|
|
const optionsModified = clone(options);
|
|
|
|
|
modify(optionsModified);
|
|
|
|
|
|
|
|
|
|
const optionsUpdated = await optionsUtil.update(clone(optionsModified));
|
|
|
|
|
assert.deepStrictEqual(clone(optionsUpdated), clone(options));
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-20 15:33:12 +00:00
|
|
|
|
|
|
|
|
|
async function testFieldTemplatesUpdate(extDir) {
|
|
|
|
|
const vm = createVM(extDir);
|
|
|
|
|
const [OptionsUtil] = vm.get(['OptionsUtil']);
|
|
|
|
|
const optionsUtil = new OptionsUtil();
|
|
|
|
|
await optionsUtil.prepare();
|
|
|
|
|
|
|
|
|
|
const loadDataFile = (fileName) => fs.readFileSync(path.join(extDir, fileName), {encoding: 'utf8'});
|
|
|
|
|
const update2 = loadDataFile('bg/data/anki-field-templates-upgrade-v2.handlebars');
|
|
|
|
|
const update4 = loadDataFile('bg/data/anki-field-templates-upgrade-v4.handlebars');
|
2020-11-05 01:39:23 +00:00
|
|
|
|
const update6 = loadDataFile('bg/data/anki-field-templates-upgrade-v6.handlebars');
|
2021-01-16 20:29:42 +00:00
|
|
|
|
const update8 = loadDataFile('bg/data/anki-field-templates-upgrade-v8.handlebars');
|
2020-09-20 15:33:12 +00:00
|
|
|
|
|
|
|
|
|
const data = [
|
|
|
|
|
// Standard format
|
|
|
|
|
{
|
|
|
|
|
old: `
|
|
|
|
|
{{#*inline "character"}}
|
|
|
|
|
{{~definition.character~}}
|
|
|
|
|
{{/inline}}
|
|
|
|
|
|
|
|
|
|
{{~> (lookup . "marker") ~}}`.trimStart(),
|
|
|
|
|
|
|
|
|
|
expected: `
|
|
|
|
|
{{#*inline "character"}}
|
|
|
|
|
{{~definition.character~}}
|
|
|
|
|
{{/inline}}
|
|
|
|
|
|
|
|
|
|
${update2}
|
|
|
|
|
${update4}
|
2020-11-05 01:39:23 +00:00
|
|
|
|
${update6}
|
2021-01-16 20:29:42 +00:00
|
|
|
|
${update8}
|
2020-09-20 15:33:12 +00:00
|
|
|
|
{{~> (lookup . "marker") ~}}`.trimStart()
|
|
|
|
|
},
|
|
|
|
|
// Non-standard marker format
|
|
|
|
|
{
|
|
|
|
|
old: `
|
|
|
|
|
{{#*inline "character"}}
|
|
|
|
|
{{~definition.character~}}
|
|
|
|
|
{{/inline}}
|
|
|
|
|
|
|
|
|
|
{{~> (lookup . "marker2") ~}}`.trimStart(),
|
|
|
|
|
|
|
|
|
|
expected: `
|
|
|
|
|
{{#*inline "character"}}
|
|
|
|
|
{{~definition.character~}}
|
|
|
|
|
{{/inline}}
|
|
|
|
|
|
|
|
|
|
{{~> (lookup . "marker2") ~}}
|
|
|
|
|
${update2}
|
2020-11-05 01:39:23 +00:00
|
|
|
|
${update4}
|
2021-01-16 20:29:42 +00:00
|
|
|
|
${update6}
|
|
|
|
|
${update8}`.trimStart()
|
2020-09-20 15:33:12 +00:00
|
|
|
|
},
|
|
|
|
|
// Empty test
|
|
|
|
|
{
|
|
|
|
|
old: `
|
|
|
|
|
{{~> (lookup . "marker") ~}}`.trimStart(),
|
|
|
|
|
|
|
|
|
|
expected: `
|
|
|
|
|
${update2}
|
|
|
|
|
${update4}
|
2020-11-05 01:39:23 +00:00
|
|
|
|
${update6}
|
2021-01-16 20:29:42 +00:00
|
|
|
|
${update8}
|
2020-09-20 15:33:12 +00:00
|
|
|
|
{{~> (lookup . "marker") ~}}`.trimStart()
|
2020-11-13 01:34:11 +00:00
|
|
|
|
},
|
|
|
|
|
// Definition tags update
|
|
|
|
|
{
|
|
|
|
|
old: `
|
|
|
|
|
{{#*inline "glossary-single"}}
|
|
|
|
|
{{~#unless brief~}}
|
|
|
|
|
{{~#if definitionTags~}}<i>({{#each definitionTags}}{{name}}{{#unless @last}}, {{/unless}}{{/each}})</i> {{/if~}}
|
|
|
|
|
{{~#if only~}}({{#each only}}{{{.}}}{{#unless @last}}, {{/unless}}{{/each}} only) {{/if~}}
|
|
|
|
|
{{~/unless~}}
|
|
|
|
|
{{/inline}}
|
|
|
|
|
|
|
|
|
|
{{#*inline "glossary-single2"}}
|
|
|
|
|
{{~#unless brief~}}
|
|
|
|
|
{{~#if definitionTags~}}<i>({{#each definitionTags}}{{name}}{{#unless @last}}, {{/unless}}{{/each}})</i> {{/if~}}
|
|
|
|
|
{{~#if only~}}({{#each only}}{{{.}}}{{#unless @last}}, {{/unless}}{{/each}} only) {{/if~}}
|
|
|
|
|
{{~/unless~}}
|
|
|
|
|
{{/inline}}
|
|
|
|
|
|
|
|
|
|
{{#*inline "glossary"}}
|
|
|
|
|
{{~> glossary-single definition brief=brief compactGlossaries=compactGlossaries~}}
|
|
|
|
|
{{~> glossary-single definition brief=brief compactGlossaries=../compactGlossaries~}}
|
|
|
|
|
{{/inline}}
|
|
|
|
|
|
|
|
|
|
{{~> (lookup . "marker") ~}}
|
|
|
|
|
`.trimStart(),
|
|
|
|
|
|
|
|
|
|
expected: `
|
|
|
|
|
{{#*inline "glossary-single"}}
|
|
|
|
|
{{~#unless brief~}}
|
|
|
|
|
{{~#scope~}}
|
|
|
|
|
{{~#set "any" false}}{{/set~}}
|
|
|
|
|
{{~#if definitionTags~}}{{#each definitionTags~}}
|
|
|
|
|
{{~#if (op "||" (op "!" ../data.compactTags) (op "!" redundant))~}}
|
|
|
|
|
{{~#if (get "any")}}, {{else}}<i>({{/if~}}
|
|
|
|
|
{{name}}
|
|
|
|
|
{{~#set "any" true}}{{/set~}}
|
|
|
|
|
{{~/if~}}
|
|
|
|
|
{{~/each~}}
|
|
|
|
|
{{~#if (get "any")}})</i> {{/if~}}
|
|
|
|
|
{{~/if~}}
|
|
|
|
|
{{~/scope~}}
|
|
|
|
|
{{~#if only~}}({{#each only}}{{{.}}}{{#unless @last}}, {{/unless}}{{/each}} only) {{/if~}}
|
|
|
|
|
{{~/unless~}}
|
|
|
|
|
{{/inline}}
|
|
|
|
|
|
|
|
|
|
{{#*inline "glossary-single2"}}
|
|
|
|
|
{{~#unless brief~}}
|
|
|
|
|
{{~#scope~}}
|
|
|
|
|
{{~#set "any" false}}{{/set~}}
|
|
|
|
|
{{~#if definitionTags~}}{{#each definitionTags~}}
|
|
|
|
|
{{~#if (op "||" (op "!" ../data.compactTags) (op "!" redundant))~}}
|
|
|
|
|
{{~#if (get "any")}}, {{else}}<i>({{/if~}}
|
|
|
|
|
{{name}}
|
|
|
|
|
{{~#set "any" true}}{{/set~}}
|
|
|
|
|
{{~/if~}}
|
|
|
|
|
{{~/each~}}
|
|
|
|
|
{{~#if (get "any")}})</i> {{/if~}}
|
|
|
|
|
{{~/if~}}
|
|
|
|
|
{{~/scope~}}
|
|
|
|
|
{{~#if only~}}({{#each only}}{{{.}}}{{#unless @last}}, {{/unless}}{{/each}} only) {{/if~}}
|
|
|
|
|
{{~/unless~}}
|
|
|
|
|
{{/inline}}
|
|
|
|
|
|
|
|
|
|
{{#*inline "glossary"}}
|
|
|
|
|
{{~> glossary-single definition brief=brief compactGlossaries=compactGlossaries data=.~}}
|
|
|
|
|
{{~> glossary-single definition brief=brief compactGlossaries=../compactGlossaries data=../.~}}
|
|
|
|
|
{{/inline}}
|
|
|
|
|
|
|
|
|
|
${update2}
|
|
|
|
|
${update4}
|
|
|
|
|
${update6}
|
2021-01-16 20:29:42 +00:00
|
|
|
|
${update8}
|
2020-11-13 01:34:11 +00:00
|
|
|
|
{{~> (lookup . "marker") ~}}
|
|
|
|
|
`.trimStart()
|
2020-09-20 15:33:12 +00:00
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
for (const {old, expected} of data) {
|
|
|
|
|
const options = createOptionsTestData1();
|
|
|
|
|
options.profiles[0].options.anki.fieldTemplates = old;
|
|
|
|
|
const optionsUpdated = clone(await optionsUtil.update(options));
|
|
|
|
|
const fieldTemplatesActual = optionsUpdated.profiles[0].options.anki.fieldTemplates;
|
|
|
|
|
assert.deepStrictEqual(fieldTemplatesActual, expected);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
|
const extDir = path.join(__dirname, '..', 'ext');
|
|
|
|
|
await testUpdate(extDir);
|
2020-10-27 23:26:30 +00:00
|
|
|
|
await testDefault(extDir);
|
2020-09-20 15:33:12 +00:00
|
|
|
|
await testFieldTemplatesUpdate(extDir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-11-07 16:34:14 +00:00
|
|
|
|
if (require.main === module) { testMain(main); }
|