-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.inc.php
72 lines (65 loc) · 2.32 KB
/
main.inc.php
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/*
Plugin Name: piwigo-plugin-prompts
Version: 1.0
Description: better support for prompts
Author: hulucc
*/
if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
function add_prompts_detail() {
global $template;
$js = <<<EOT
function insertCopyButton() {
var element = document.querySelector('p.imageComment');
var button = document.createElement('button');
button.textContent = 'Copy';
button.addEventListener('click', function() {
var content = element.textContent;
var tempInput = document.createElement('textarea');
tempInput.style.position = 'fixed';
tempInput.style.opacity = 0;
tempInput.value = content;
document.body.appendChild(tempInput);
tempInput.select();
document.execCommand('copy');
document.body.removeChild(tempInput);
});
element.parentNode.insertBefore(button, element.nextSibling);
}
function insertDiv(id, titleText, contentText) {
var categories = document.getElementById("Categories");
var newDiv = document.createElement("div");
newDiv.id = id;
newDiv.className = "imageInfo";
var title = document.createElement("dt");
title.innerText = titleText;
var content = document.createElement("dd");
content.innerText = contentText;
newDiv.appendChild(title);
newDiv.appendChild(content);
categories.parentNode.insertBefore(newDiv, categories);
}
function parseInfo(infoString) {
const targetInfo = infoString;
const regex = /([A-Z][\s\w\d]+):\s(("[^"]+")|([\s\w\d\+]+))/g;
let match;
let infoObj = {};
while ((match = regex.exec(targetInfo)) !== null) {
const key = match[1].trim();
const value = match[2].trim();
// Remove the quotes if they exist
const finalValue = value[0] === '"' ? value.slice(1, -1) : value;
infoObj[key] = finalValue;
}
return infoObj;
}
var data = document.querySelector('p.imageComment').innerText.replaceAll('\\n', ',');
obj = parseInfo(data)
for (const [key, value] of Object.entries(obj)) {
insertDiv(key, key, value);
}
insertCopyButton();
EOT;
$template->block_footer_script('', $js);
}
add_event_handler('loc_end_picture', 'add_prompts_detail');