hyperlink aanmaken
ik ben in het bezit van een uitgebreide Java script die bepaalde woorden op zoekt en dan daar een hyperlink rond maakt die gekopelt staat in een andere boek maar ik bezit nu een nieuwere versie van die boek en krijg ze niet gekoppeld in de nieuwe versie kan iemand mij daar bij helpen?
Waar loopt je op vast? Kan je wat relevante code laten zien? En bij voorkeur op JSfiddle?
Code (php)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
if (app.viewerVersion < 10) {
app.addMenuItem({ cName: "AddLinksToBible", cUser: "Add Links To Bible", cParent: "Tools", nPos: -1,
cExec: "addLinksToBible()", cEnable: "event.rc = (event.target != null);"});
app.addMenuItem({ cName: "DiscloseFile", cUser: "Disclose File", cParent: "Tools", nPos: 0,
cExec: "discloseFile()", cEnable: "event.rc = (event.target != null);"});
} else {
app.addToolButton({ cName: "AddLinksToBible", cLabel: "Add Links To Bible", cTooltext: "Add Links To Bible",
cExec: "addLinksToBible()", cEnable: "event.rc = (event.target != null);"});
app.addToolButton({ cName: "DiscloseFile", cLabel: "Disclose File", cTooltext: "Disclose File",
cExec: "discloseFile()", cEnable: "event.rc = (event.target != null);"});
app.addToolButton({ cName: "OffsetLinks", cLabel: "Offset Links", cTooltext: "Offset Links",
cExec: "offsetLinks()", cEnable: "event.rc = (event.target != null);"});
}
var booksFullNames = ["Genesis", "Exodus", "Leviticus", "Numeri", "Deuteronomium", "Jozua", "Rechters", "Ruth", "1Samul", "2Samul",
"1Koningen", "2Koningen", "1Kronieken", "2Kronieken", "Ezra", "Nehemia", "Esther", "Job", "Psalm", "Spreuken", "Prediker",
"Hooglied", "Jesaja", "Jeremia", "Klaagliederen", "Ezechil", "Danil", "Hosea", "Jol", "Amos", "Obadja", "Jona", "Micha", "Nahum",
"Habakuk", "Zefanja", "Hagga", "Zacharia", "Maleachi",
"Matthes", "Markus", "Lukas", "Johannes", "Handelingen", "Romeinen", "1Korinthirs", "2Korinthirs", "Galaten",
"Efezirs", "Filippenzen", "Kolossenzen", "1Thessalonicenzen", "2Thessalonicenzen", "1Timothes", "2Timothes", "Titus", "Filemon",
"Hebreen", "Jakobus", "1Petrus", "2Petrus", "1Johannes", "2Johannes", "3Johannes", "Judas", "Openbaring"
];
var booksMediumNames = [
"Gen", "Ex", "Lev", "Num", "Deut", "Joz", "Rechters", "Ruth", "1Sam", "2Sam",
"1Kon", "2Kon", "1Kron", "2Kron", "Ezra", "Neh", "Esth", "Job", "Ps", "Spr", "Pred",
"Hoogl", "Jes", "Jer", "Klaagl", "Ezech", "Dan", "Hos", "Jol", "Amos", "Obadja", "Jona", "Micha", "Nahum",
"Hab", "Zef", "Hag", "Zach", "Mal",
"Matth", "Mark", "Luk", "Joh", "Hand", "Rom", "1Kor", "2Kor", "Gal",
"Ef", "Fil", "Kol", "1Thess", "2Thess", "1Tim", "2Tim", "Tit", "Filem",
"Hebr", "Jak", "1Petr", "2Petr", "1Joh", "2Joh", "3Joh", "Jud", "Openb"
];
var booksShortNames = [ "Ge", "Ex", "Le", "Nu", "De", "Joz", "Re", "Ru", "1Sa", "2Sa",
"1Kon", "2Kon", "1Kr", "2Kr", "Ezr", "Ne", "Es", "Job", "Ps", "Sp", "Pr",
"Hgl", "Jes", "Jer", "Klg", "Ez", "Da", "Ho", "Jo", "Am", "Ob", "Jon", "Mi", "Na",
"Hab", "Ze", "Hag", "Za", "Mal",
"Mt", "Mr", "Lu", "Jo", "Han", "Ro", "1Kor", "2Kor", "Ga",
"Ef", "Fil", "Kol", "1Th", "2Th", "1Ti", "2Ti", "Tit", "Flm",
"Heb", "Jak", "1Pe", "2Pe", "1Jo", "2Jo", "3Jo", "Ju", "Opb"
];
var namedDests = ["Ge", "Ex", "Le", "Nu", "De", "Joz", "Re", "Ru", "1Sa", "2Sa",
"1Kon", "2Kon", "1Kr", "2Kr", "Ezr", "Ne", "Es", "Job", "Ps", "Sp", "Pr",
"Hgl", "Jes", "Jer", "Klg", "Ez", "Da", "Ho", "Joe", "Am", "Ob", "Jon",
"Mi", "Na", "Hab", "Ze", "Hag", "Za", "Mal",
"Mt", "Mr", "Lu", "Jo", "Han", "Ro", "1Kor", "2Kor", "Ga", "Ef", "Fil", "Kol",
"1Th", "2Th", "1Ti", "2Ti", "Tit", "Flm", "Heb", "Jak", "1Pe", "2Pe",
"1Jo", "2Jo", "3Jo", "Ju", "Opb"
];
function discloseFile() {
this.addScript("init", "this.disclosed=true;");
app.alert("Done.",3);
}
function offsetLinks() {
var resp = app.response("Enter the offset (in points):","", "16");
if (resp==null || resp=="" || isNaN(+resp)) return;
var offset = +resp;
for (var i=0; i<this.numFields; i++) {
var f = this.getField(this.getNthFieldName(i));
if (f==null) continue;
if (f.type=="button" && /^_/.test(f.name)) {
var r = f.rect;
r[0]-=offset;
r[1]-=offset;
r[2]-=offset;
r[3]-=offset;
f.rect = r;
}
}
app.alert("Done.",3);
}
//addLinksToBible(2,9,9);
function addLinksToBible() {
var mode, firstPage, lastPage;
var dialog1 = {
initialize: function (dialog) {
dialog.load({
rad1: true,
txt1: "1",
txt2: ""+this.parentDoc.numPages,
})
},
cancel: function(dialog) {
return;
},
destroy: function(dialog) {
return;
},
commit:function (dialog) {
var results = dialog.store();
if (results["rad1"]) mode = 1;
else if (results["rad2"]) mode = 2;
else if (results["rad3"]) mode = 3;
firstPage = Number(results["txt1"])-1;
lastPage = Number(results["txt2"])-1;
return;
},
validate:function (dialog) {
var results = dialog.store();
if (results["rad1"]==false && results["rad2"]==false && results["rad3"]==false) {
app.alert("You must select the book names mode.");
return false;
}
if (results["txt1"]==null || results["txt1"]=="" || isNaN(+results["txt1"]) ||
results["txt2"]==null || results["txt2"]=="" || isNaN(+results["txt2"])) {
app.alert("Invalid page range.");
return false;
}
return true;
},
description: {
name: "",
align_children: "align_left",
width: 350,
height: 100,
elements:[
{
type: "cluster",
name: "Add Bible Links",
align_children: "align_left",
elements:[
{
type: "static_text",
name: "Select the type of book names:"
},
{
type: "view",
align_children: "align_distribute",
elements:[
{
group_id: "mode",
item_id: "rad1",
type: "radio",
name: "Short names",
width: 20,
height: 20,
},
{
group_id: "mode",
item_id: "rad2",
type: "radio",
name: "Medium names",
width: 20,
height: 20,
},
{
group_id: "mode",
item_id: "rad3",
type: "radio",
name: "Long names",
width: 20,
height: 20,
}
]
},
{
type: "static_text",
name: "Which pages to process:"
},
{
type: "view",
align_children: "align_distribute",
elements:[
{
item_id: "txt1",
type: "edit_text",
width: 40,
},
{
type: "static_text",
name: "-"
},
{
item_id: "txt2",
type: "edit_text",
width: 40,
}
]
},
{ type: "gap"},
{
alignment: "align_right",
type: "ok_cancel",
ok_name: "OK",
cancel_name: "Cancel"
},
]
},
]
}
};
dialog1.parentDoc = this;
if (app.execDialog(dialog1)!="ok") {return};
function openBibleLink() {
var bibleFileName = "2006 'bi' BIJBEL genootsch";
var bibleDoc = app.openDoc({cPath: bibleFileName, oDoc: this, cDest: event.target.name});
if (bibleDoc==null) {
app.alert("Error! Can't locate the bible file: " + bibleFileName);
return;
}
}
var bookNames;
if (mode==1) { // short names
bookNames = [].concat(booksShortNames);
} else if (mode==2) { // medium names
bookNames = [].concat(booksMediumNames);
} else if (mode==3) { // full names
bookNames = [].concat(booksFullNames);
}
for (var i in bookNames) bookNames[i]=bookNames[i].toLowerCase();
//console.println(bookNames);
var startTime = new Date();
var t = app.thermometer;
t.duration = (lastPage - firstPage);
t.begin();
var counter = 0;
//console.clear();
for (var p=firstPage; p<=lastPage; p++) {
console.println("Processing page #"+p);
t.value = (p-firstPage)+1;
t.text = "Processing page " + ((p-firstPage)+1) + "/" + ((lastPage - firstPage)+1);
var numWords = this.getPageNumWords(p);
for (var i=0; i<numWords-2; i++) {
//console.println("Processing word #"+i);
var word = this.getPageNthWord(p,i,true).toLowerCase();
word = word.replace(/^\(/,"");
var wordFull = this.getPageNthWord(p,i,false);
var wordRect = convertWordQuadsToRect(this, p, i);
if (bookNames.indexOf(word)==-1 || bookNames.indexOf(word)==42) {
var prevWord = "";
if (i>0) prevWord=this.getPageNthWord(p,i-1,true).toLowerCase();
if (prevWord!="" && /^\d$/.test(prevWord)) {
word = prevWord+word;
var prevWordRect = convertWordQuadsToRect(this, p, i-1);
wordRect[0] = prevWordRect[0];
}
}
word = word.replace(/^\(/,"");
//console.println("word: " + word);
if (bookNames.indexOf(word)!=-1) {
//console.println("MATCH");
var word1 = this.getPageNthWord(p,i+1,true).toLowerCase();
var word2 = this.getPageNthWord(p,i+2,true).toLowerCase();
if (/^\d+$/.test(word1)) {
if (/^\d+$/.test(word2)) {
//var r1 = convertWordQuadsToRect(this, p, i);
var r2 = convertWordQuadsToRect(this, p, i+2);
var r;
if (wordRect[1]==r2[1]) {
r = [wordRect[0],wordRect[1],r2[2],wordRect[3]];
createBibleLink(this, p, r, word, word1, word2, bookNames);
}
else {
r = [wordRect[0],wordRect[1],wordRect[2],wordRect[3]];
createBibleLink(this, p, r, word, word1, word2, bookNames);
var r3 = convertWordQuadsToRect(this, p, i+1);
r = [r3[0],r3[1],r2[2],r3[3]];
createBibleLink(this, p, r, word, word1, word2, bookNames);
}
counter++;
} else {
//var r1 = convertWordQuadsToRect(this, p, i);
var r2 = convertWordQuadsToRect(this, p, i+1);
r = [wordRect[0],wordRect[1],r2[2],wordRect[3]];
createBibleLink(this, p, r, word, word1, "", bookNames);
counter++;
}
}
} else if (wordFull==" " || wordFull=="") {
//console.println(i+":"+wordFull)
word = this.getPageNthWord(p,i-1,true).toLowerCase();
if (/u$/.test(word)) {
word = word.replace(/u$/, "");
}
word+=this.getPageNthWord(p,i+1,true).toLowerCase();
word = word.replace(/\s/g,"");
//console.println("full word: " + word);
if (bookNames.indexOf(word)!=-1) {
i++;
//console.println("MATCH");
wordRect = convertWordQuadsToRect(this, p, i-2);
var word1 = this.getPageNthWord(p,i+1,true).toLowerCase();
var word2 = this.getPageNthWord(p,i+2,true).toLowerCase();
if (/^\d+$/.test(word1)) {
if (/^\d+$/.test(word2)) {
//var r1 = convertWordQuadsToRect(this, p, i);
var r2 = convertWordQuadsToRect(this, p, i+2);
var r;
if (wordRect[1]==r2[1]) {
r = [wordRect[0],wordRect[1],r2[2],wordRect[3]];
createBibleLink(this, p, r, word, word1, word2, bookNames);
}
else {
r = [wordRect[0],wordRect[1],wordRect[2],wordRect[3]];
createBibleLink(this, p, r, word, word1, word2, bookNames);
var r3 = convertWordQuadsToRect(this, p, i+1);
r = [r3[0],r3[1],r2[2],r3[3]];
createBibleLink(this, p, r, word, word1, word2, bookNames);
}
counter++;
} else {
//var r1 = convertWordQuadsToRect(this, p, i);
var r2 = convertWordQuadsToRect(this, p, i+1);
r = [wordRect[0],wordRect[1],r2[2],wordRect[3]];
createBibleLink(this, p, r, word, word1, "", bookNames);
counter++;
}
}
}
} else {
// in case the book name and chapter number are connected
for (var j in bookNames) {
var reg = new RegExp("^"+bookNames[j]+"\\d+");
if (reg.test(word)) {
var word1 = this.getPageNthWord(p,i+1,true).toLowerCase();
if (/^\d+$/.test(word1)) {
var chapterNumber = word.match(/\d+$/)[0];
var bookName = word.replace(new RegExp(chapterNumber+"$"),"");
//var r1 = convertWordQuadsToRect(this, p, i);
var r2 = convertWordQuadsToRect(this, p, i+1);
r = [wordRect[0],wordRect[1],r2[2],wordRect[3]];
createBibleLink(this, p, r, bookName, chapterNumber, word1, bookNames);
counter++;
}
break;
}
}
}
}
}
t.end();
var endTime = new Date();
//console.println("Run time: " + ((endTime-startTime)/1000));
this.addScript("BibleLinks", openBibleLink);
app.alert("Done. " + counter + " links were created.",3);
}
function createBibleLink(doc, p, r, book, chapter, verse, bookNames) {
var bookIndex = bookNames.indexOf(book);
if (bookIndex==-1) {
console.println("Error! Could not locate the index for: " + book);
return false;
}
/*var pageCropBox = doc.getPageBox("Crop", p);
var pageBBox = doc.getPageBox("BBox", p);
var xOffset = pageBBox[0]-pageCropBox[0];
var yOffset = pageBBox[1]-pageCropBox[1];
console.println("xOffset:"+xOffset);
console.println("yOffset:"+yOffset);*/
/*xOffset = 16;
yOffset = 16;
r[0]-=xOffset;
r[2]-=xOffset;
r[1]-=yOffset;
r[3]-=yOffset;*/
var bookDestName = namedDests[bookIndex]
var destName = bookDestName+"_"+chapter;
if (verse!=null && verse!="" && verse!="1")
destName+="_"+verse;
var f = doc.addField(destName, "button", p, r);
f.setAction("MouseUp", "openBibleLink()");
f.lineWidth = 0;
//f.strokeColor = color.ltGray;
f.userName = "Click to jump to this location in the Bible file.";
}
function convertWordQuadsToRect(doc, p, i) {
return convertQuadsToRect(doc, p, doc.getPageNthWordQuads(p, i));
}
function convertQuadsToRect(doc, p, q) {
var m = (new Matrix2D).fromRotated(doc,p);
var mInv = m.invert()
var r = mInv.transform(q)
r = r.toString()
r = r.split(",");
return [+r[4], +r[3], +r[2], +r[5]];
}
app.addMenuItem({ cName: "AddLinksToBible", cUser: "Add Links To Bible", cParent: "Tools", nPos: -1,
cExec: "addLinksToBible()", cEnable: "event.rc = (event.target != null);"});
app.addMenuItem({ cName: "DiscloseFile", cUser: "Disclose File", cParent: "Tools", nPos: 0,
cExec: "discloseFile()", cEnable: "event.rc = (event.target != null);"});
} else {
app.addToolButton({ cName: "AddLinksToBible", cLabel: "Add Links To Bible", cTooltext: "Add Links To Bible",
cExec: "addLinksToBible()", cEnable: "event.rc = (event.target != null);"});
app.addToolButton({ cName: "DiscloseFile", cLabel: "Disclose File", cTooltext: "Disclose File",
cExec: "discloseFile()", cEnable: "event.rc = (event.target != null);"});
app.addToolButton({ cName: "OffsetLinks", cLabel: "Offset Links", cTooltext: "Offset Links",
cExec: "offsetLinks()", cEnable: "event.rc = (event.target != null);"});
}
var booksFullNames = ["Genesis", "Exodus", "Leviticus", "Numeri", "Deuteronomium", "Jozua", "Rechters", "Ruth", "1Samul", "2Samul",
"1Koningen", "2Koningen", "1Kronieken", "2Kronieken", "Ezra", "Nehemia", "Esther", "Job", "Psalm", "Spreuken", "Prediker",
"Hooglied", "Jesaja", "Jeremia", "Klaagliederen", "Ezechil", "Danil", "Hosea", "Jol", "Amos", "Obadja", "Jona", "Micha", "Nahum",
"Habakuk", "Zefanja", "Hagga", "Zacharia", "Maleachi",
"Matthes", "Markus", "Lukas", "Johannes", "Handelingen", "Romeinen", "1Korinthirs", "2Korinthirs", "Galaten",
"Efezirs", "Filippenzen", "Kolossenzen", "1Thessalonicenzen", "2Thessalonicenzen", "1Timothes", "2Timothes", "Titus", "Filemon",
"Hebreen", "Jakobus", "1Petrus", "2Petrus", "1Johannes", "2Johannes", "3Johannes", "Judas", "Openbaring"
];
var booksMediumNames = [
"Gen", "Ex", "Lev", "Num", "Deut", "Joz", "Rechters", "Ruth", "1Sam", "2Sam",
"1Kon", "2Kon", "1Kron", "2Kron", "Ezra", "Neh", "Esth", "Job", "Ps", "Spr", "Pred",
"Hoogl", "Jes", "Jer", "Klaagl", "Ezech", "Dan", "Hos", "Jol", "Amos", "Obadja", "Jona", "Micha", "Nahum",
"Hab", "Zef", "Hag", "Zach", "Mal",
"Matth", "Mark", "Luk", "Joh", "Hand", "Rom", "1Kor", "2Kor", "Gal",
"Ef", "Fil", "Kol", "1Thess", "2Thess", "1Tim", "2Tim", "Tit", "Filem",
"Hebr", "Jak", "1Petr", "2Petr", "1Joh", "2Joh", "3Joh", "Jud", "Openb"
];
var booksShortNames = [ "Ge", "Ex", "Le", "Nu", "De", "Joz", "Re", "Ru", "1Sa", "2Sa",
"1Kon", "2Kon", "1Kr", "2Kr", "Ezr", "Ne", "Es", "Job", "Ps", "Sp", "Pr",
"Hgl", "Jes", "Jer", "Klg", "Ez", "Da", "Ho", "Jo", "Am", "Ob", "Jon", "Mi", "Na",
"Hab", "Ze", "Hag", "Za", "Mal",
"Mt", "Mr", "Lu", "Jo", "Han", "Ro", "1Kor", "2Kor", "Ga",
"Ef", "Fil", "Kol", "1Th", "2Th", "1Ti", "2Ti", "Tit", "Flm",
"Heb", "Jak", "1Pe", "2Pe", "1Jo", "2Jo", "3Jo", "Ju", "Opb"
];
var namedDests = ["Ge", "Ex", "Le", "Nu", "De", "Joz", "Re", "Ru", "1Sa", "2Sa",
"1Kon", "2Kon", "1Kr", "2Kr", "Ezr", "Ne", "Es", "Job", "Ps", "Sp", "Pr",
"Hgl", "Jes", "Jer", "Klg", "Ez", "Da", "Ho", "Joe", "Am", "Ob", "Jon",
"Mi", "Na", "Hab", "Ze", "Hag", "Za", "Mal",
"Mt", "Mr", "Lu", "Jo", "Han", "Ro", "1Kor", "2Kor", "Ga", "Ef", "Fil", "Kol",
"1Th", "2Th", "1Ti", "2Ti", "Tit", "Flm", "Heb", "Jak", "1Pe", "2Pe",
"1Jo", "2Jo", "3Jo", "Ju", "Opb"
];
function discloseFile() {
this.addScript("init", "this.disclosed=true;");
app.alert("Done.",3);
}
function offsetLinks() {
var resp = app.response("Enter the offset (in points):","", "16");
if (resp==null || resp=="" || isNaN(+resp)) return;
var offset = +resp;
for (var i=0; i<this.numFields; i++) {
var f = this.getField(this.getNthFieldName(i));
if (f==null) continue;
if (f.type=="button" && /^_/.test(f.name)) {
var r = f.rect;
r[0]-=offset;
r[1]-=offset;
r[2]-=offset;
r[3]-=offset;
f.rect = r;
}
}
app.alert("Done.",3);
}
//addLinksToBible(2,9,9);
function addLinksToBible() {
var mode, firstPage, lastPage;
var dialog1 = {
initialize: function (dialog) {
dialog.load({
rad1: true,
txt1: "1",
txt2: ""+this.parentDoc.numPages,
})
},
cancel: function(dialog) {
return;
},
destroy: function(dialog) {
return;
},
commit:function (dialog) {
var results = dialog.store();
if (results["rad1"]) mode = 1;
else if (results["rad2"]) mode = 2;
else if (results["rad3"]) mode = 3;
firstPage = Number(results["txt1"])-1;
lastPage = Number(results["txt2"])-1;
return;
},
validate:function (dialog) {
var results = dialog.store();
if (results["rad1"]==false && results["rad2"]==false && results["rad3"]==false) {
app.alert("You must select the book names mode.");
return false;
}
if (results["txt1"]==null || results["txt1"]=="" || isNaN(+results["txt1"]) ||
results["txt2"]==null || results["txt2"]=="" || isNaN(+results["txt2"])) {
app.alert("Invalid page range.");
return false;
}
return true;
},
description: {
name: "",
align_children: "align_left",
width: 350,
height: 100,
elements:[
{
type: "cluster",
name: "Add Bible Links",
align_children: "align_left",
elements:[
{
type: "static_text",
name: "Select the type of book names:"
},
{
type: "view",
align_children: "align_distribute",
elements:[
{
group_id: "mode",
item_id: "rad1",
type: "radio",
name: "Short names",
width: 20,
height: 20,
},
{
group_id: "mode",
item_id: "rad2",
type: "radio",
name: "Medium names",
width: 20,
height: 20,
},
{
group_id: "mode",
item_id: "rad3",
type: "radio",
name: "Long names",
width: 20,
height: 20,
}
]
},
{
type: "static_text",
name: "Which pages to process:"
},
{
type: "view",
align_children: "align_distribute",
elements:[
{
item_id: "txt1",
type: "edit_text",
width: 40,
},
{
type: "static_text",
name: "-"
},
{
item_id: "txt2",
type: "edit_text",
width: 40,
}
]
},
{ type: "gap"},
{
alignment: "align_right",
type: "ok_cancel",
ok_name: "OK",
cancel_name: "Cancel"
},
]
},
]
}
};
dialog1.parentDoc = this;
if (app.execDialog(dialog1)!="ok") {return};
function openBibleLink() {
var bibleFileName = "2006 'bi' BIJBEL genootsch";
var bibleDoc = app.openDoc({cPath: bibleFileName, oDoc: this, cDest: event.target.name});
if (bibleDoc==null) {
app.alert("Error! Can't locate the bible file: " + bibleFileName);
return;
}
}
var bookNames;
if (mode==1) { // short names
bookNames = [].concat(booksShortNames);
} else if (mode==2) { // medium names
bookNames = [].concat(booksMediumNames);
} else if (mode==3) { // full names
bookNames = [].concat(booksFullNames);
}
for (var i in bookNames) bookNames[i]=bookNames[i].toLowerCase();
//console.println(bookNames);
var startTime = new Date();
var t = app.thermometer;
t.duration = (lastPage - firstPage);
t.begin();
var counter = 0;
//console.clear();
for (var p=firstPage; p<=lastPage; p++) {
console.println("Processing page #"+p);
t.value = (p-firstPage)+1;
t.text = "Processing page " + ((p-firstPage)+1) + "/" + ((lastPage - firstPage)+1);
var numWords = this.getPageNumWords(p);
for (var i=0; i<numWords-2; i++) {
//console.println("Processing word #"+i);
var word = this.getPageNthWord(p,i,true).toLowerCase();
word = word.replace(/^\(/,"");
var wordFull = this.getPageNthWord(p,i,false);
var wordRect = convertWordQuadsToRect(this, p, i);
if (bookNames.indexOf(word)==-1 || bookNames.indexOf(word)==42) {
var prevWord = "";
if (i>0) prevWord=this.getPageNthWord(p,i-1,true).toLowerCase();
if (prevWord!="" && /^\d$/.test(prevWord)) {
word = prevWord+word;
var prevWordRect = convertWordQuadsToRect(this, p, i-1);
wordRect[0] = prevWordRect[0];
}
}
word = word.replace(/^\(/,"");
//console.println("word: " + word);
if (bookNames.indexOf(word)!=-1) {
//console.println("MATCH");
var word1 = this.getPageNthWord(p,i+1,true).toLowerCase();
var word2 = this.getPageNthWord(p,i+2,true).toLowerCase();
if (/^\d+$/.test(word1)) {
if (/^\d+$/.test(word2)) {
//var r1 = convertWordQuadsToRect(this, p, i);
var r2 = convertWordQuadsToRect(this, p, i+2);
var r;
if (wordRect[1]==r2[1]) {
r = [wordRect[0],wordRect[1],r2[2],wordRect[3]];
createBibleLink(this, p, r, word, word1, word2, bookNames);
}
else {
r = [wordRect[0],wordRect[1],wordRect[2],wordRect[3]];
createBibleLink(this, p, r, word, word1, word2, bookNames);
var r3 = convertWordQuadsToRect(this, p, i+1);
r = [r3[0],r3[1],r2[2],r3[3]];
createBibleLink(this, p, r, word, word1, word2, bookNames);
}
counter++;
} else {
//var r1 = convertWordQuadsToRect(this, p, i);
var r2 = convertWordQuadsToRect(this, p, i+1);
r = [wordRect[0],wordRect[1],r2[2],wordRect[3]];
createBibleLink(this, p, r, word, word1, "", bookNames);
counter++;
}
}
} else if (wordFull==" " || wordFull=="") {
//console.println(i+":"+wordFull)
word = this.getPageNthWord(p,i-1,true).toLowerCase();
if (/u$/.test(word)) {
word = word.replace(/u$/, "");
}
word+=this.getPageNthWord(p,i+1,true).toLowerCase();
word = word.replace(/\s/g,"");
//console.println("full word: " + word);
if (bookNames.indexOf(word)!=-1) {
i++;
//console.println("MATCH");
wordRect = convertWordQuadsToRect(this, p, i-2);
var word1 = this.getPageNthWord(p,i+1,true).toLowerCase();
var word2 = this.getPageNthWord(p,i+2,true).toLowerCase();
if (/^\d+$/.test(word1)) {
if (/^\d+$/.test(word2)) {
//var r1 = convertWordQuadsToRect(this, p, i);
var r2 = convertWordQuadsToRect(this, p, i+2);
var r;
if (wordRect[1]==r2[1]) {
r = [wordRect[0],wordRect[1],r2[2],wordRect[3]];
createBibleLink(this, p, r, word, word1, word2, bookNames);
}
else {
r = [wordRect[0],wordRect[1],wordRect[2],wordRect[3]];
createBibleLink(this, p, r, word, word1, word2, bookNames);
var r3 = convertWordQuadsToRect(this, p, i+1);
r = [r3[0],r3[1],r2[2],r3[3]];
createBibleLink(this, p, r, word, word1, word2, bookNames);
}
counter++;
} else {
//var r1 = convertWordQuadsToRect(this, p, i);
var r2 = convertWordQuadsToRect(this, p, i+1);
r = [wordRect[0],wordRect[1],r2[2],wordRect[3]];
createBibleLink(this, p, r, word, word1, "", bookNames);
counter++;
}
}
}
} else {
// in case the book name and chapter number are connected
for (var j in bookNames) {
var reg = new RegExp("^"+bookNames[j]+"\\d+");
if (reg.test(word)) {
var word1 = this.getPageNthWord(p,i+1,true).toLowerCase();
if (/^\d+$/.test(word1)) {
var chapterNumber = word.match(/\d+$/)[0];
var bookName = word.replace(new RegExp(chapterNumber+"$"),"");
//var r1 = convertWordQuadsToRect(this, p, i);
var r2 = convertWordQuadsToRect(this, p, i+1);
r = [wordRect[0],wordRect[1],r2[2],wordRect[3]];
createBibleLink(this, p, r, bookName, chapterNumber, word1, bookNames);
counter++;
}
break;
}
}
}
}
}
t.end();
var endTime = new Date();
//console.println("Run time: " + ((endTime-startTime)/1000));
this.addScript("BibleLinks", openBibleLink);
app.alert("Done. " + counter + " links were created.",3);
}
function createBibleLink(doc, p, r, book, chapter, verse, bookNames) {
var bookIndex = bookNames.indexOf(book);
if (bookIndex==-1) {
console.println("Error! Could not locate the index for: " + book);
return false;
}
/*var pageCropBox = doc.getPageBox("Crop", p);
var pageBBox = doc.getPageBox("BBox", p);
var xOffset = pageBBox[0]-pageCropBox[0];
var yOffset = pageBBox[1]-pageCropBox[1];
console.println("xOffset:"+xOffset);
console.println("yOffset:"+yOffset);*/
/*xOffset = 16;
yOffset = 16;
r[0]-=xOffset;
r[2]-=xOffset;
r[1]-=yOffset;
r[3]-=yOffset;*/
var bookDestName = namedDests[bookIndex]
var destName = bookDestName+"_"+chapter;
if (verse!=null && verse!="" && verse!="1")
destName+="_"+verse;
var f = doc.addField(destName, "button", p, r);
f.setAction("MouseUp", "openBibleLink()");
f.lineWidth = 0;
//f.strokeColor = color.ltGray;
f.userName = "Click to jump to this location in the Bible file.";
}
function convertWordQuadsToRect(doc, p, i) {
return convertQuadsToRect(doc, p, doc.getPageNthWordQuads(p, i));
}
function convertQuadsToRect(doc, p, q) {
var m = (new Matrix2D).fromRotated(doc,p);
var mInv = m.invert()
var r = mInv.transform(q)
r = r.toString()
r = r.split(",");
return [+r[4], +r[3], +r[2], +r[5]];
}
de boek waar hij naar moet verwijzen is een andere maar als ik deze naam veranderd doet hij niks
Edit:
code-tags geplaatst. Gelieve dit voortaan zelf te doen.
Gewijzigd op 22/07/2019 15:35:18 door - Ariën -
Ook is nog niet echt duidelijk wat je precies doet en wat er gebeurt.
Gewijzigd op 21/07/2019 17:09:01 door - Ariën -
ik heb deze scrip gekregen via via en de regel waar
function openBibleLink() {
var bibleFileName = "2006 'bi' BIJBEL genootsch";
var bibleDoc = app.openDoc({cPath: bibleFileName, oDoc: this, cDest: event.target.name});
if (bibleDoc==null) {
app.alert("Error! Can't locate the bible file: " + bibleFileName);
return;
staat moet veranderd worden want "2006 'bi' BIJBEL genootsch" is nu een andere boek en als ik de boek naam aanpas
in "nwt_O.pdf" doet hij het nog niet.
daarom de vraag of smeking hier.
En waar komt die "app" variabele vandaan (met name: wat doet app.openDoc; ik zie iets met een Adobe lib voorbij komen op de internets - is dat 'm; en hoe weet die lib waar "2006 'bi' BIJBEL genootsch" is te vinden - wat is dat: een HTML pagina of een PDF)?
Toevoeging op 21/07/2019 17:20:17:
Misschien enkel "nwt_O" (zonder de ".pdf" - net zoals bij "2006 'bi' BIJBEL genootsch")?
Gewijzigd op 21/07/2019 17:21:45 door Rob Doemaarwat
dus voor de duidelijkheid
in boek 1 worden er links aangemaakt met de java script en deze worden verwezen naar boek 2 de ( nieuwe bijbel)
de 2 boeken zijn PDF's
de oude bijbel was 2006 bi BIJBEL genootsch
De Bijbel wijzigt nou niet echt frequent qua opbouw/inhoud etc.
Als het alleen maar een link aanpassen is; waarom dan niet eenmalig met een CTRL + H in je editor doen?
uw redenatie klopt wel, maar het is om de lees boek die moet steeds naar de bijbel verwijzen, en deze word steeds nieuw.
Daarom dynamisch, ik verlies veel tijd om steeds dit manueel te moeten doen
Gewijzigd op 23/07/2019 10:01:58 door - Ariën -
van mij mag het gemaakt worden in een andere vorm als het maar doet.
ps ik heb eens de scrip op JSfiddle gezet hier de link
https://jsfiddle.net/sg73ubxv/
Moet je het wel goed op JSfiddle zetten, in het JS-veld en met de juiste HTML zodat het werkt ;-)
Als we het in werking kunnen zien, maak anders een testsite met het script erop aan.