-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutilities.js
More file actions
88 lines (77 loc) · 2.42 KB
/
utilities.js
File metadata and controls
88 lines (77 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Useful general functions
function get_read_loc() {
var doc2=document.getElementById("KindleReaderIFrame").contentDocument;
var loct = doc2.getElementById('kindleReader_footer_message').textContent;
var patt=/% · (\d+) of/;
var matches = patt.exec(loct);
if (matches==null) {return null};
var loc = matches[1];
return loc;
}
function goto_loc(location) {
var doc2=document.getElementById("KindleReaderIFrame").contentDocument;
doc2.getElementById('kindleReader_button_goto').click();
doc2.getElementById('kindleReader_goToMenuItem_goToLocation').click();
var gotobutton = findGoToButton();
doc2.getElementById('kindleReader_dialog_gotoField').value = location;
gotobutton.click();
}
function findGoToButton() {
var doc2=document.getElementById("KindleReaderIFrame").contentDocument;
var buts = doc2.getElementsByTagName("button")
for (var i=0; i<buts.length; i++){
var x=buts[i].children;
if (x.length==1 && x[0].textContent=="Go to location"){
return buts[i];
}
}
}
function getBookName() {
// <label id="kindleReader_title" style="color: rgb(153, 153, 153);">Les Misérables - Tome I - Fantine</label>
var frame=document.getElementById("KindleReaderIFrame");
if (frame==null) {return null;}
var doc2 = frame.contentDocument;
var bookel = doc2.getElementById("kindleReader_title");
if (bookel==null) {return null;}
return bookel.textContent;
}
function hasBookChanged() {
var frame = document.getElementById("KindleReaderIFrame");
if (frame==null) {
// Have returned to Library page from Book page
// reset book name, and wait
current_book_id = "";
allQA = [];
current_book_name = "";
return false;
}
new_book_name = getBookName();
if (new_book_name==null || new_book_name=="") {
// Have landed straight onto Library page
// do nothing, as there is nothing to do...?
current_book_name = "";
return false;
}
else if (new_book_name!==current_book_name){
// Have gone to book from Library or other book
// Need to setup again
return true;
}
else {
return false;
}
}
function login_as(usr) {
username = usr;
}
function isLoggedIn() {
if (getUsername()=="") {
return false;
}
else {
return true;
}
}
function getUsername() {
return username;
}