Skip to content

Commit b3897e8

Browse files
authored
Merge pull request #1 from SkylineThomasCR/main
Support board view and move button next to original copy link button
2 parents 1cb5a37 + 2aebc25 commit b3897e8

File tree

1 file changed

+46
-39
lines changed

1 file changed

+46
-39
lines changed

main.js

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@
33
// @namespace Violentmonkey Scripts
44
// @match https://collaboration.dataminer.services/*
55
// @grant none
6-
// @version 1.0
7-
// @author Jan-Klaas Kesteloot
8-
// @description 25/3/2024, 20:57:40
6+
// @version 1.1
7+
// @author JKE, TCR
8+
// @description 28/3/2024, 17:26:21
99
// ==/UserScript==
1010

1111
(
1212
function() {
1313
'use strict';
14-
14+
1515
// Function to copy text to clipboard
1616
function copyToClipboard(text) {
1717
const type = "text/html";
1818
const blob = new Blob([text], { type });
1919
const data = [new ClipboardItem({ [type]: blob })];
2020
navigator.clipboard.write(data);
21-
21+
2222
}
23-
24-
25-
23+
24+
25+
2626
function buttonClickFunction() {
2727
// Execute your desired function here
2828
// Find the <a> tag under the div with id "dropdownMenMoreOptions"
@@ -50,53 +50,60 @@
5050
}
5151
} else {
5252
alert('Input field with id "taskTitle" not found!');
53-
53+
5454
}
5555
}
56-
56+
5757
function addButtonToToolbar() {
5858
//var toolbarButtonGroup = document.querySelector('.toolbar-btn-group');
59-
var toolbarButtonGroup = document.querySelector('#navbarsExampleDefault');
60-
61-
if (toolbarButtonGroup) {
59+
var toolbarButtonGroup = document.querySelector('div.toolbar-btn-group');
60+
61+
if (toolbarButtonGroup && toolbarButtonGroup.querySelector('#PrettyDCPLinkCopy') === null) {
6262
// Create the button element
6363
var customButton = document.createElement('button');
64+
customButton.id = 'PrettyDCPLinkCopy'
6465
customButton.classList.add("btn","btn-outline-secondary-custom","btn-toolbar-task-details","d-inline-flex","justify-content-center","align-items-center","ng-star-inserted");
66+
// customButton.style.borderRadius = '50%'; // Makes the button circular
67+
customButton.style.width = '30px'; // Set the width to desired size
68+
customButton.style.height = '30px'; // Set the height to desired size
69+
customButton.style.marginRight = '3px';
6570
customButton.innerHTML = 'Copy';
66-
71+
6772
customButton.innerHTML = '<fa-icon _ngcontent-ng-c2024319211="" class="ng-fa-icon"><svg role="img" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="share" class="svg-inline--fa fa-share fa-fw" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M307 34.8c-11.5 5.1-19 16.6-19 29.2v64H176C78.8 128 0 206.8 0 304C0 417.3 81.5 467.9 100.2 478.1c2.5 1.4 5.3 1.9 8.1 1.9c10.9 0 19.7-8.9 19.7-19.7c0-7.5-4.3-14.4-9.8-19.5C108.8 431.9 96 414.4 96 384c0-53 43-96 96-96h96v64c0 12.6 7.4 24.1 19 29.2s25 3 34.4-5.4l160-144c6.7-6.1 10.6-14.7 10.6-23.8s-3.8-17.7-10.6-23.8l-160-144c-9.4-8.5-22.9-10.6-34.4-5.4z"></path></svg></fa-icon>';
68-
73+
6974
customButton.addEventListener('click', buttonClickFunction);
70-
75+
7176
// Append the button to the toolbar
7277
//toolbarButtonGroup.appendChild(customButton);
73-
78+
7479
toolbarButtonGroup.insertBefore(customButton, toolbarButtonGroup.childNodes[1]);
75-
76-
// Disconnect the observer once the button is added
77-
observer.disconnect();
7880
}
7981
}
80-
81-
// Create a MutationObserver to watch for changes in the DOM
82-
var observer = new MutationObserver(addButtonToToolbar);
83-
84-
// Configure the observer to watch for changes in the body subtree
85-
observer.observe(document.body, { childList: true, subtree: true });
86-
87-
// Initially check if the toolbar is already available
88-
addButtonToToolbar();
89-
90-
91-
82+
83+
function observeToolbarVisibility(retry) {
84+
var toolbar = document.querySelector('div.toolbar-btn-group');
85+
if (toolbar) {
86+
addButtonToToolbar();
87+
return;
88+
}
89+
if (retry > 0) {
90+
setTimeout(observeToolbarVisibility, 250, retry -1);
91+
}
92+
}
93+
94+
document.addEventListener('click', function(event) {
95+
observeToolbarVisibility(4)
96+
});
97+
98+
99+
100+
observeToolbarVisibility(4);
101+
102+
92103
// window.addEventListener('popstate', function (event) {
93104
// addButtonToToolbar();
94105
//});
95-
96-
97-
106+
107+
108+
98109
})();
99-
100-
101-
102-

0 commit comments

Comments
 (0)