-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathsidebar.gs
58 lines (44 loc) · 1.73 KB
/
sidebar.gs
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 updateProps(tempSettings) {
const docProps = PropertiesService.getDocumentProperties()
for (const labCode in tempSettings) {
docProps.setProperty(getPropKey(labCode), encodeSetting(tempSettings[labCode]))
}
updateDoc()
return '#save'
}
function storeDefault(tempSettings) {
const userProps = PropertiesService.getUserProperties()
for (const labCode in tempSettings) {
const setting = tempSettings[labCode]
userProps.setProperty(getPropKey(labCode), encodeSetting(setting))
}
return '#save-defaults'
}
const storeCustom = setting => PropertiesService.getUserProperties().setProperty(getPropKey(setting.lab.code), encodeSetting(setting))
function getDefaults() {
const userPropStore = PropertiesService.getUserProperties()
const settings = getDefaultSettings()
return patchSettings(settings, userPropStore)
}
// Remove a custom category from user prop stores
function removePair(code) {
if (isDefault(code)) return new Error('cannot delete default code')
PropertiesService.getUserProperties().deleteProperty("cross_" + code)
PropertiesService.getDocumentProperties().deleteProperty("cross_" + code)
}
// Return the color of highlighted text
function cloneColor(type='lab') {
const selection = DocumentApp.getActiveDocument().getSelection()
if (!selection) {
DocumentApp.getUi().alert(
"Clone colour", "Please select some text with the colour you want to clone.",
DocumentApp.getUi().ButtonSet.OK
)
return
}
const element = selection.getRangeElements()[0]
if (!element.getElement().editAsText) return
const text = element.getElement().editAsText()
const offset = element.isPartial() ? element.getStartOffset() : 0
return text.getAttributes(offset).FOREGROUND_COLOR
}