Vocab list (separated by ',') generator -- add reading and meaning

Use this to kill Item Marker / Leeches.

Item Marker
Leeches via Stat site
Leeches via Leech Detector

Dropbox - listVocab-sep-noproxy.htm - Simplify your life (No-proxy version. – will need to be downloaded to My Computer.)

It now auto-replace every needed things, so no need to overwork yourself.

////

Hosted by @alexbeldan
http://www.oceanofsound.net/misc/japanese/listVocab-sep.html?proxy=http://crossorigin.me/
http://www.oceanofsound.net/misc/japanese/listVocab-sep.html?proxy=https://cors-anywhere.herokuapp.com/
(both are Javascript-enabled, but with different proxy.)

Hosted by @rfindley
I’ve moved the autoconvert to a url parameter: convert=auto
https://www.idigtech.com/wanikani/vocab-sep/?convert=auto&proxy=https://cors-anywhere.herokuapp.com/

////

Use this to kill Item Marker / Leeches.

I also attempted to make LeechKiller for Kanji, here: Dropbox - Kanji LeechKiller - Simplify your life which is some complicated Python chuck.

For Kanji list separated by \n.


I have just started playing with HTML requests in JavaScript yesterday, but I couldn’t find a way to make use of anything other than WaniKani API. I want to make use of JMDict or other similar things.

For example, I want to convert

余計,倒す,倒産,妨害,機械,災難

into

Could you please help me, or at least educate me?

教えてください。

Assuming you’re okay with using jQuery…

Jisho.org has an API that you can use, and it’s based on jmdict.

// We'll use a cross-origin proxy, since jisho.org doesn't have a CORS policy,
// which means browsers will block the query since it's not from the same location
// that our script is running.
var proxy = 'https://crossorigin.me/';
var word = '余計';
var url = proxy + 'http://jisho.org/api/v1/search/words?keyword=' + word;

// Run the query.  When the requested document is loaded,
// the callback function "process_result()" will be called, 
$.getJSON(url, process_result);

// Here's the callback function that receives the response from our query
function process_result(json) {
  // Grab the first kanji orthography from the first search result.
  var word = json.data[0].japanese[0].word;

  // Grab the first reading from the first search result
  var reading = json.data[0].japanese[0].reading;

  // Grab the first meaning from the first sense of the word
  var meaning = json.data[0].senses[0].english_definitions[0];

  console.log(word+';'+reading+';'+meaning);
}

Here’s the format of a returned sample query:

Expand for Jisho result... ```javascript { "meta": { "status": 200 }, "data": [{ "is_common": true, "tags": ["wanikani20"], "japanese": [{ "word": "余計", "reading": "よけい" }], "senses": [{ "english_definitions": ["too many", "too much", "excessive", "superfluous", "superabundant", "extra", "spare", "surplus"], "parts_of_speech": ["Na-adjective", "Noun"], "links": [], "tags": [], "restrictions": [], "see_also": [], "antonyms": [], "source": [], "info": ["often as 余計に"] }, { "english_definitions": ["unnecessary", "needless", "uncalled-for", "otiose"], "parts_of_speech": ["Na-adjective", "No-adjective", "Noun"], "links": [], "tags": [], "restrictions": [], "see_also": [], "antonyms": [], "source": [], "info": [] }, { "english_definitions": ["abundantly", "excessively", "needlessly", "all the more"], "parts_of_speech": ["Adverb"], "links": [], "tags": [], "restrictions": [], "see_also": [], "antonyms": [], "source": [], "info": [] }], "attribution": { "jmdict": true, "jmnedict": false, "dbpedia": false } }, { "is_common": false, "tags": [], "japanese": [{ "word": "余計なお世話", "reading": "よけいなおせわ" }, { "word": "よけいなお世話", "reading": "よけいなおせわ" }, { "word": "余計な御世話", "reading": "よけいなおせわ" }], "senses": [{ "english_definitions": ["it's none of your business", "it's not your concern"], "parts_of_speech": ["Expression"], "links": [], "tags": [], "restrictions": [], "see_also": [], "antonyms": [], "source": [], "info": [] }], "attribution": { "jmdict": true, "jmnedict": false, "dbpedia": false } }, { "is_common": false, "tags": [], "japanese": [{ "word": "余計者", "reading": "よけいもの" }], "senses": [{ "english_definitions": ["person whose presence is unwelcome, unnecessary or a nuisance", "fifth wheel", "third wheel", "interloper"], "parts_of_speech": ["Noun"], "links": [], "tags": [], "restrictions": [], "see_also": [], "antonyms": [], "source": [], "info": [] }, { "english_definitions": ["Superfluous man"], "parts_of_speech": ["Wikipedia definition"], "links": [{ "text": "Read “Superfluous man” on English Wikipedia", "url": "http://en.wikipedia.org/wiki/Superfluous_man?oldid=492561516" }, { "text": "Read “余計者” on Japanese Wikipedia", "url": "http://ja.wikipedia.org/wiki/余計者?oldid=42376303" }], "tags": [], "restrictions": [], "see_also": [], "antonyms": [], "source": [], "info": [], "sentences": [] }], "attribution": { "jmdict": true, "jmnedict": false, "dbpedia": "http://dbpedia.org/resource/Superfluous_man" } }, { "is_common": false, "tags": [], "japanese": [{ "word": "余計な御世話", "reading": "よけいなおせわ" }], "senses": [{ "english_definitions": ["Mind your own business"], "parts_of_speech": ["Expression"], "links": [], "tags": ["Idiomatic expression"], "restrictions": [], "see_also": [], "antonyms": [], "source": [], "info": [] }], "attribution": { "jmdict": true, "jmnedict": false, "dbpedia": false } }, { "is_common": false, "tags": [], "japanese": [{ "word": "余計な世話を焼く", "reading": "よけいなせわをやく" }], "senses": [{ "english_definitions": ["to poke one's nose (in) where one is not wanted"], "parts_of_speech": ["Expression", "Godan verb with ku ending"], "links": [], "tags": [], "restrictions": [], "see_also": [], "antonyms": [], "source": [], "info": [] }], "attribution": { "jmdict": true, "jmnedict": false, "dbpedia": false } }] } ```

And the console output from the code above is:

余計;よけい;too many
1 Like

Sorry if I know too little about JSON.

For $.getJSON(url, process_result), I get [object Object].
For $.getJSON(url, process_result).data, I get undefined.
For $.getJSON(url, process_result).data[0].japanese[0].word, I get

TypeError: undefined is not an object (evaluating ‘$.getJSON(url, process_result).data’)

For $.getJSON(url, process_result).word, I get undefined.

How do I access the JSON data structure?

What are you using to run your javascript? Node.js? A browser?

The reason I ask: I noticed that the jisho.org API doesn’t have a CORS (i.e. cross-origin) policy, meaning browsers won’t allow the JSON to be accepted unless the script is running while on jisho.org.


EDIT: If you’re in a browser, you can get around this by using a cross-origin proxy, such as crossorigin.me.

For example, instead of:

   http://jisho.org/api/v1/search/words?keyword=余計

use this:

   https://crossorigin.me/http://jisho.org/api/v1/search/words?keyword=余計

$.getJSON() doesn’t return the JSON object. It only starts the query, and returns immediately.
When the query is complete, the callback function process_result() will be called, with the JSON object as the first parameter. Then you can process the JSON from inside the callback.

I’ve updated my code above to use the proxy. I just tested it in the Chrome javascript console, and it works fine.

(Note: if you’re running the script from a page that is http (instead of https), you may need to remove the ‘s’ from the proxy url.)

Success, but I can’t make process_result(json) return the result directly.

I just use

var result = "";

and

result = word+';'+reading+';'+meaning;

Which does work, with a little time lag.

NB. I made it without using a proxy.

Yeah… Since $.getJSON() is an asynchronous function, there’s really no way to create a synchronous function like:

   var result = fetchJishoInfo();

The closest you can get is to use Promises, but that’s not very intuitive:

code ```javascript function fetchJishoInfo(word) { return new Promise(function(resolve, reject){ // We'll use a cross-origin proxy, since jisho.org doesn't have a CORS policy, // which means browsers will block the query since it's not from the same location // that our script is running. var proxy = 'https://crossorigin.me/'; var url = proxy + 'http://jisho.org/api/v1/search/words?keyword=' + word;
// Run the query.  When the requested document is loaded,
// the callback function "process_result()" will be called,
$.getJSON(url)
.done(json => {
  // Grab the first kanji orthography from the first search result.
  var word = json.data[0].japanese[0].word;

  // Grab the first reading from the first search result
  var reading = json.data[0].japanese[0].reading;

  // Grab the first meaning from the first sense of the word
  var meaning = json.data[0].senses[0].english_definitions[0];

  resolve(word+';'+reading+';'+meaning);
})
.fail(error => {
  reject();
});

});
}

// Our list of comma-separated vocabulary.
var vocab = ‘余計,倒す,倒産,妨害,機械,災難’;

// Send out jisho.org requests for ALL of them simultaneously.
var array = vocab.split(‘,’);
Promise.all(array.map(fetchJishoInfo))
.then(values => {
// When all of them are fetched, their values are accessible here in the array ‘values’.
// In this case, we just join them all together with a ‘\n’ between each one, and output to console.
console.log(values.join(‘\n’));
});

</details>
1 Like

Done.

But I don’t know how to host an html file, so if you want to use it, you’ll have to download it to your computer. Use this to kill Item Marker / Leeches.

Item Marker: replace all " \t" with ‘,’
Leeches via Stat site: replace all “Level” with ‘,’

I only slightly read through things. It’s hosted if that helps…
http://www.oceanofsound.net/misc/japanese/listVocab-sep.html

Although it doesn’t seem to do anything on there. I know nothing about what you’re trying to do. If you want I can supply you with your own login and ftp access and you can upload your Japanese projects there @polv.

1 Like

Perhaps it needs:

var proxy = 'https://crossorigin.me/';
var url = proxy + 

So, now I have updated the code.

It seems to be working now.

I wonder if you can tie execute and show together into 1 command. Also, If you what you want to show it continually adds to the output.

Updated. Try uploading again.

I failed to put it into 1 single button, though.

Updated now.

Updated to separated by tab, for easy copying to Excel.

In bed now, but I’ll update it on the morning. Thanks.

FYI, there are some problems when using the proxy. It occasionally returns an error about “service unavailable”, which means you’ll miss some of your vocab if you’re not paying attention.

1 Like

That’s why I personally use non-proxy version. I also have uploaded (for downloading) the non-proxy version.

What about Jisho API for Kanji? Documentation?

Should I specifically host the no proxy version?
Also, I updated to the new one and it’s not working nearly as well. It’s not always displaying and requires many presses on the “show” button.