Skip to content

Commit

Permalink
Load the dictionary from https://skk-dev.github.io/dict/
Browse files Browse the repository at this point in the history
The dictionaries are not available at http://skk-dict-mirror.appspot.com/ any
more.  This change replaces the URL with the ones at
https://skk-dev.github.io/dict.  This is a temporary change and is going to be
configurable so that the user can specify any URLs as they like.

The change also introduces a third party library, pako, for deflating a gzip
file.  This is just a hacky way to introduce a library into the extension and
we need to take advantage of any package system to install the library.
  • Loading branch information
hkurokawa committed Jul 6, 2022
1 parent 78ac54e commit 326337a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
45 changes: 27 additions & 18 deletions extension/dictionary_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ Dictionary.prototype.log = function(obj) {
Dictionary.prototype.doUpdate = function(fs) {
var self = this;
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://skk-dict-mirror.appspot.com/' + this.dictionary_name);
xhr.responseType = 'arraybuffer';
xhr.open('GET', 'https://skk-dev.github.io/dict/' + this.dictionary_name);
self.log({status:'loading'});
xhr.onreadystatechange = function() {
if (xhr.readyState != 4) {
Expand All @@ -95,23 +96,31 @@ Dictionary.prototype.doUpdate = function(fs) {

self.log({status:'loaded'});

self.systemDict = self.parseData(xhr.responseText);
self.log({'status':'parsed'});
fs.root.getFile(
'system-dictionary.json', {create:true}, function(fileEntry) {
fileEntry.createWriter(function(fileWriter) {
fileWriter.onwriteend = function(e) {
var dict_size = 0;
for (var w in self.systemDict) dict_size++;
self.log({'status':'written'});
self.logger = null;
};
var blob = new Blob([JSON.stringify(self.systemDict)],
{'type': 'text/plain'});
fileWriter.write(blob);
var fr = new FileReader;
fr.onloadend = function() {
var response = fr.result;
console.log(response);
self.systemDict = self.parseData(response);
self.log({'status':'parsed'});
fs.root.getFile(
'system-dictionary.json', {create:true}, function(fileEntry) {
fileEntry.createWriter(function(fileWriter) {
fileWriter.onwriteend = function(e) {
var dict_size = 0;
for (var w in self.systemDict) dict_size++;
self.log({'status':'written'});
self.logger = null;
};
var blob = new Blob([JSON.stringify(self.systemDict)],
{'type': 'text/plain'});
fileWriter.write(blob);
});
});
});
};
}
var compressed = new Uint8Array(xhr.response);
var decompressed = pako.inflate(compressed);
fr.readAsText(new Blob([decompressed], {type: "text/plain"}), 'euc-jp');
};
xhr.send();
};

Expand Down Expand Up @@ -170,7 +179,7 @@ Dictionary.prototype.initSystemDictionary = function() {
}

var request = window.requestFileSystem || window.webkitRequestFileSystem;
request(window.TEMPORARY, 50 * 1024 * 1024, onInitFS);
request(window.TEMPORARY, 50 * 1024 * 1024, onInitFS, function(error) { console.error(error); });
};

Dictionary.prototype.lookup = function(reading) {
Expand Down
1 change: 1 addition & 0 deletions extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"roman_modes.js",
"preedit_modes.js",
"conversion_modes.js",
"pako.es5.min.js",
"main.js"
]
},
Expand Down
2 changes: 2 additions & 0 deletions extension/pako.es5.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions testpage/testpage.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<script type="text/javascript" src="../extension/roman_table.js"></script>
<script type="text/javascript" src="../extension/roman_modes.js"></script>
<script type="text/javascript" src="../extension/preedit_modes.js"></script>
<script type="text/javascript" src="../extension/pako.es5.min.js"></script>
<script type="text/javascript" src="../extension/main.js"></script>
</head>
<body>
Expand Down

0 comments on commit 326337a

Please sign in to comment.