-
Notifications
You must be signed in to change notification settings - Fork 2
/
guessSeriesRelationship.js
28 lines (23 loc) · 1.04 KB
/
guessSeriesRelationship.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
/**
* - Guesses the series name from the name of the currently edited entity and adds a relationship.
* - Tries to extract the series number from the entity name to use it as relationship attribute.
* - Currently limited to release groups, both via their edit pages and via the release relationship editor.
*/
import { createDialog } from '../relationship-editor/createDialog.js';
async function guessSeriesRelationship(entityName) {
const seriesMatch = entityName.match(/(.+?)(?: (\d+))?:/);
if (!seriesMatch) return;
const sourceEntity = MB.relationshipEditor.state.entity;
createDialog({
source: sourceEntity.releaseGroup ?? sourceEntity, // prefer the RG for releases
target: seriesMatch[1],
targetType: 'series',
linkTypeId: 742, // depends on the target entity type, for RGs only so far
attributes: [{
type: { gid: 'a59c5830-5ec7-38fe-9a21-c7ea54f6650a' }, // number (in a series)
text_value: seriesMatch[2],
}],
});
}
const entityName = document.querySelector('h1 bdi').textContent;
guessSeriesRelationship(entityName);