-
Notifications
You must be signed in to change notification settings - Fork 1
/
thread-link.js
31 lines (30 loc) · 1.18 KB
/
thread-link.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
29
30
31
(function () {
'use strict';
console.log("loaded extension - GChat ThreadLink");
var threads = document.querySelectorAll('c-wiz[data-topic-id]');
for (var i = 0; i < threads.length; i++) {
var thread = threads[i];
var threadId = thread.dataset.topicId;
var threadLink = document.URL + "/" + threadId;
var follow = thread.querySelector('div[aria-label=Follow]');
if (!follow) { continue }
var threadLinkButtonId = 'permalink-' + threadId;
if (!document.getElementById(threadLinkButtonId)) {
var a = document.createElement('a');
a.href = threadLink;
a.title = "Permalink";
a.innerText = "#";
a.style = "padding: 0 0.3em 0 0.5em;font-weight: bold;";
a.addEventListener('click', copyLinkToClipboard)
var followWrapper = follow.parentNode.parentNode;
followWrapper.appendChild(a);
}
}
})();
function copyLinkToClipboard(event) {
event.preventDefault();
navigator.clipboard.writeText(event.target.href)
.catch(function (err) {
console.log("error occurred while copying to clipboard: ", err)
});
}