This repository has been archived by the owner on Feb 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29890f7
commit 9915aa8
Showing
6 changed files
with
175 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"manifest": { | ||
"manifest_version": 2, | ||
"manifest_version": 3, | ||
"name": "Yomichan", | ||
"version": "20.8.24.0", | ||
"description": "Japanese dictionary with Anki integration", | ||
|
@@ -28,8 +28,7 @@ | |
"default_popup": "bg/context.html" | ||
}, | ||
"background": { | ||
"page": "bg/background.html", | ||
"persistent": true | ||
"service_worker": "sw.js" | ||
}, | ||
"content_scripts": [ | ||
{ | ||
|
@@ -70,8 +69,7 @@ | |
"sandbox": { | ||
"pages": [ | ||
"bg/template-renderer.html" | ||
], | ||
"content_security_policy": "sandbox allow-scripts; script-src 'self' 'unsafe-eval'; object-src 'self'" | ||
] | ||
}, | ||
"permissions": [ | ||
"<all_urls>", | ||
|
@@ -103,7 +101,9 @@ | |
"fg/float.html", | ||
"bg/template-renderer.html" | ||
], | ||
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'", | ||
"content_security_policy": { | ||
"sandbox": "sandbox allow-scripts; script-src 'self' 'unsafe-eval'; object-src 'self'" | ||
}, | ||
"applications": { | ||
"gecko": { | ||
"id": "[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"manifest_version": 2, | ||
"manifest_version": 3, | ||
"name": "Yomichan", | ||
"version": "20.8.24.0", | ||
"description": "Japanese dictionary with Anki integration", | ||
|
@@ -27,8 +27,7 @@ | |
"default_popup": "bg/context.html" | ||
}, | ||
"background": { | ||
"page": "bg/background.html", | ||
"persistent": true | ||
"service_worker": "sw.js" | ||
}, | ||
"content_scripts": [ | ||
{ | ||
|
@@ -69,8 +68,7 @@ | |
"sandbox": { | ||
"pages": [ | ||
"bg/template-renderer.html" | ||
], | ||
"content_security_policy": "sandbox allow-scripts; script-src 'self' 'unsafe-eval'; object-src 'self'" | ||
] | ||
}, | ||
"permissions": [ | ||
"<all_urls>", | ||
|
@@ -102,7 +100,9 @@ | |
"fg/float.html", | ||
"bg/template-renderer.html" | ||
], | ||
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'", | ||
"content_security_policy": { | ||
"sandbox": "sandbox allow-scripts; script-src 'self' 'unsafe-eval'; object-src 'self'" | ||
}, | ||
"applications": { | ||
"gecko": { | ||
"id": "[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (C) 2020 Yomichan Authors | ||
* | ||
* 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/>. | ||
*/ | ||
|
||
self.importScripts( | ||
'/mixed/lib/wanakana.min.js', | ||
'/mixed/js/core.js', | ||
'/mixed/js/yomichan.js', | ||
'/mixed/js/environment.js', | ||
'/mixed/js/japanese.js', | ||
'/mixed/js/audio-system.js', | ||
'/mixed/js/cache-map.js', | ||
'/mixed/js/dictionary-data-util.js', | ||
'/mixed/js/object-property-accessor.js', | ||
'/bg/js/anki.js', | ||
'/bg/js/audio-uri-builder.js', | ||
'/bg/js/clipboard-monitor.js', | ||
'/bg/js/database.js', | ||
'/bg/js/deinflector.js', | ||
'/bg/js/dictionary-database.js', | ||
'/bg/js/json-schema.js', | ||
'/bg/js/mecab.js', | ||
'/bg/js/options.js', | ||
'/bg/js/profile-conditions.js', | ||
'/bg/js/request-builder.js', | ||
'/bg/js/simple-dom-parser.js', | ||
'/bg/js/text-source-map.js', | ||
'/bg/js/translator.js', | ||
'/bg/js/backend.js', | ||
'/bg/js/background-main.js' | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright (C) 2020 Yomichan Authors | ||
* Author: Yomichan Authors | ||
* | ||
* 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 path = require('path'); | ||
const {JSDOM} = require('jsdom'); | ||
const {VM} = require('../dev/vm'); | ||
const assert = require('assert'); | ||
|
||
|
||
function getAllHtmlScriptPaths(fileName) { | ||
const domSource = fs.readFileSync(fileName, {encoding: 'utf8'}); | ||
const dom = new JSDOM(domSource); | ||
const {window} = dom; | ||
const {document} = window; | ||
try { | ||
const scripts = document.querySelectorAll('script'); | ||
return [...scripts].map(({src}) => src); | ||
} finally { | ||
window.close(); | ||
} | ||
} | ||
|
||
|
||
function main() { | ||
try { | ||
// Verify that sw.js scripts match background.html scripts | ||
const rootDir = path.join(__dirname, '..'); | ||
const extDirName = 'ext'; | ||
const extDir = path.join(rootDir, extDirName); | ||
|
||
const scripts = getAllHtmlScriptPaths(path.join(extDir, 'bg', 'background.html')); | ||
const importedScripts = []; | ||
|
||
const importScripts = (...scripts2) => { | ||
importedScripts.push(...scripts2); | ||
}; | ||
|
||
const vm = new VM({importScripts}); | ||
vm.context.self = vm.context; | ||
vm.execute(['sw.js']); | ||
|
||
vm.assert.deepStrictEqual(scripts, importedScripts); | ||
|
||
// Verify that eslint config lists files correctly | ||
const expectedSwRulesFiles = scripts.filter((src) => !src.startsWith('/mixed/lib/')).map((src) => `${extDirName}${src}`); | ||
const eslintConfig = JSON.parse(fs.readFileSync(path.join(rootDir, '.eslintrc.json'), {encoding: 'utf8'})); | ||
const swRules = eslintConfig.overrides.find((item) => ( | ||
typeof item.env === 'object' && | ||
item.env !== null && | ||
item.env.serviceworker === true | ||
)); | ||
assert.ok(typeof swRules !== 'undefined'); | ||
assert.ok(Array.isArray(swRules.files)); | ||
assert.deepStrictEqual(swRules.files, expectedSwRulesFiles); | ||
} catch (e) { | ||
console.error(e); | ||
process.exit(-1); | ||
return; | ||
} | ||
process.exit(0); | ||
} | ||
|
||
|
||
if (require.main === module) { main(); } |