@ai0x1337/budoux-extension 0.0.1-security → 99.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @ai0x1337/budoux-extension might be problematic. Click here for more details.
- package/.github/workflows/poc.yml +25 -0
- package/budoux-extension-backup/.github/dependabot.yml +10 -0
- package/budoux-extension-backup/.github/workflows/ci.yml +38 -0
- package/budoux-extension-backup/.prettierrc.json +6 -0
- package/budoux-extension-backup/CONTRIBUTING.md +29 -0
- package/budoux-extension-backup/LICENSE +202 -0
- package/budoux-extension-backup/README.md +79 -0
- package/budoux-extension-backup/_locales/en/messages.json +24 -0
- package/budoux-extension-backup/_locales/ja/messages.json +23 -0
- package/budoux-extension-backup/docs/icon128.png +0 -0
- package/budoux-extension-backup/docs/neko-budoux-640x400.png +0 -0
- package/budoux-extension-backup/docs/neko-budoux-idsp-640x400.png +0 -0
- package/budoux-extension-backup/docs/options-640x400.png +0 -0
- package/budoux-extension-backup/eslint.config.mjs +75 -0
- package/budoux-extension-backup/karma.conf.js +31 -0
- package/budoux-extension-backup/manifest.json +24 -0
- package/budoux-extension-backup/package-lock.json +6544 -0
- package/budoux-extension-backup/package.json +61 -0
- package/budoux-extension-backup/scripts/clean.js +51 -0
- package/budoux-extension-backup/scripts/esbuild.js +27 -0
- package/budoux-extension-backup/scripts/package.ts +98 -0
- package/budoux-extension-backup/src/background.ts +53 -0
- package/budoux-extension-backup/src/content.ts +19 -0
- package/budoux-extension-backup/src/document_applier.ts +148 -0
- package/budoux-extension-backup/src/options.html +109 -0
- package/budoux-extension-backup/src/options.ts +92 -0
- package/budoux-extension-backup/tests/index.browser.ts +17 -0
- package/budoux-extension-backup/tests/test.html +35 -0
- package/budoux-extension-backup/tests/test_document_applier.ts +125 -0
- package/budoux-extension-backup/tsconfig.json +29 -0
- package/package.json +9 -3
- package/README.md +0 -5
@@ -0,0 +1,61 @@
|
|
1
|
+
{
|
2
|
+
"name": "budoux-extension",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"description": "",
|
5
|
+
"engines": {
|
6
|
+
"node": ">=16.0"
|
7
|
+
},
|
8
|
+
"files": [
|
9
|
+
"dist/**/*"
|
10
|
+
],
|
11
|
+
"scripts": {
|
12
|
+
"build": "npm run bundle",
|
13
|
+
"rebuild": "npm run clean && npm run build",
|
14
|
+
"tsc:cjs": "tsc",
|
15
|
+
"tsc:es": "tsc --module ES2020",
|
16
|
+
"prebundle": "npm run tsc:es",
|
17
|
+
"bundle": "node scripts/esbuild.js",
|
18
|
+
"predist": "npm run bundle",
|
19
|
+
"dist": "ts-node scripts/package.ts -d dist --js build/bundle",
|
20
|
+
"prezip": "npm run clean && npm run dist",
|
21
|
+
"zip": "ts-node scripts/package.ts -d dist --zip budoux.zip",
|
22
|
+
"bundle:test": "esbuild build/tests/index.browser.js --outdir=build/bundle --bundle --sourcemap",
|
23
|
+
"pretest": "npm run tsc:es && npm run bundle:test",
|
24
|
+
"test": "karma start --single-run",
|
25
|
+
"lint": "eslint src/** tests/** --no-error-on-unmatched-pattern",
|
26
|
+
"fix": "eslint src/** tests/** --no-error-on-unmatched-pattern --fix",
|
27
|
+
"clean": "node scripts/clean.js && gts clean"
|
28
|
+
},
|
29
|
+
"author": "Koji Ishii",
|
30
|
+
"license": "Apache-2.0",
|
31
|
+
"dependencies": {
|
32
|
+
"@material/mwc-button": "^0.27.0",
|
33
|
+
"@material/mwc-formfield": "^0.27.0",
|
34
|
+
"@material/mwc-radio": "^0.27.0",
|
35
|
+
"@material/mwc-textfield": "^0.27.0",
|
36
|
+
"budoux": "^0.7.0",
|
37
|
+
"budoux-extension": "file:"
|
38
|
+
},
|
39
|
+
"devDependencies": {
|
40
|
+
"@types/archiver": "^6.0.0",
|
41
|
+
"@types/chrome": "^0.1.0",
|
42
|
+
"@types/jasmine": "^5.1.0",
|
43
|
+
"@types/jsdom": "^21.1.1",
|
44
|
+
"@types/node": "^24.0.1",
|
45
|
+
"@typescript-eslint/eslint-plugin": "^8.18.2",
|
46
|
+
"archiver": "^7.0.1",
|
47
|
+
"commander": "^14.0.0",
|
48
|
+
"esbuild": "^0.25.0",
|
49
|
+
"eslint": "^9.17.0",
|
50
|
+
"eslint-config-prettier": "^10.0.2",
|
51
|
+
"eslint-plugin-prettier": "^5.2.1",
|
52
|
+
"glob": "^11.0.0",
|
53
|
+
"jasmine": "^5.1.0",
|
54
|
+
"jsdom": "^26.0.0",
|
55
|
+
"karma": "^6.4.2",
|
56
|
+
"karma-chrome-launcher": "^3.2.0",
|
57
|
+
"karma-jasmine": "^5.1.0",
|
58
|
+
"ts-node": "^10.4.0",
|
59
|
+
"typescript": "^5.1.3"
|
60
|
+
}
|
61
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
/**
|
2
|
+
* @license
|
3
|
+
* Copyright 2021 Google LLC
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
const fs = require('fs');
|
18
|
+
const {glob} = require('glob');
|
19
|
+
|
20
|
+
const dirs = ['build', 'dist'];
|
21
|
+
const patterns = ['*.crx', '*.zip', '**/Icon[\r]*', '**/desktop.ini'];
|
22
|
+
|
23
|
+
function logRemoving(file) {
|
24
|
+
console.log(`Removing ${file} ...`);
|
25
|
+
}
|
26
|
+
|
27
|
+
function isDirectoryExists(dir) {
|
28
|
+
try {
|
29
|
+
return fs.statSync(dir).isDirectory();
|
30
|
+
} catch (error) {
|
31
|
+
if (error.code === 'ENOENT') return false;
|
32
|
+
throw error;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
for (const dir of dirs) {
|
37
|
+
if (isDirectoryExists(dir)) {
|
38
|
+
logRemoving(dir);
|
39
|
+
(fs.rmSync || fs.rmdirSync)(dir, {recursive: true});
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
for (const pattern of patterns) {
|
44
|
+
glob(pattern, (err, files) => {
|
45
|
+
if (err) throw err;
|
46
|
+
for (const file of files) {
|
47
|
+
logRemoving(file);
|
48
|
+
fs.unlinkSync(file);
|
49
|
+
}
|
50
|
+
});
|
51
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
/**
|
2
|
+
* @license
|
3
|
+
* Copyright 2023 Google LLC
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
require('esbuild').build({
|
18
|
+
entryPoints: [
|
19
|
+
'build/src/background.js',
|
20
|
+
'build/src/content.js',
|
21
|
+
'build/src/options.js',
|
22
|
+
],
|
23
|
+
bundle: true,
|
24
|
+
minify: true,
|
25
|
+
outdir: 'build/bundle',
|
26
|
+
sourcemap: true,
|
27
|
+
});
|
@@ -0,0 +1,98 @@
|
|
1
|
+
/* eslint-disable prettier/prettier */
|
2
|
+
/**
|
3
|
+
* @license
|
4
|
+
* Copyright 2021 Google LLC
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*/
|
17
|
+
|
18
|
+
import * as archiver from 'archiver';
|
19
|
+
import {Command} from 'commander';
|
20
|
+
import * as fs from 'fs';
|
21
|
+
const {glob} = require('glob');
|
22
|
+
import * as path from 'path';
|
23
|
+
|
24
|
+
const log = console.log;
|
25
|
+
|
26
|
+
function throwMissingArg(name: string): never {
|
27
|
+
throw new Error(`Missing ${name}`);
|
28
|
+
}
|
29
|
+
|
30
|
+
class ChromeExtensionPackage {
|
31
|
+
async run() {
|
32
|
+
const program = new Command();
|
33
|
+
program.option('-d, --dir <dir>', 'unpacked extension directory');
|
34
|
+
program.option('-j --js <dir>', 'JavaScript directory');
|
35
|
+
program.option('-z, --zip <zip>', 'ZIP file name');
|
36
|
+
program.parse(process.argv);
|
37
|
+
const options = program.opts();
|
38
|
+
const dist_dir = options.dir ?? throwMissingArg('extension directory');
|
39
|
+
const js_dir = options.js;
|
40
|
+
if (js_dir) {
|
41
|
+
await this.copy(js_dir, dist_dir);
|
42
|
+
}
|
43
|
+
const zip_path = options.zip;
|
44
|
+
if (zip_path) {
|
45
|
+
await this.zip(dist_dir, zip_path);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
async copy(js_dir: string, dist_dir: string) {
|
50
|
+
if (!fs.existsSync(dist_dir)) {
|
51
|
+
await fs.promises.mkdir(dist_dir, {recursive: true});
|
52
|
+
}
|
53
|
+
// Bundles are copied from `js_dir` to the root of `dist_dir`.
|
54
|
+
const bundles = ['background.js', 'content.js', 'options.js']
|
55
|
+
.map(name => [path.join(js_dir, name), name]);
|
56
|
+
// Resources are copied to the root of `dist_dir`.
|
57
|
+
const resources = [
|
58
|
+
'manifest.json',
|
59
|
+
'src/options.html',
|
60
|
+
'docs/icon128.png',
|
61
|
+
].map(name => [name, path.basename(name)]);
|
62
|
+
// Locales are copied to the `dist_dir` keeping the tree structure.
|
63
|
+
const locales: string[][] = (await glob('_locales/**/*.json'))
|
64
|
+
.map((name: string) => [name, name]);
|
65
|
+
const files = [...bundles, ...resources, ...locales]
|
66
|
+
.map(([src, dest]) => [src, path.join(dist_dir, dest)]);
|
67
|
+
for (const [, dest] of files) {
|
68
|
+
const dir = path.dirname(dest);
|
69
|
+
if (!fs.existsSync(dir)) await fs.promises.mkdir(dir, {recursive: true});
|
70
|
+
}
|
71
|
+
await Promise.all(
|
72
|
+
files.map(([src, dest]) => {
|
73
|
+
log(`Copying ${src} -> ${dest}`);
|
74
|
+
return fs.promises.copyFile(src, dest);
|
75
|
+
})
|
76
|
+
);
|
77
|
+
}
|
78
|
+
|
79
|
+
async zip(src_dir: string, zip_path: string) {
|
80
|
+
if (!fs.existsSync(src_dir)) {
|
81
|
+
throw new Error(`Directory not found: ${src_dir}`);
|
82
|
+
}
|
83
|
+
const output = fs.createWriteStream(zip_path);
|
84
|
+
const closed_or_ended = new Promise<void>(resolve => {
|
85
|
+
output.on('close', resolve);
|
86
|
+
output.on('end', resolve);
|
87
|
+
});
|
88
|
+
const archive = archiver('zip', {
|
89
|
+
zlib: {level: 9},
|
90
|
+
});
|
91
|
+
archive.pipe(output);
|
92
|
+
archive.directory(src_dir, false);
|
93
|
+
await Promise.all([archive.finalize(), closed_or_ended]);
|
94
|
+
log(`${zip_path}: ${archive.pointer()} bytes`);
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
new ChromeExtensionPackage().run();
|
@@ -0,0 +1,53 @@
|
|
1
|
+
/**
|
2
|
+
* @license
|
3
|
+
* Copyright 2021 Google LLC
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
const assert = console.assert;
|
18
|
+
|
19
|
+
async function applyBudouX(tab?: chrome.tabs.Tab, frameId?: number) {
|
20
|
+
const tabId = tab?.id;
|
21
|
+
assert(tabId !== undefined, tab);
|
22
|
+
if (tabId === undefined) return;
|
23
|
+
const target: chrome.scripting.InjectionTarget = {
|
24
|
+
tabId: tabId,
|
25
|
+
frameIds: frameId !== undefined ? [frameId] : undefined,
|
26
|
+
};
|
27
|
+
await chrome.scripting.executeScript({
|
28
|
+
target: target,
|
29
|
+
files: ['content.js'],
|
30
|
+
});
|
31
|
+
|
32
|
+
await chrome.action.setBadgeText({
|
33
|
+
text: 'ON',
|
34
|
+
tabId: tabId,
|
35
|
+
});
|
36
|
+
await chrome.action.setBadgeBackgroundColor({
|
37
|
+
color: '#00c853',
|
38
|
+
tabId: tabId,
|
39
|
+
});
|
40
|
+
}
|
41
|
+
|
42
|
+
chrome.runtime.onInstalled.addListener(() => {
|
43
|
+
chrome.contextMenus.create({
|
44
|
+
id: 'BudouX',
|
45
|
+
title: chrome.i18n.getMessage('applyMenuTitle'),
|
46
|
+
contexts: ['all'],
|
47
|
+
});
|
48
|
+
});
|
49
|
+
|
50
|
+
chrome.contextMenus.onClicked.addListener(async (info, tab) => {
|
51
|
+
await applyBudouX(tab, info.frameId);
|
52
|
+
});
|
53
|
+
chrome.action.onClicked.addListener(applyBudouX);
|
@@ -0,0 +1,19 @@
|
|
1
|
+
/**
|
2
|
+
* @license
|
3
|
+
* Copyright 2021 Google LLC
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
import {DocumentApplier} from './document_applier';
|
18
|
+
|
19
|
+
DocumentApplier.fromDocument(document).apply();
|
@@ -0,0 +1,148 @@
|
|
1
|
+
/**
|
2
|
+
* @license
|
3
|
+
* Copyright 2023 Google LLC
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
import {
|
18
|
+
loadDefaultJapaneseParser,
|
19
|
+
loadDefaultParsers,
|
20
|
+
HTMLProcessor,
|
21
|
+
Parser,
|
22
|
+
} from 'budoux';
|
23
|
+
|
24
|
+
const isDebug = false;
|
25
|
+
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
27
|
+
function logDebug(...args: any[]) {
|
28
|
+
if (isDebug) {
|
29
|
+
console.log(...args);
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
export class DocumentApplier {
|
34
|
+
private document: Document;
|
35
|
+
protected separator = '\u200B';
|
36
|
+
private className = 'BudouX';
|
37
|
+
private isClassDefined = false;
|
38
|
+
|
39
|
+
constructor(document: Document) {
|
40
|
+
this.document = document;
|
41
|
+
}
|
42
|
+
|
43
|
+
static fromDocument(document: Document): DocumentApplier {
|
44
|
+
// @ts-expect-error Use a dynamic property of the document.
|
45
|
+
let docApplier = document.budouX;
|
46
|
+
logDebug('fromDocument: ', docApplier);
|
47
|
+
if (!docApplier) {
|
48
|
+
docApplier = new DocumentApplier(document);
|
49
|
+
// @ts-expect-error Use a dynamic property of the document.
|
50
|
+
document.budouX = docApplier;
|
51
|
+
}
|
52
|
+
return docApplier;
|
53
|
+
}
|
54
|
+
|
55
|
+
async apply() {
|
56
|
+
await this.loadSettings();
|
57
|
+
const parser = this.loadParser();
|
58
|
+
const applier = new HTMLProcessor(parser, {
|
59
|
+
className: this.className,
|
60
|
+
separator: this.separator,
|
61
|
+
});
|
62
|
+
|
63
|
+
const document = this.document;
|
64
|
+
await this.waitForDOMContentLoaded(document);
|
65
|
+
|
66
|
+
this.ensureClass();
|
67
|
+
applier.applyToElement(document.body);
|
68
|
+
}
|
69
|
+
|
70
|
+
private loadParser(): Parser {
|
71
|
+
const document = this.document;
|
72
|
+
const element = document.body ?? document.documentElement;
|
73
|
+
let lang = DocumentApplier.langFromElement(element);
|
74
|
+
lang = DocumentApplier.normalizeLocale(lang);
|
75
|
+
if (lang) {
|
76
|
+
const parsers = loadDefaultParsers();
|
77
|
+
const parser = parsers.get(lang);
|
78
|
+
if (parser) return parser;
|
79
|
+
}
|
80
|
+
console.warn(`No parser for "${lang}", using the Japanese parser.`);
|
81
|
+
return loadDefaultJapaneseParser();
|
82
|
+
}
|
83
|
+
|
84
|
+
protected async loadSettings() {
|
85
|
+
if ('chrome' in window && 'storage' in chrome) {
|
86
|
+
await new Promise<void>(resolve => {
|
87
|
+
chrome.storage.sync.get(
|
88
|
+
{
|
89
|
+
separator: this.separator,
|
90
|
+
},
|
91
|
+
items => {
|
92
|
+
this.separator = items.separator;
|
93
|
+
resolve();
|
94
|
+
}
|
95
|
+
);
|
96
|
+
});
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
private ensureClass(): void {
|
101
|
+
if (this.isClassDefined || !this.className) return;
|
102
|
+
this.isClassDefined = true;
|
103
|
+
|
104
|
+
const document = this.document;
|
105
|
+
const styleElement = document.createElement('style');
|
106
|
+
styleElement.textContent = `.${this.className} { word-break: keep-all; overflow-wrap: anywhere; }`;
|
107
|
+
document.head.appendChild(styleElement);
|
108
|
+
}
|
109
|
+
|
110
|
+
static normalizeLocale(locale?: string): string | undefined {
|
111
|
+
if (!locale) return undefined;
|
112
|
+
let subtags = locale.split('-');
|
113
|
+
if (!subtags.length) return undefined;
|
114
|
+
// The first subtag is the language.
|
115
|
+
const lang = subtags[0].toLowerCase();
|
116
|
+
if (lang === 'zh') {
|
117
|
+
// `zh` requires the script subtag.
|
118
|
+
subtags = subtags.slice(1);
|
119
|
+
for (const subtag of subtags) {
|
120
|
+
if (subtag.match(/^han[st]$/i))
|
121
|
+
return `${lang}-${subtag.toLowerCase()}`;
|
122
|
+
}
|
123
|
+
// If neither `hans` nor `hant`, check the region or the macrolanguage.
|
124
|
+
for (const subtag of subtags) {
|
125
|
+
if (subtag.match(/^(hk|mo|tw|hak|lzh|nan|yue)$/i)) return 'zh-hant';
|
126
|
+
}
|
127
|
+
return 'zh-hans';
|
128
|
+
}
|
129
|
+
return lang;
|
130
|
+
}
|
131
|
+
|
132
|
+
static langFromElement(element: HTMLElement | null): string | undefined {
|
133
|
+
for (; element; element = element.parentElement) {
|
134
|
+
const lang = element.lang;
|
135
|
+
if (lang) return lang;
|
136
|
+
}
|
137
|
+
return undefined;
|
138
|
+
}
|
139
|
+
|
140
|
+
async waitForDOMContentLoaded(document: Document) {
|
141
|
+
logDebug('waitForDOMContentLoaded: ', document.readyState);
|
142
|
+
if (document.readyState !== 'loading') return;
|
143
|
+
await new Promise<void>(resolve => {
|
144
|
+
document.addEventListener('DOMContentLoaded', () => resolve());
|
145
|
+
});
|
146
|
+
logDebug('DOMContentLoaded: ', document.readyState);
|
147
|
+
}
|
148
|
+
}
|
@@ -0,0 +1,109 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
|
4
|
+
<head>
|
5
|
+
<meta charset="utf-8">
|
6
|
+
<link
|
7
|
+
href="https://fonts.googleapis.com/css?family=Google+Sans:400,500,700&display=swap&lang=en"
|
8
|
+
rel="stylesheet">
|
9
|
+
<style>
|
10
|
+
:root {
|
11
|
+
--mdc-theme-primary: #9c27b0;
|
12
|
+
--mdc-theme-secondary: #64dd17;
|
13
|
+
height: 100%;
|
14
|
+
user-select: none;
|
15
|
+
}
|
16
|
+
|
17
|
+
body {
|
18
|
+
align-items: center;
|
19
|
+
background: #ede7f6;
|
20
|
+
display: flex;
|
21
|
+
font-family: 'Google Sans', sans-serif;
|
22
|
+
height: 100%;
|
23
|
+
justify-content: center;
|
24
|
+
margin: 0;
|
25
|
+
padding: 0 1rem;
|
26
|
+
}
|
27
|
+
|
28
|
+
section {
|
29
|
+
background: #fff;
|
30
|
+
border-radius: 0.5rem;
|
31
|
+
box-shadow: 0 2px 4px rgba(0, 0, 0, .2);
|
32
|
+
box-sizing: border-box;
|
33
|
+
max-width: 460px;
|
34
|
+
padding: 2rem;
|
35
|
+
width: 100%;
|
36
|
+
}
|
37
|
+
|
38
|
+
h1 {
|
39
|
+
font-family: 'Google Sans', sans-serif;
|
40
|
+
font-size: 1.5rem;
|
41
|
+
font-weight: 500;
|
42
|
+
line-height: 3rem;
|
43
|
+
margin: 0;
|
44
|
+
}
|
45
|
+
|
46
|
+
p {
|
47
|
+
align-items: center;
|
48
|
+
display: flex;
|
49
|
+
line-height: 1.5rem;
|
50
|
+
margin: 1rem 0;
|
51
|
+
}
|
52
|
+
|
53
|
+
.button-container {
|
54
|
+
margin-top: 2rem;
|
55
|
+
}
|
56
|
+
|
57
|
+
mwc-formfield {
|
58
|
+
/* Prevent wrapping of label text on e.g., Windows */
|
59
|
+
word-break: keep-all;
|
60
|
+
}
|
61
|
+
|
62
|
+
mwc-textfield {
|
63
|
+
margin-left: 1rem;
|
64
|
+
}
|
65
|
+
|
66
|
+
.powered-by {
|
67
|
+
align-self: flex-end;
|
68
|
+
margin-left: auto;
|
69
|
+
}
|
70
|
+
</style>
|
71
|
+
|
72
|
+
</head>
|
73
|
+
|
74
|
+
<body>
|
75
|
+
<section>
|
76
|
+
<h1>BudouX Chrome Extension 🍇</h1>
|
77
|
+
<p>
|
78
|
+
<mwc-formfield label="__MSG_insertZwSpace__">
|
79
|
+
<mwc-radio id="zwsp" name="separator" value="​"></mwc-radio>
|
80
|
+
</mwc-formfield>
|
81
|
+
</p>
|
82
|
+
<p>
|
83
|
+
<mwc-formfield label="__MSG_insertSpace__">
|
84
|
+
<mwc-radio id="space" name="separator" value=" "></mwc-radio>
|
85
|
+
</mwc-formfield>
|
86
|
+
</p>
|
87
|
+
<p>
|
88
|
+
<mwc-formfield label="__MSG_insertIdeoSpace__">
|
89
|
+
<mwc-radio id="idsp" name="separator" value=" "></mwc-radio>
|
90
|
+
</mwc-formfield>
|
91
|
+
</p>
|
92
|
+
<p>
|
93
|
+
<mwc-formfield label="__MSG_insertUserText__">
|
94
|
+
<mwc-radio id="other" name="separator" value="other"></mwc-radio>
|
95
|
+
</mwc-formfield>
|
96
|
+
<mwc-textfield id="separatorText" outlined></mwc-textfield>
|
97
|
+
</p>
|
98
|
+
<p class="button-container">
|
99
|
+
<mwc-button raised id="save" type="submit" label="__MSG_save__"></mwc-button>
|
100
|
+
<span class="powered-by">
|
101
|
+
Powered by
|
102
|
+
<a href="https://github.com/google/budoux" target="_blank">BudouX</a>
|
103
|
+
</span>
|
104
|
+
</p>
|
105
|
+
</section>
|
106
|
+
<script src="options.js"></script>
|
107
|
+
</body>
|
108
|
+
|
109
|
+
</html>
|
@@ -0,0 +1,92 @@
|
|
1
|
+
/**
|
2
|
+
* @license
|
3
|
+
* Copyright 2021 Google LLC
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
import '@material/mwc-radio';
|
18
|
+
import '@material/mwc-button';
|
19
|
+
import '@material/mwc-formfield';
|
20
|
+
import '@material/mwc-textfield';
|
21
|
+
import {Radio} from '@material/mwc-radio';
|
22
|
+
import {TextField} from '@material/mwc-textfield';
|
23
|
+
import {Button} from '@material/mwc-button';
|
24
|
+
|
25
|
+
const zwsp = document.getElementById('zwsp') as Radio;
|
26
|
+
const idsp = document.getElementById('idsp') as Radio;
|
27
|
+
const space = document.getElementById('space') as Radio;
|
28
|
+
const presets = [zwsp, idsp, space];
|
29
|
+
const other = document.getElementById('other') as Radio;
|
30
|
+
const separatorText = document.getElementById('separatorText') as TextField;
|
31
|
+
const saveButton = document.getElementById('save') as Button;
|
32
|
+
|
33
|
+
function checkOtherIfNeeded() {
|
34
|
+
if (separatorText.value) other.checked = true;
|
35
|
+
}
|
36
|
+
|
37
|
+
function getSeparator() {
|
38
|
+
for (const preset of presets) {
|
39
|
+
if (preset.checked) return preset.value;
|
40
|
+
}
|
41
|
+
return separatorText.value;
|
42
|
+
}
|
43
|
+
|
44
|
+
function setSeparator(separator: string) {
|
45
|
+
for (const preset of presets) {
|
46
|
+
if (separator === preset.value) {
|
47
|
+
preset.checked = true;
|
48
|
+
return;
|
49
|
+
}
|
50
|
+
}
|
51
|
+
other.checked = true;
|
52
|
+
separatorText.value = separator;
|
53
|
+
}
|
54
|
+
|
55
|
+
function saveOptions() {
|
56
|
+
chrome.storage.sync.set({
|
57
|
+
separator: getSeparator(),
|
58
|
+
});
|
59
|
+
}
|
60
|
+
|
61
|
+
function restoreOptions() {
|
62
|
+
chrome.storage.sync.get(
|
63
|
+
{
|
64
|
+
separator: '\u200B',
|
65
|
+
},
|
66
|
+
items => {
|
67
|
+
setSeparator(items.separator);
|
68
|
+
}
|
69
|
+
);
|
70
|
+
}
|
71
|
+
|
72
|
+
function localizeString(str: string): string {
|
73
|
+
return str.replace(/__MSG_(\w+)__/g, (match, name) =>
|
74
|
+
name ? chrome.i18n.getMessage(name) : ''
|
75
|
+
);
|
76
|
+
}
|
77
|
+
|
78
|
+
function localize() {
|
79
|
+
for (const element of document.querySelectorAll(
|
80
|
+
'mwc-button, mwc-formfield'
|
81
|
+
)) {
|
82
|
+
const label = element.getAttribute('label');
|
83
|
+
if (label) {
|
84
|
+
element.setAttribute('label', localizeString(label));
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
localize();
|
90
|
+
document.addEventListener('DOMContentLoaded', restoreOptions);
|
91
|
+
saveButton.addEventListener('click', saveOptions);
|
92
|
+
separatorText.addEventListener('input', checkOtherIfNeeded);
|
@@ -0,0 +1,17 @@
|
|
1
|
+
/**
|
2
|
+
* @license
|
3
|
+
* Copyright 2023 Google LLC
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
import './test_document_applier.js';
|