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:el-GR			Αντιγραφή συνδέσμου ΔΙΑΥΓΕΙΑΣ
// @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.
// @description:el-GR	Αυτός ο κώδικας εμφανίζει ένα εικονίδιο στα δεξιά του συνδέσμου «Προβολή αρχείου» στα αποτελέσματα της ΔΙΑΥΓΕΙΑΣ, όπου πατώντας αντιγράφει τη διεύθυνση του αρχείου σε αναγνώσιμη μορφή.
// @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});
})();