-
Notifications
You must be signed in to change notification settings - Fork 1
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
0 parents
commit 9349f9e
Showing
27 changed files
with
12,923 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!DOCTYPE HTML> | ||
<html lang="en"> | ||
<head> | ||
<title>Sugoi Web Translation</title> | ||
<meta content="text/html; charset=utf-8"> | ||
<script src="../js/vendor/vue.js"></script> | ||
</head> | ||
<body style="width: 400px;"> | ||
<div id="app"> | ||
<div> | ||
<label> | ||
Enabled: <input type="checkbox" v-model="enabled"> | ||
</label> | ||
</div> | ||
<div> | ||
<label> | ||
Always Translate: <input type="checkbox" v-model="alwaysTranslate"> | ||
</label> | ||
</div> | ||
<div> | ||
<label> | ||
Server Port: | ||
<input name="port" type="number" v-model="port" min="1"> | ||
</label> | ||
</div> | ||
<div> | ||
<label> | ||
Concurrent Requests: | ||
<input name="requests" type="number" v-model="requests" min="1"> | ||
</label> | ||
</div> | ||
</div> | ||
|
||
<textarea id="output" style="width: 100%; height: 500px;"> | ||
|
||
</textarea> | ||
|
||
<script> | ||
const html = document.getElementById('app').innerHTML; | ||
const compiled = Vue.compile('<div>' + html + '</div>'); | ||
console.log(compiled.render); | ||
document.getElementById('output').value = compiled.render.toString(); | ||
</script> | ||
</body> | ||
</html> |
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,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
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,3 @@ | ||
.idea | ||
!build | ||
.hg |
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,3 @@ | ||
.idea | ||
!build | ||
.git |
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,14 @@ | ||
# Sugoi-web | ||
Chrome extension: translates pages using Sugoi Offline Translation Server | ||
|
||
To install: | ||
1. Download the "sugoi-web" archive from Releases | ||
2. Unpack the archive | ||
3. Open "chrome://extensions/" | ||
4. Enable "Developer Mode" | ||
5. Add extension using the "Load Unpacked" button | ||
|
||
Recommended to update server to support long lines: | ||
1. Download the "server" archive from Releases | ||
2. Unpack the archive | ||
3. Copy files with overwrite to "backendServer / Program-Backend / Sugoi-Japanese-Translator / offlineTranslation / fairseq" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,43 @@ | ||
'use strict'; | ||
|
||
function button_toggle(tab_id, enable) | ||
{ | ||
chrome.action.enable(tab_id); | ||
/* | ||
chrome.action.setIcon({ | ||
path: enable ? 'images/icon32.png' : 'images/icon32_off.png' | ||
}); | ||
*/ | ||
} | ||
|
||
/** | ||
* | ||
* @param {any} data | ||
* @param {MessageSender} sender | ||
* @param {function} sendResponse | ||
*/ | ||
function processMessage(data, sender, sendResponse) | ||
{ | ||
console.log('message:', data, sender); | ||
|
||
let response; | ||
switch (data.action) | ||
{ | ||
case 'show': | ||
button_toggle(sender.tab.id, true); | ||
response = {success: true}; | ||
break; | ||
case 'hide': | ||
button_toggle(sender.tab.id, false); | ||
response = {success: true}; | ||
break; | ||
default: | ||
console.error('Unknown request:', data); | ||
response = {success: false}; | ||
break; | ||
} | ||
|
||
sendResponse(response); | ||
} | ||
|
||
chrome.runtime.onMessage.addListener(processMessage); |
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,103 @@ | ||
'use strict'; | ||
|
||
class ChromeApi | ||
{ | ||
/** | ||
* | ||
* @type {[function]} | ||
* @private | ||
*/ | ||
_changedListeners = []; | ||
|
||
constructor() | ||
{ | ||
chrome.storage.onChanged.addListener((changes, namespace) => this._processStorageChanged(changes, namespace)); | ||
} | ||
|
||
/** | ||
* | ||
* @param {object} changes | ||
* @param {string} namespace | ||
* @private | ||
*/ | ||
_processStorageChanged(changes, namespace) | ||
{ | ||
this._changedListeners.forEach(x => x(changes, namespace)); | ||
} | ||
|
||
/** | ||
* | ||
* @param {string} key | ||
* @returns {Promise<object>} | ||
*/ | ||
async storageGet(key) | ||
{ | ||
return new Promise(resolve => { | ||
chrome.storage.local.get([key], response => { | ||
resolve(response[key] ?? null); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* | ||
* @param {object} data | ||
* @returns {Promise<any>} | ||
*/ | ||
async storageSet(data) | ||
{ | ||
return new Promise(resolve => { | ||
chrome.storage.local.set(data, response => { | ||
resolve(response); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* | ||
* @returns {Promise<Config>} | ||
*/ | ||
async getConfig() | ||
{ | ||
return this.storageGet('config'); | ||
} | ||
|
||
/** | ||
* | ||
* @param {Config} config | ||
* @returns {Promise<any>} | ||
*/ | ||
async setConfig(config) | ||
{ | ||
return this.storageSet({config: config}); | ||
} | ||
|
||
/** | ||
* | ||
* @param {function} listener | ||
*/ | ||
onStorageChanged(listener) | ||
{ | ||
this._changedListeners.push(listener); | ||
} | ||
|
||
/** | ||
* | ||
* @param {any} request | ||
* @returns {Promise<any>} | ||
*/ | ||
async send(request) | ||
{ | ||
return chrome.runtime.sendMessage(request); | ||
} | ||
|
||
/** | ||
* | ||
* @param {object} query | ||
* @returns {Promise<object>} | ||
*/ | ||
async tabsFind(query) | ||
{ | ||
return chrome.tabs.query(query); | ||
} | ||
} |
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,26 @@ | ||
class Config | ||
{ | ||
/** | ||
* | ||
* @type {boolean} | ||
*/ | ||
enabled = true; | ||
|
||
/** | ||
* | ||
* @type {boolean} | ||
*/ | ||
alwaysTranslate = false; | ||
|
||
/** | ||
* | ||
* @type {string} | ||
*/ | ||
port = '14366'; | ||
|
||
/** | ||
* | ||
* @type {number} | ||
*/ | ||
requests = 10; | ||
} |
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,141 @@ | ||
'use strict'; | ||
|
||
class Translator | ||
{ | ||
_domains = { | ||
'.syosetu.com': () => new ProxySyosetu(), | ||
}; | ||
|
||
/** | ||
* | ||
* @type {string} | ||
* @private | ||
*/ | ||
_url = 'http://127.0.0.1'; | ||
|
||
/** | ||
* | ||
* @type {string} | ||
*/ | ||
port = '14366'; | ||
|
||
/** | ||
* | ||
* @type {number} | ||
*/ | ||
requests = 10; | ||
|
||
/** | ||
* | ||
* @type {string} | ||
*/ | ||
get url() | ||
{ | ||
return this._url + ':' + this.port; | ||
} | ||
|
||
/** | ||
* | ||
* @param domain | ||
* @returns {null|Proxy} | ||
*/ | ||
getProxy(domain) | ||
{ | ||
for (let d in this._domains) | ||
{ | ||
if ((domain === d) || domain.endsWith(d)) | ||
{ | ||
return this._domains[d](); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* | ||
* @returns {Promise<boolean>} | ||
*/ | ||
async serverAvailable() | ||
{ | ||
try | ||
{ | ||
const response = await this._request('test'); | ||
return true; | ||
} | ||
catch (e) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* @param {[TranslatorLine]} lines | ||
* @returns {Promise<void>} | ||
*/ | ||
async run(lines) | ||
{ | ||
/** | ||
* | ||
* @type {Promise<void>[]} | ||
*/ | ||
const promises = []; | ||
let i = 0; | ||
for (i = 0; i < lines.length; i++) | ||
{ | ||
if (i === this.requests) | ||
{ | ||
break; | ||
} | ||
|
||
promises.push(this._translate(lines[i])); | ||
} | ||
|
||
const next = () => { | ||
const p = this._translate(lines[i]); | ||
i += 1; | ||
|
||
return i < lines.length ? p.then(next) : p; | ||
}; | ||
|
||
return await Promise.race(promises).then(next); | ||
} | ||
|
||
/** | ||
* | ||
* @param {TranslatorLine} line | ||
* @returns {Promise<void>} | ||
* @private | ||
*/ | ||
async _translate(line) | ||
{ | ||
line.translation = line.needTranslate | ||
? await this._request(line.original) | ||
: line.original; | ||
} | ||
|
||
/** | ||
* | ||
* @param {string} jpn | ||
* @returns {Promise<string>} | ||
* @private | ||
*/ | ||
async _request(jpn) | ||
{ | ||
const data = { | ||
message: 'translate sentences', | ||
content: jpn | ||
}; | ||
|
||
const response = await fetch(this.url, { | ||
method: 'POST', | ||
body: JSON.stringify(data), | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}); | ||
|
||
return await response.json(); | ||
} | ||
} |
Oops, something went wrong.