X-Git-Url: https://git.ktnx.net/?p=icedeb.git;a=blobdiff_plain;f=icedeb.js;h=be9c21771b73b1b56f34e6b4676ec5710c5cfb32;hp=c36044c7c6d3a4d75c29cb3cc37f218aaa25f21e;hb=0709382658bc0826abbcd39b250f6238ee095f07;hpb=f58a4234607ccc574ea15773b26c7fec6eb259d7 diff --git a/icedeb.js b/icedeb.js index c36044c..be9c217 100644 --- a/icedeb.js +++ b/icedeb.js @@ -116,15 +116,10 @@ function link_clicked(e) { return false; } - if ( !e.target.classList.contains('icedeb-button') ) - return; - - let autoclose = true; - let clip_input = document.getElementById("clipboard"); let clip = trim(clip_input.value); - console.log(clip); + if(clip_input.value == '') return; let url; @@ -142,17 +137,19 @@ function link_clicked(e) { url = 'https://lists.debian.org/msgid-search/' + clip; break; case 'ddpo': - url = 'https://qa.debian.org/developer.php'; - if (clip != '') - url += '?login=' + clip; + url = 'https://qa.debian.org/developer.php?login=' + clip; + break; + case 'dmd': + url = 'https://udd.debian.org/dmd.cgi?email1=' + clip; break; case 'buildd': url = 'https://buildd.debian.org/' + clip; break; case 'security': - url = 'https://security-tracker.debian.org/'; - if (clip != '') - url += 'tracker/' + clip; + url = 'https://security-tracker.debian.org/tracker/' + clip; + break; + case 'r-b': + url = 'https://tests.reproducible-builds.org/debian/rb-pkg/' + clip + '.html'; break; } @@ -164,8 +161,61 @@ function link_clicked(e) { } }); -window.addEventListener('load', (e) => { - document.getElementById('button-list-container').addEventListener('click', link_clicked); + e.preventDefault(); + return false; +} + +function check_likely_inputs(q) { + let cnt = document.getElementById('button-list-container').classList; + + cnt.remove('like-b', 'like-p', 'like-m', 'like-i'); + document.querySelectorAll('.likely') + .forEach((el) => { + el.classList.remove('likely'); + }); + + if ( /^\d+$/.test(q) || /^CVE-/.test(q) ) + cnt.add('like-b'); + + if ( /^[a-z0-9][a-z0-9\-+.]+$/.test(q) ) + cnt.add('like-p'); + + if ( /.@[a-z0-9-]/i.test(q) ) + cnt.add('like-m'); + + if ( /^<.+@.+>$/.test(q) ) + cnt.add('like-i'); + + document.querySelectorAll('.like-b .hint.b, .like-p .hint.p, .like-m .hint.m, .like-i .hint.i') + .forEach((el) => { + el.parentElement.parentElement.classList.add('likely'); + } ); +} + +function get_clipboard_contents() { + let clip_pot = document.getElementById('clip-pot'); + let clip_input = document.getElementById("clipboard"); + clip_pot.focus(); + if (document.execCommand("Paste")) { + let q = clip_pot.textContent.trim(); + clip_input.value = q; + clip_input.focus(); + clip_input.setSelectionRange(0, clip_input.value.length); + + check_likely_inputs(q); + } +} + +window.addEventListener('DOMContentLoaded', (e) => { + document.querySelectorAll('.icedeb-button, #button-list-container a') + .forEach(function(el){ + el.addEventListener('mouseup', link_clicked); + }); + + document.querySelector('#clipboard') + .addEventListener('input', function(ev) { + check_likely_inputs(ev.target.value); + }); document.addEventListener('change', (e) => { if ( !e.target.classList.contains('icedeb-option') ) @@ -174,11 +224,7 @@ window.addEventListener('load', (e) => { save_settings(); }); - let clip_input = document.getElementById("clipboard"); - clip_input.focus(); - if (!document.execCommand("paste")) { - let err = document.getElementById('error'); - err.textContent = 'Error retrieving clipboard contents'; - err.classList.remove('hidden'); - } + window.requestAnimationFrame(()=>{ + window.requestAnimationFrame(get_clipboard_contents); + }); });