Copy link in DIAVGEIA

Adds an icon to copy link in human readable format in DIAVGEIA

当前为 2025-06-13 提交的版本,查看 最新版本

// ==UserScript==
// @name			Copy link in DIAVGEIA
// @name:el			Αντιγραφή συνδέσμου ΔΙΑΥΓΕΙΑΣ
// @description		Adds an icon to copy link in human readable format in DIAVGEIA
// @description:el	Προσθέτει εικονίδιο για αντιγραφή συνδέσμου σε αναγνώσιμη μορφή στη ΔΙΑΥΓΕΙΑ
// @author			Δρ. Παναγιώτης Ε. Παπάζογλου (Δασαρχείο Μετσόβου)
// @namespace		diavgeia
// @version			1.0
// @match			https://diavgeia.gov.gr/*
// @grant			GM_setClipboard
// @require			https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js
// @license			GPL-3.0-or-later
// ==/UserScript==

(function()
{
	const observer = new MutationObserver((mutationsList,observer)=>
	{
		for(const mutation of mutationsList)
		{
			for(const node of mutation.addedNodes)
			{
				if(node.nodeType===Node.ELEMENT_NODE)
				{
					const links = node.querySelectorAll('a[href$="inline=true"]');
					if((node.tagName==='A' && node.href.endsWith('inline=true')) || links.length>0)
					{
						$('a[href$="inline=true"]').each(function()
						{
							var lnk = $(this);
							if(lnk.next('.copy-icon,.check-icon').length===0)
							{
								lnk.after('<span class="copy-icon" title="Αντιγραφή συνδέσμου ΔΙΑΥΓΕΙΑΣ" style="cursor:pointer">📋</span><span class="check-icon" title="Η διεύθυνση αντιγράφτηκε" style="display:none">✅</span>');
								lnk.next('.copy-icon').on('click',function(e)
								{
									e.preventDefault();
									navigator.clipboard.writeText(decodeURIComponent(lnk.attr('href'))).then(()=>
									{
										lnk.nextAll('.copy-icon').first().fadeOut(300,()=>{lnk.nextAll('.check-icon').first().fadeIn(300).delay(1000).fadeOut(300,()=>{lnk.nextAll('.copy-icon').first().fadeIn(300);});});
										let msg=document.createElement('div');
										msg.textContent='Η διεύθυνση αντιγράφτηκε!';
										Object.assign(msg.style,{position:'fixed',top:'50%',left:'50%',transform:'translate(-50%,-50%)',backgroundColor:'rgba(60,125,34,0.8)',color:'white',padding:'10px 20px',borderRadius:'5px',fontSize:'16px',zIndex:99999,fontFamily:'Arial,sans-serif'});
										document.body.appendChild(msg);setTimeout(()=>msg.remove(),5000);
									});
								});
							}
							else
							{
								return;
							}
						});
						return;
					}
				}
			}
		}
	});
	observer.observe(document.body,{childList:true,subtree:true});
})();