|
1 | | -(function () { |
2 | | - "use strict"; |
3 | | - function AppendTitleField(text, event) { |
4 | | - if ((!event.altKey && !event.ctrlKey) || event.shiftKey) { |
5 | | - try { |
6 | | - var titleInput = document.getElementById("title"); |
7 | | - if (event.shiftKey) titleInput.value = text; |
8 | | - else titleInput.value += text; |
9 | | - console.log("Appended title to title field: " + text); |
10 | | - } catch (err) { |
11 | | - console.error("Failed to append text to title field:", err); |
12 | | - } |
| 1 | +(function() { |
| 2 | + 'use strict'; |
| 3 | + function AppendTitleField(text, event) { |
| 4 | + if ((!event.altKey && !event.ctrlKey) || event.shiftKey) { |
| 5 | + try { |
| 6 | + var titleInput = document.getElementById('title'); |
| 7 | + if (event.shiftKey) |
| 8 | + titleInput.value = text; |
| 9 | + else |
| 10 | + titleInput.value += text; |
| 11 | + console.log('Appended title to title field: ' + text); |
| 12 | + } catch (err) { |
| 13 | + console.error('Failed to append text to title field:', err); |
| 14 | + } |
| 15 | + } |
| 16 | + |
| 17 | + var textArea = null; |
| 18 | + var fileckUrl = null; |
| 19 | + if (event.altKey) { |
| 20 | + try { |
| 21 | + const navElements = document.querySelectorAll("a"); |
| 22 | + for (const element of navElements) |
| 23 | + { |
| 24 | + var ckUrl = decodeURI(element.href); |
| 25 | + if (ckUrl.startsWith("file://")){ |
| 26 | + fileckUrl = ckUrl; |
| 27 | + ckUrl = ckUrl.replace("file:///", ""); |
| 28 | + ckUrl = ckUrl.replace("file://", ""); |
| 29 | + console.debug("Copping " + ckUrl + " to clipboard"); |
| 30 | + textArea = document.createElement("textarea"); |
| 31 | + textArea.value = ckUrl; |
| 32 | + document.body.appendChild(textArea); |
| 33 | + textArea.select(); |
| 34 | + break; |
| 35 | + } |
| 36 | + } |
| 37 | + } catch (err) { |
| 38 | + console.error('Failed to get file URL:', err); |
| 39 | + } |
| 40 | + } |
| 41 | + else if (event.ctrlKey) { |
| 42 | + try { |
| 43 | + console.debug("Copping " + text + " to clipboard"); |
| 44 | + textArea = document.createElement("textarea"); |
| 45 | + textArea.value = text; |
| 46 | + document.body.appendChild(textArea); |
| 47 | + textArea.select(); |
| 48 | + } catch (err) { |
| 49 | + console.error('Failed to get title:', err); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + if (textArea != null) |
| 54 | + { |
| 55 | + try { |
| 56 | + var successful = document.execCommand('copy'); |
| 57 | + var msg = successful ? 'successful' : 'unsuccessful'; |
| 58 | + console.log('Text copy ' + msg + ':', textArea.value); |
| 59 | + } catch (err) { |
| 60 | + console.error('Failed to copy text to clipboard:', err); |
| 61 | + } |
| 62 | + document.body.removeChild(textArea); |
| 63 | + try { |
| 64 | + if (fileckUrl != null && event.ctrlKey){ |
| 65 | + window.open(fileckUrl, "_blank"); |
| 66 | + console.log('Opening link ' + fileckUrl); |
| 67 | + } |
| 68 | + } catch (err) { |
| 69 | + console.error("Failed to open link '" + fileckUrl + "' with error:", err); |
| 70 | + } |
| 71 | + |
| 72 | + } |
13 | 73 | } |
14 | 74 |
|
15 | | - var textArea = null; |
16 | | - var fileckUrl = null; |
17 | | - if (event.altKey) { |
18 | | - try { |
19 | | - const navElements = document.querySelectorAll("a"); |
20 | | - for (const element of navElements) { |
21 | | - var ckUrl = decodeURI(element.href); |
22 | | - if (ckUrl.startsWith("file://")) { |
23 | | - fileckUrl = ckUrl; |
24 | | - ckUrl = ckUrl.replace("file:///", ""); |
25 | | - ckUrl = ckUrl.replace("file://", ""); |
26 | | - console.debug("Copping " + ckUrl + " to clipboard"); |
27 | | - textArea = document.createElement("textarea"); |
28 | | - textArea.value = ckUrl; |
29 | | - document.body.appendChild(textArea); |
30 | | - textArea.select(); |
31 | | - break; |
32 | | - } |
33 | | - } |
34 | | - } catch (err) { |
35 | | - console.error("Failed to get file URL:", err); |
36 | | - } |
37 | | - } else if (event.ctrlKey) { |
38 | | - try { |
39 | | - console.debug("Copping " + text + " to clipboard"); |
40 | | - textArea = document.createElement("textarea"); |
41 | | - textArea.value = text; |
42 | | - document.body.appendChild(textArea); |
43 | | - textArea.select(); |
44 | | - } catch (err) { |
45 | | - console.error("Failed to get title:", err); |
46 | | - } |
| 75 | + function wrapElement(element) { |
| 76 | + var text = element.textContent.trim(); |
| 77 | + var anchor = document.createElement('a'); |
| 78 | + anchor.href = '#'; |
| 79 | + anchor.textContent = text; |
| 80 | + anchor.classList.add('renamefile'); |
| 81 | + anchor.title = 'Click to append title to [Title] input field; OR ctrl-key & mouse click to copy title to clipboard; OR shift-key click to copy to [Title] input field; OR alt-key click to copy file URI to clipboard.'; |
| 82 | + anchor.addEventListener('click', function(event) { |
| 83 | + event.preventDefault(); |
| 84 | + AppendTitleField(text, event); |
| 85 | + }); |
| 86 | + element.innerHTML = ''; |
| 87 | + element.appendChild(anchor); |
47 | 88 | } |
48 | 89 |
|
49 | | - if (textArea != null) { |
50 | | - try { |
51 | | - var successful = document.execCommand("copy"); |
52 | | - var msg = successful ? "successful" : "unsuccessful"; |
53 | | - console.log("Text copy " + msg + ":", textArea.value); |
54 | | - } catch (err) { |
55 | | - console.error("Failed to copy text to clipboard:", err); |
56 | | - } |
57 | | - document.body.removeChild(textArea); |
58 | | - try { |
59 | | - if (fileckUrl != null && event.ctrlKey) { |
60 | | - window.open(fileckUrl, "_blank"); |
61 | | - console.log("Opening link " + fileckUrl); |
62 | | - } |
63 | | - } catch (err) { |
64 | | - console.error( |
65 | | - "Failed to open link '" + fileckUrl + "' with error:", |
66 | | - err |
67 | | - ); |
68 | | - } |
69 | | - } |
70 | | - } |
71 | | - |
72 | | - function wrapElement(element) { |
73 | | - var text = element.textContent.trim(); |
74 | | - var anchor = document.createElement("a"); |
75 | | - anchor.href = "#"; |
76 | | - anchor.textContent = text; |
77 | | - anchor.classList.add("renamefile"); |
78 | | - anchor.title = |
79 | | - "Click to append title to [Title] input field; OR ctrl-key & mouse click to copy title to clipboard; OR shift-key click to copy to [Title] input field; OR alt-key click to copy file URI to clipboard."; |
80 | | - anchor.addEventListener("click", function (event) { |
81 | | - event.preventDefault(); |
82 | | - AppendTitleField(text, event); |
83 | | - }); |
84 | | - element.innerHTML = ""; |
85 | | - element.appendChild(anchor); |
86 | | - } |
87 | | - |
88 | | - function handleMutations(mutationsList, observer) { |
89 | | - for (const mutation of mutationsList) { |
90 | | - for (const addedNode of mutation.addedNodes) { |
91 | | - if ( |
92 | | - addedNode.nodeType === Node.ELEMENT_NODE && |
93 | | - addedNode.querySelector(".scene-header div.TruncatedText") |
94 | | - ) { |
95 | | - wrapElement( |
96 | | - addedNode.querySelector(".scene-header div.TruncatedText") |
97 | | - ); |
| 90 | + function handleMutations(mutationsList, observer) { |
| 91 | + for(const mutation of mutationsList) { |
| 92 | + for(const addedNode of mutation.addedNodes) { |
| 93 | + if (addedNode.nodeType === Node.ELEMENT_NODE && addedNode.querySelector('.scene-header div.TruncatedText')) { |
| 94 | + wrapElement(addedNode.querySelector('.scene-header div.TruncatedText')); |
| 95 | + } |
| 96 | + } |
98 | 97 | } |
99 | | - } |
100 | 98 | } |
101 | | - } |
102 | | - const observer = new MutationObserver(handleMutations); |
103 | | - observer.observe(document.body, { childList: true, subtree: true }); |
| 99 | + const observer = new MutationObserver(handleMutations); |
| 100 | + observer.observe(document.body, { childList: true, subtree: true }); |
104 | 101 | })(); |
0 commit comments