Initial
This commit is contained in:
8
vocabulary-editing/README.md
Normal file
8
vocabulary-editing/README.md
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
# Tampermonkey scripts for customizing musdb for the purpose of vocabulary control
|
||||
|
||||
## TransferEvent.user.js
|
||||
|
||||
This script adds a button on each event component of the object editing page. Using this button, one can immediately transfer the name of a linked actor or place to the object description and remove the link to the given actor or place.
|
||||
|
||||

|
BIN
vocabulary-editing/TransferEvent.png
Normal file
BIN
vocabulary-editing/TransferEvent.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
114
vocabulary-editing/TransferEvent.user.js
Normal file
114
vocabulary-editing/TransferEvent.user.js
Normal file
@ -0,0 +1,114 @@
|
||||
// ==UserScript==
|
||||
// @name TransferEvent
|
||||
// @namespace http://tampermonkey.net/
|
||||
// @version 0.1
|
||||
// @description Transfer events to object description
|
||||
// @author Nathan Eikermann
|
||||
// @match https://sandkasten.museum-digital.de/musdb/objekt_cha.php*
|
||||
// @icon https://www.google.com/s2/favicons?sz=64&domain=museum-digital.de
|
||||
// @grant none
|
||||
// ==/UserScript==
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
const objectId = document.getElementById("objCounter").textContent;
|
||||
|
||||
const eventModuleOld = document.getElementById("eventModuleOld");
|
||||
|
||||
function identifyEventId(href) {
|
||||
|
||||
console.log("Parsing event ID from " + href)
|
||||
const urlParams = new URLSearchParams(href.substring(href.indexOf('?')));
|
||||
console.log(urlParams)
|
||||
return urlParams.get('ernum');
|
||||
|
||||
}
|
||||
|
||||
function createButton(title) {
|
||||
const button = document.createElement('span');
|
||||
button.textContent = title;
|
||||
button.style.background = "#000";
|
||||
button.style.color = "#FFF";
|
||||
button.style.cursor = "pointer";
|
||||
button.style.margin = "0 20px"
|
||||
return button;
|
||||
}
|
||||
|
||||
function createClickFunction(newObjectText, eventId, eventTypeId) {
|
||||
return function() {
|
||||
let updated = 0;
|
||||
|
||||
window.fetch('/musdb/objekt_update.php', {
|
||||
method: 'POST', cache: 'no-cache',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
body: "objektnum=" + encodeURIComponent(objectId) + '&objekt_beschreibung=' + encodeURIComponent(document.getElementById('objekt_beschreibung').textContent + "\n\n" + newObjectText)
|
||||
}).then(function(response) {
|
||||
|
||||
updated++;
|
||||
if (updated === 2) location.reload();
|
||||
|
||||
}).catch((error) => {
|
||||
console.log(error);
|
||||
});
|
||||
|
||||
window.fetch('/musdb/api_int/object/update_event/' + objectId, {
|
||||
method: 'POST', cache: 'no-cache',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
body: eventTypeId + '=0&event_id=' + encodeURIComponent(eventId)
|
||||
}).then(function(response) {
|
||||
|
||||
updated++;
|
||||
if (updated === 2) location.reload();
|
||||
|
||||
}).catch((error) => {
|
||||
console.log(error);
|
||||
});
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
for (let child of eventModuleOld.children) {
|
||||
|
||||
// Get update link to identify event ID
|
||||
const updateLink = child.getElementsByClassName("iconsEdit")[0];
|
||||
if (updateLink === undefined) continue;
|
||||
|
||||
// Identify event ID
|
||||
const eventId = identifyEventId(updateLink.href);
|
||||
console.log(eventId);
|
||||
|
||||
const actorLinks = child.getElementsByClassName('actorToolTip');
|
||||
if (actorLinks.length !== 0) {
|
||||
const actorLink = actorLinks[0];
|
||||
|
||||
const button = createButton('Transfer')
|
||||
actorLink.parentElement.appendChild(button);
|
||||
|
||||
button.addEventListener('click', createClickFunction(actorLink.textContent, eventId, 'persinst_id'), {once: true});
|
||||
|
||||
}
|
||||
|
||||
|
||||
const placeLinks = child.getElementsByClassName('placeToolTip');
|
||||
if (actorLinks.length !== 0) {
|
||||
const placeLink = placeLinks[0];
|
||||
|
||||
const button = createButton('Transfer')
|
||||
placeLink.parentElement.appendChild(button);
|
||||
|
||||
button.addEventListener('click', createClickFunction(placeLink.textContent, eventId, 'place_id'), {once: true});
|
||||
|
||||
}
|
||||
|
||||
// Offer manipulating actor
|
||||
|
||||
}
|
||||
|
||||
})();
|
Reference in New Issue
Block a user