-
Notifications
You must be signed in to change notification settings - Fork 0
/
TitlePage.js
65 lines (58 loc) · 2.63 KB
/
TitlePage.js
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
// Title page function
function addTitlePage(tpInfo){
var body = DocumentApp.getActiveDocument().getBody();
var topSpaces = 15;
// Add title page
body.insertPageBreak(0);
body.insertParagraph(0, tpInfo.contact4).setAlignment(DocumentApp.HorizontalAlignment.RIGHT);
body.insertParagraph(0, tpInfo.contact3).setAlignment(DocumentApp.HorizontalAlignment.RIGHT);
body.insertParagraph(0, tpInfo.contact2).setAlignment(DocumentApp.HorizontalAlignment.RIGHT);
body.insertParagraph(0, tpInfo.contact1).setAlignment(DocumentApp.HorizontalAlignment.RIGHT);
for(var i = 0; i < 17; i++){
body.insertParagraph(0, "").setAlignment(DocumentApp.HorizontalAlignment.CENTER);
}
body.insertParagraph(0, tpInfo.author).setAlignment(DocumentApp.HorizontalAlignment.CENTER);
body.insertParagraph(0, '').setAlignment(DocumentApp.HorizontalAlignment.CENTER);
body.insertParagraph(0, 'by').setAlignment(DocumentApp.HorizontalAlignment.CENTER);
body.insertParagraph(0, '').setAlignment(DocumentApp.HorizontalAlignment.CENTER);
if(tpInfo.subtitle !== ""){
body.insertParagraph(0, tpInfo.subtitle).setAlignment(DocumentApp.HorizontalAlignment.CENTER);
topSpaces = topSpaces - 1;
}
body.insertParagraph(0, tpInfo.title.toUpperCase()).setAlignment(DocumentApp.HorizontalAlignment.CENTER);
for(var i = 0; i < topSpaces; i++){
body.insertParagraph(0, "").setAlignment(DocumentApp.HorizontalAlignment.CENTER);
}
storeSettings('tpInfo', tpInfo);
}
// Remove title page
function removeTitlePage(){
// Find first page break and delete everything up to that
var body = DocumentApp.getActiveDocument().getBody();
var PBindex;
for(var i = 0; i < body.getNumChildren(); i++){
var p = body.getChild(i);
// But make sure they haven't deleted the page themselves! If so, expect a scene header somewhere before the first page break
var sceneText = p.asParagraph()
sceneText = sceneText.getText().toUpperCase();
var sceneConditions = [
sceneText.substr(0,4) === 'INT.', // 1. Starts with 'int.' or 'ext.'
sceneText.substr(0,4) === 'EXT.',
!isNaN(parseInt(sceneText.substr(0,1))) && (sceneText.indexOf('INT.') > -1 || sceneText.indexOf('EXT.') > -1)
];
if(matches(sceneConditions)){
// Assume they've deleted thepage themselves and only delete up to the scene header
PBindex = i - 1;
// prompt('Its a match');
break
}
// If we find a page break before we find a scene header, delete up to that
if(p.findElement(DocumentApp.ElementType.PAGE_BREAK)){
PBindex = i;
break;
};
}
for(var i = 0; i < PBindex + 1; i++){
body.removeChild(body.getChild(0));
}
}