Add webpage demo, Tweak code for it, Add build script, Add screenshot, Update README

This commit is contained in:
octospacc 2024-12-01 16:32:32 +01:00
parent 7c84f82f3c
commit 8c62d57691
8 changed files with 109 additions and 21 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
web-ext-artifacts/

View File

@ -1,12 +1,25 @@
# nekotsume IME | ネコツメIME
Efficient Japanese IME for (almost) any website in your web browser!
_nekotsume IME_ is an efficient and privacy-friendly Japanese IME for (almost) any website in your web browser. It works fully locally: what you type is never sent on the Internet and stays private. With this, it's also pretty fast, and the suggestions dictionary should be decent.
<!-- TODO: Features and Usage -->
![](screenshot.png)
<!-- TODO, complete: Features, Usage general/WebExtension/webpage -->
## Usage
General:
* You can toggle the IME to ON [あ] to enable conversion of for all standard text input fields (`<input type="text">` and `<textarea>`) of the current window, and to OFF [A] to disable conversion and write normally.
* When the IME is enabled, type lowecase latin letters to have them converted to hiragana characters. Press ENTER to accept a direct conversion, or press SPACE to show other options (kanji, etc.).
Browser Extension:
* The IME can be toggled ON and OFF by clicking the extension button in your browser's toolbar (for your comfort, please pin it). A textual tooltip indicates the current status of the IME: [あ] with blue background when enabled, [A] with gray background when disabled.
## Building from Source
The core code is not compiled and doesn't need to be. However, it uses open-source third-party dependencies that may provide their own build procedures for the following library files:
The core code is not compiled and doesn't need to be. However, it uses open-source third-party dependencies that require their own build procedures for the following library files:
Require compilation, and can optionally be minified:
@ -18,15 +31,18 @@ Don't require any compilation, but can optionally be minified:
To prepare the dependencies:
1. Init Git submodules (or clone the above Git repositories in the `lib/` directory)
2. Manually follow the libraries instructions to setup a build environment and complete the process
0. You will need a POSIX-compliant shell and NodeJS on your build system, and this repository cloned
1. Make sure to init Git submodules (or clone the above Git repositories in the `lib/` directory)
2. Manually follow the libraries' instructions to setup a build environment and complete the process
3. Copy the respective built files to the paths specified above
Alternatively, if requirements are met, you can just run the `build.sh` script and it should perform all the steps automatically, including building a ZIP/XPI file for the WebExtension distribution.
## Copyright Notice
_nekotsume IME_ is forked and readapted to work as a Web Extension from _IgoIME_ by shogo82148 (Ichinose Shogo): <https://github.com/shogo82148/IgoIME>. _IgoIME_ is based on _Ajax IME_ by taku (Taku Kudo).
They are not legally open-source, as _Ajax IME_ is available only under the terms of: `(C) Taku Kudo, all rights reserve rd. Personal use only!`
_nekotsume IME_ is only being distributed in good faith and in the spirit of the fair use doctrine, in the hopes that it can be useful.
_nekotsume IME_ is only being distributed in good faith and in the spirit of the fair use doctrine, in the hopes that it can be useful, but without any warranty.

23
build.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/sh
set -e
# Get dependencies
git submodule update --init --recursive
# Build lib/igo.min.js
cd lib/igo-javascript
npm install
cd build
node build.js
cp igo.min.js ../../igo.min.js
cd ../../..
# Build lib/zip.min.js
cd lib/zipjs
echo 'Uin32Array=Uint32Array;' > ../zip.min.js
cat zip.js jsinflate.js sjis.js >> ../zip.min.js
cd ../..
# Build WebExtension package
npm install web-ext
web-ext build --overwrite-dest --ignore-files *.xcf lib/*/

44
demo.html Normal file
View File

@ -0,0 +1,44 @@
<!DOCTYPE html>
<html>
<head>
<title>nekotsume IME Demo</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,minimum-scale=1" />
<script src="lib/igo.min.js"></script>
<script src="lib/zip.min.js"></script>
<script src="loader.js"></script>
<script src="ime.js"></script>
<style>
* { box-sizing: border-box; }
textarea { width: 100%; }
</style>
</head>
<body>
<h1>nekotsume IME | ネコツメIME</h1>
<p>
Efficient Japanese IME for (almost) any website in your web browser!
<br />
For more information please visit the Git repository:
<a href="https://gitlab.com/octospacc/nekotsume-ime">https://gitlab.com/octospacc/nekotsume-ime</a>.
</p>
<h2>Demo</h2>
<p>
IME Status: <span name="ImeStatus">Loading</span>
<button name="ToggleIme">Toggle IME</button>
</p>
<textarea placeholder="Write anything..."></textarea>
<script>
function setImeStatusLabel () {
document.querySelector('span[name="ImeStatus"]').textContent = {
true: "ON [あ]",
false: "OFF [A]",
}[ImeEnabled_];
}
document.querySelector('button[name="ToggleIme"]').onclick = function(){
ImeChangeMode();
setImeStatusLabel();
};
setImeStatusLabel();
</script>
</body>
</html>

26
ime.js
View File

@ -177,7 +177,7 @@ function AjaxIME(doc) {
ImeDocument_.ImeRequestCallback = ImeRequestCallback;
ImeDocument_.ImeChangeMode = ImeChangeMode;
addEvent(ImeDocument_, 'keydown', ImeDocumentKeyDown);
//addEvent(ImeDocument_, 'keydown', ImeDocumentKeyDown);
addEvent(ImePreEdit_, 'keydown', ImePreEditKeyDown);
addEvent(ImePreEdit_, 'keyup', ImePreEditKeyUp);
@ -682,15 +682,17 @@ function ImeRequestCallback(result, source) {
ImeCurrentDocument_.ImeRequestCallback(result, source);
}
browser.runtime.onMessage.addListener(function(data){
if (data.browserAction) {
ImeInit();
if (!ImeEnabled_ || data.browserAction === 'ImeChangeMode') {
ImeChangeMode();
}
return;
}
ImeRequestCallback(data.result, data.source);
});
addEvent(window, 'load', ImeInit);
if (typeof browser !== 'undefined' && typeof browser.runtime !== 'undefined' && typeof browser.runtime.onMessage !== 'undefined') {
browser.runtime.onMessage.addListener(function(data){
if (data.browserAction) {
ImeInit();
if (!ImeEnabled_ || data.browserAction === 'ImeChangeMode') {
ImeChangeMode();
}
return;
}
ImeRequestCallback(data.result, data.source);
});
}

View File

@ -30,7 +30,7 @@ function initRuntime () {
}
var worker = new Worker('worker.js');
igo.getServerFileToArrayBufffer("skkdic.zip", function(buffer){
igo.getServerFileToArrayBufffer('skkdic.bin', function(buffer){
event({event: 'downloaded'});
var blob = new Blob([new Uint8Array(buffer)]);
worker.postMessage({method: 'setdic', dic: blob});
@ -46,7 +46,9 @@ function initRuntime () {
postToWorker = function(data) {
worker.postMessage(data);
}
browser.runtime.onMessage.addListener(postToWorker);
if (typeof browser !== 'undefined' && typeof browser.runtime !== 'undefined' && typeof browser.runtime.onMessage !== 'undefined') {
browser.runtime.onMessage.addListener(postToWorker);
}
}
if (document.readyState === 'loading') {
@ -55,4 +57,4 @@ if (document.readyState === 'loading') {
initRuntime();
}
})();
})();

BIN
screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB