Skip to content

[Feature] Add alternative service endpoint URLs #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ options argument is an optional object of following fields:

```javascript
var options = {
width : 800, //int, width of the writing area, default: undefined
height : 800, //int, height of the writing area, default: undefined
language : "zh_TW", //string, language of input trace, default: "zh_TW"
numOfWords : 1, //int, number of words of input trace, default: undefined
numOfReturn : 5, //int, number of maximum returned results, default: undefined
width : 800, //int, width of the writing area, default: undefined
height : 800, //int, height of the writing area, default: undefined
language : "zh_TW", //string, language of input trace, default: "zh_TW"
serviceEndpoint: "google_tw", //string, service endpoint URL used, default: "default"
numOfWords : 1, //int, number of words of input trace, default: undefined
numOfReturn : 5, //int, number of maximum returned results, default: undefined
};
```

Expand Down Expand Up @@ -177,6 +178,18 @@ Note that, even included handwriting.canvas.js now, the previous way of calling

so that you can take advantage of the **handwriting.canvas** object, while not changing previous code.

---
<h3 id="serviceEndpointUrl">Supported Service Endpoint URLs</h3>

| code | URL |
|------------|---------------------------------------------------------------------------------------------|
| default | https://www.google.com.tw/inputtools/request?ime=handwriting&app=mobilesearch&cs=1&oe=UTF-8 |
| google_tw | https://www.google.com.tw/inputtools/request?ime=handwriting |
| google_jp | https://www.google.co.jp/inputtools/request?ime=handwriting |
| google_kr | https://www.google.co.kr/inputtools/request?ime=handwriting |
| google | https://www.google.com/inputtools/request?ime=handwriting |
| inputtools | https://inputtools.google.com/request?ime=handwriting |

---
<h3 id="language">Supported Language</h3>

Expand Down
10 changes: 9 additions & 1 deletion handwriting.canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@
options = this.options;
callback = this.callback;
} else if (!options) options = {};
var serviceEndpointURLs = {
"default": "https://www.google.com.tw/inputtools/request?ime=handwriting&app=mobilesearch&cs=1&oe=UTF-8",
"google_tw": "https://www.google.com.tw/inputtools/request?ime=handwriting",
"google_jp": "https://www.google.co.jp/inputtools/request?ime=handwriting",
"google_kr": "https://www.google.co.kr/inputtools/request?ime=handwriting",
"google": "https://www.google.com/inputtools/request?ime=handwriting",
"inputtools": "https://inputtools.google.com/request?ime=handwriting"
}
var data = JSON.stringify({
"options": "enable_pre_space",
"requests": [{
Expand Down Expand Up @@ -240,7 +248,7 @@

}
});
xhr.open("POST", "https://www.google.com.tw/inputtools/request?ime=handwriting&app=mobilesearch&cs=1&oe=UTF-8");
xhr.open("POST", serviceEndpointURLs[options.serviceEndpoint] || serviceEndpointURLs["default"]);
xhr.setRequestHeader("content-type", "application/json");
xhr.send(data);
};
Expand Down
10 changes: 9 additions & 1 deletion handwriting.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
options = this.options;
callback = this.callback;
} else if (!options) options = {};
var serviceEndpointURLs = {
"default": "https://www.google.com.tw/inputtools/request?ime=handwriting&app=mobilesearch&cs=1&oe=UTF-8",
"google_tw": "https://www.google.com.tw/inputtools/request?ime=handwriting",
"google_jp": "https://www.google.co.jp/inputtools/request?ime=handwriting",
"google_kr": "https://www.google.co.kr/inputtools/request?ime=handwriting",
"google": "https://www.google.com/inputtools/request?ime=handwriting",
"inputtools": "https://inputtools.google.com/request?ime=handwriting"
}
var data = JSON.stringify({
"options": "enable_pre_space",
"requests": [{
Expand Down Expand Up @@ -61,7 +69,7 @@

}
});
xhr.open("POST", "https://www.google.com.tw/inputtools/request?ime=handwriting&app=mobilesearch&cs=1&oe=UTF-8");
xhr.open("POST", serviceEndpointURLs[options.serviceEndpoint] || serviceEndpointURLs["default"]);
xhr.setRequestHeader("content-type", "application/json");
xhr.send(data);
};
Expand Down