Skip to content

Commit

Permalink
Added export/lookup hotkeys to mpv window
Browse files Browse the repository at this point in the history
  • Loading branch information
RicBent committed Nov 19, 2021
1 parent 3f58d60 commit de5c3c3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 17 deletions.
47 changes: 31 additions & 16 deletions migaku_mpv.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
<option>Hidden</option>
</select>

<div id="versionInfo">v0.5.1</div>
<div id="versionInfo">v0.6.0</div>
</div>

<div id="subsList">
Expand Down Expand Up @@ -177,6 +177,14 @@
{
location.reload();
}
else if (cmd == 'e')
{
export_current_card();
}
else if (cmd == 'l')
{
lookup_current();
}
};

// Called when event source is opened
Expand Down Expand Up @@ -786,6 +794,26 @@
})()


function lookup_current() {
if (current_sub_id != null)
{
var current_sub_element = get_sub_element_by_id(current_sub_id);
var unknowns = get_unknowns_container(current_sub_element);

if (unknowns.length > 0)
request_dict_search(unknowns);
}
}


function export_current_card() {
if (current_sub_id != null)
{
var card_data = get_card_data(current_sub_id);
request_cards_export([card_data]);
}
}


// Key event handlers
function on_key_down(evt)
Expand Down Expand Up @@ -840,27 +868,14 @@
// e key, search current line's unknowns
else if (evt.keyCode == 69)
{
if (current_sub_id != null)
{
var current_sub_element = get_sub_element_by_id(current_sub_id);
var unknowns = get_unknowns_container(current_sub_element);

if (unknowns.length > 0)
request_dict_search(unknowns);
}

lookup_current();
evt.preventDefault();
}

// q key, anki card for current line
else if (evt.keyCode == 81)
{
if (current_sub_id != null)
{
var card_data = get_card_data(current_sub_id);
request_cards_export([card_data]);
}

export_current_card();
evt.preventDefault();
}

Expand Down
25 changes: 24 additions & 1 deletion migaku_mpv.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def get_handler_data(socket):
else:
cmd = data[0]

if cmd in ['s', 'r']:
if cmd in ['s', 'r', 'e', 'l']:
send_msg = 'data: ' + data + '\r\n\r\n'
try:
socket.sendall(send_msg.encode())
Expand Down Expand Up @@ -303,6 +303,25 @@ def send_subtitle_time(arg):
data_queues_lock.release()


def browser_export_current():

data_queues_lock.acquire()

for q in data_queues:
q.put('e')

data_queues_lock.release()


def browser_lookup_current():

data_queues_lock.acquire()

for q in data_queues:
q.put('l')

data_queues_lock.release()


def open_webbrowser_new_tab():
url = 'http://' + str(host) + ':' + str(port)
Expand Down Expand Up @@ -810,6 +829,10 @@ def main():
load_and_open_migaku(*event_args[2:10+1])
elif cmd == 'resync':
resync_subtitle(*event_args[2:4+1])
elif cmd == 'export':
browser_export_current()
elif cmd == 'lookup':
browser_lookup_current()

# Close server
server.close()
Expand Down

0 comments on commit de5c3c3

Please sign in to comment.