Copy link in DIAVGEIA

This code displays an icon on the right side of the link "Προβολή αρχείου" on the search results of DIAVGEIA, where by click on it, it copies the URL of the file in human readable format.

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

// ==UserScript==
// @name			Copy link in DIAVGEIA
// @name:en			Copy link in DIAVGEIA
// @name:el			Αντιγραφή συνδέσμου ΔΙΑΥΓΕΙΑΣ
// @description:en		This code displays an icon on the right side of the link "Προβολή αρχείου" on the search results of DIAVGEIA, where by click on it, it copies the URL of the file in human readable format.
// @description:el	Αυτός ο κώδικας εμφανίζει ένα εικονίδιο στα δεξιά του συνδέσμου «Προβολή αρχείου» στα αποτελέσματα της ΔΙΑΥΓΕΙΑΣ, όπου πατώντας αντιγράφει τη διεύθυνση του αρχείου σε αναγνώσιμη μορφή.
// @author			Δρ. Παναγιώτης Ε. Παπάζογλου (Δασαρχείο Μετσόβου)
// @namespace		diavgeia
// @version			1.1
// @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
// @description This code displays an icon on the right side of the link "Προβολή αρχείου" on the search results of DIAVGEIA, where by click on it, it copies the URL of the file in human readable format.
// ==/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,.ada').length===0)
							{
								lnk.after('<span class="copy-icon" title="Αντιγραφή συνδέσμου ΔΙΑΥΓΕΙΑΣ" style="cursor:pointer">📋</span><span class="check-icon" title="Η διεύθυνση αντιγράφτηκε" style="display:none">✅</span> <span class="ada" title="Αντιγραφή ΑΔΑ" style="cursor:pointer">ΑΔΑ</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);
									});
								});
								lnk.nextAll('.ada').first().on('click',function(e)
								{
									e.preventDefault();
									navigator.clipboard.writeText(decodeURIComponent(lnk.attr('href')).split('/').pop().split('?')[0]).then(()=>
									{
										lnk.nextAll('.ada').first().css({'font-weight':'bold','color':'rgb(60,125,34)'});
										setTimeout(()=>{lnk.nextAll('.ada').first().css({'font-weight':'normal','color':'rgb(0,0,0)'});},3000);
										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(),3000);
									});
								});
							}
							else
							{
								return;
							}
						});
						return;
					}
				}
			}
		}
	});
	observer.observe(document.body,{childList:true,subtree:true});
})();