-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathparseCopyrightNotice.user.js
More file actions
38 lines (33 loc) · 1.39 KB
/
Copy pathparseCopyrightNotice.user.js
File metadata and controls
38 lines (33 loc) · 1.39 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
import { addCopyrightRelationships } from '../relationship-editor/addCopyrightRelationships.js';
import { addParserButton, buildCreditParserUI } from '../creditParserUI.js';
import { nameToMBIDCache } from '../nameToMBIDCache.js';
import { parseCopyrightNotice } from '../parseCopyrightNotice.js';
import { dom } from '@kellnerd/es-utils/dom/select.js';
import { getPatternAsRegExp } from '@kellnerd/es-utils/regex/parse.js';
function buildCopyrightParserUI() {
const terminatorInput = dom('credit-terminator');
const nameSeparatorInput = dom('name-separator');
nameToMBIDCache.load();
addParserButton('Parse copyright notice', async (creditLine, event) => {
const copyrightInfo = parseCopyrightNotice(creditLine, {
terminatorRE: getPatternAsRegExp(terminatorInput.value || '/$/'),
nameSeparatorRE: getPatternAsRegExp(nameSeparatorInput.value || '/$/'),
});
if (copyrightInfo.length) {
const result = await addCopyrightRelationships(copyrightInfo, {
forceArtist: event.shiftKey,
bypassCache: event.ctrlKey || event.metaKey,
useAllYears: event.altKey,
});
nameToMBIDCache.store();
return result;
} else {
return 'skipped';
}
}, [
'SHIFT key to force names to be treated as artist names',
'CTRL or ⌘ key to bypass the cache and force a search',
'ALT key to add multiple relationships for multiple years',
].join('\n'));
}
buildCreditParserUI(buildCopyrightParserUI);