[~] Refactor
This commit is contained in:
parent
fd6378a643
commit
392faf5526
@ -1,7 +1,9 @@
|
|||||||
(async function() {
|
(async function() {
|
||||||
await context.loading.script.promise;
|
await context.loading.script.promise;
|
||||||
|
|
||||||
window.context.books.push(`
|
window.context.books.push({
|
||||||
|
url: null,
|
||||||
|
text: `
|
||||||
DEATH of a HERO
|
DEATH of a HERO
|
||||||
|
|
||||||
|
|
||||||
@ -4748,6 +4750,7 @@
|
|||||||
And I too walked away
|
And I too walked away
|
||||||
|
|
||||||
In an agony of helpless grief and pity.
|
In an agony of helpless grief and pity.
|
||||||
`);
|
`
|
||||||
|
});
|
||||||
window.context.update_books();
|
window.context.update_books();
|
||||||
})();
|
})();
|
||||||
|
@ -50,7 +50,11 @@ $(window).on('load', () => {
|
|||||||
context.update_books = () => {
|
context.update_books = () => {
|
||||||
context.ui.books_select.empty();
|
context.ui.books_select.empty();
|
||||||
window.context.books.map(
|
window.context.books.map(
|
||||||
(o, i) => $('<option>').attr('value', '' + i).text(o.slice(0, 10))
|
(o, i) =>
|
||||||
|
$('<option>')
|
||||||
|
.attr('value', '' + i)
|
||||||
|
.attr('url', o.url || '')
|
||||||
|
.text(o.text.slice(0, 10))
|
||||||
).forEach((o) => context.ui.books_select.append(o))
|
).forEach((o) => context.ui.books_select.append(o))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,11 +240,19 @@ $(window).on('load', () => {
|
|||||||
let book_id = parseInt(context.ui.books_select.val());
|
let book_id = parseInt(context.ui.books_select.val());
|
||||||
if (context.current_book != book_id)
|
if (context.current_book != book_id)
|
||||||
{
|
{
|
||||||
|
if (context.books[book_id].url)
|
||||||
|
{
|
||||||
|
context.callbacks.set_cookie(
|
||||||
|
'book_url',
|
||||||
|
context.books[book_id].url,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
context.current_book = book_id;
|
context.current_book = book_id;
|
||||||
context.sentences =
|
context.sentences =
|
||||||
context.books[
|
context.books[
|
||||||
context.current_book
|
context.current_book
|
||||||
].replaceAll(/([\.\?\!])\s+/g,'$1\n')
|
].text.replaceAll(/([\.\?\!])\s+/g,'$1\n')
|
||||||
.split('\n');
|
.split('\n');
|
||||||
context.ui.total_sentences_input.val(
|
context.ui.total_sentences_input.val(
|
||||||
context.sentences.length,
|
context.sentences.length,
|
||||||
@ -249,6 +261,7 @@ $(window).on('load', () => {
|
|||||||
let state = context.callbacks.get_state();
|
let state = context.callbacks.get_state();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
context.ui.current_sentence_input.val() != ''
|
context.ui.current_sentence_input.val() != ''
|
||||||
)
|
)
|
||||||
@ -281,6 +294,18 @@ $(window).on('load', () => {
|
|||||||
context.callbacks.continuous_reading();
|
context.callbacks.continuous_reading();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
book_add: async (url) => {
|
||||||
|
let book = await (
|
||||||
|
(await fetch(url)).text()
|
||||||
|
);
|
||||||
|
//let book = prompt('enter text', '');
|
||||||
|
//let title = prompt('enter title', '');
|
||||||
|
//window.context.books.push(title + '\n' + book);
|
||||||
|
window.context.books.push({
|
||||||
|
text: book, url
|
||||||
|
});
|
||||||
|
window.context.update_books();
|
||||||
|
},
|
||||||
populateVoiceList: () => {
|
populateVoiceList: () => {
|
||||||
voices = synth.getVoices().sort(function (a, b) {
|
voices = synth.getVoices().sort(function (a, b) {
|
||||||
const aname = a.name.toUpperCase(), bname = b.name.toUpperCase();
|
const aname = a.name.toUpperCase(), bname = b.name.toUpperCase();
|
||||||
@ -331,12 +356,19 @@ $(window).on('load', () => {
|
|||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (state.book_url)
|
||||||
|
{
|
||||||
|
context.callbacks.book_add(state.book_url);
|
||||||
|
state.book_id = context.books.length - 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (state.book_id)
|
if (state.book_id)
|
||||||
{
|
{
|
||||||
context.ui.books_select.find(
|
context.ui.books_select.find(
|
||||||
'>option',
|
'>option',
|
||||||
).eq(state.book_id).attr('selected', 'selected');
|
).eq(state.book_id).attr('selected', 'selected');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.sentence_id)
|
if (state.sentence_id)
|
||||||
{
|
{
|
||||||
context.ui.current_sentence_input.val(
|
context.ui.current_sentence_input.val(
|
||||||
@ -355,17 +387,10 @@ $(window).on('load', () => {
|
|||||||
context.ui.add_book.on(
|
context.ui.add_book.on(
|
||||||
'click',
|
'click',
|
||||||
async () => {
|
async () => {
|
||||||
alert('fuck');
|
// alert('fuck');
|
||||||
let book = await (
|
let url = 'books/' + prompt('enter book file', '1.txt');
|
||||||
(await fetch(
|
|
||||||
'books/' + prompt('enter book file', '1.txt')
|
await context.callbacks.book_add(url);
|
||||||
)).text()
|
|
||||||
);
|
|
||||||
//let book = prompt('enter text', '');
|
|
||||||
//let title = prompt('enter title', '');
|
|
||||||
//window.context.books.push(title + '\n' + book);
|
|
||||||
window.context.books.push(book);
|
|
||||||
window.context.update_books();
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
context.ui.read_aloud.on(
|
context.ui.read_aloud.on(
|
||||||
|
Loading…
Reference in New Issue
Block a user