-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormat settings.js
More file actions
58 lines (53 loc) · 1.83 KB
/
Format settings.js
File metadata and controls
58 lines (53 loc) · 1.83 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
function clearFormatSettings() {
const userProperties = PropertiesService.getUserProperties();
userProperties.deleteProperty('FORMAT_SETTINGS');
onOpen();
}
function getSettings(tryToRetrieveProperties, defaultSettings, allMenuItemsObj, propertyKey) {
const resultObj = {
marker: '',
style: defaultSettings,
menuText: allMenuItemsObj[defaultSettings]['menuText']
};
if (tryToRetrieveProperties === true) {
try {
const savedSettings = PropertiesService.getUserProperties().getProperty(propertyKey);
if (savedSettings != null && allMenuItemsObj.hasOwnProperty(savedSettings)) {
resultObj['style'] = savedSettings;
resultObj['menuText'] = allMenuItemsObj[savedSettings]['menuText'];
}
resultObj['marker'] = '✅';
}
catch (error) {
// Logger.log('Needs to activate!!! ' + error);
}
}
return resultObj;
}
function activateFormatStyle(obj) {
activateSettings(formatStyles, obj, 'FORMAT_SETTINGS');
}
function activateSettings(allMenuItemsObj, targetObj, propertyKey){
const value = Object.keys(allMenuItemsObj).find(key => allMenuItemsObj[key] === targetObj);
PropertiesService.getUserProperties().setProperty(propertyKey, value);
onOpen();
}
// Menu items of format style
const formatStyles = {
"txt": {
"menuText": "Format: Sequential in text",
"run": function () { activateFormatStyle(this); }
},
"footnotes": {
"menuText": "Format: First translation in text, others in footnote",
"run": function () { activateFormatStyle(this); }
},
"table": {
"menuText": "Format: Original text and translation(s) in table",
"run": function () { activateFormatStyle(this); }
},
/* "comments": {
"menuText": "Format: Primary language in text, rest in comment (links are preserved)",
"run": function () { activateFormatStyle(this); }
} */
}