-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsta-copy-site-url.user.js
92 lines (73 loc) · 2.63 KB
/
insta-copy-site-url.user.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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// ==UserScript==
// @name Insta-Copy Site URL
// @namespace insta-copy-site-url
// @version 1.3
// @description Instantly copies URL of user's sites in one click.
// @updateURL https://github.com/druesome/andrew-scripts/raw/main/insta-copy-site-url.user.js
// @downloadURL https://github.com/druesome/andrew-scripts/raw/main/insta-copy-site-url.user.js
// @author druesome
// @match https://*.apps.zdusercontent.com/*
// @match https://*.zendesk.com/agent/*
// @require http://code.jquery.com/jquery-latest.js
// @grant GM_addStyle
// @grant GM_setClipboard
// ==/UserScript==
GM_addStyle ( `
span.site-domain {
transition: all 0.3s;
border-radius: 3px;
&:hover {
cursor: pointer;
background-color: #cfe88b;
}
}
span.site-domain {
font-style: normal;
font-size: 13px;
color: #222;
}
` );
var $ = window.jQuery;
// Transform site URLs into clickable elements
function constructLinks() {
$('.user__info_container .sites .site:not(.thisdone)').each(function() {
var $site = $(this);
$site.addClass('thisdone');
// Find all instances of site-domain within the site
var $siteDomains = $site.find('.site-domain');
// Process each instance of site-domain
$siteDomains.each(function(index) {
var $siteDomain = $(this);
var siteURL = $siteDomain.text();
// If the site-domain is the first one, add the cpy_btn class and handle click event
$siteDomain.addClass('cpy_btn');
$siteDomain.on('click', function() {
copy_url(siteURL, $siteDomain);
});
// Set DARC span
var $darcSpan = $siteDomain.next('.darc');
// Remove the surrounding link
$siteDomain.closest('a').contents().unwrap();
// Build a new link around the DARC span and make it open in a new tab
var $darcLink = $('<a>').attr('href', 'https://mc.a8c.com/tools/reportcard/domain/?domain=' + encodeURIComponent(siteURL)).attr('target', '_blank').append($darcSpan);
$siteDomain.after($darcLink);
});
});
}
// Copy the URL
async function copy_url(text, element) {
try {
await navigator.clipboard.writeText(text);
element.text('Copied');
setTimeout(function() {
element.text(text);
}, 2000);
console.log('Text copied to clipboard');
} catch (error) {
console.error('Failed to copy text to clipboard:', error);
}
}
// Loop until all links are done
window.setInterval(function(){
constructLinks();
}, 1000);