X-Git-Url: https://git.ktnx.net/?p=icedeb.git;a=blobdiff_plain;f=icedeb.js;h=41117778fa9a08fc08acb30ff44b05acb69b465b;hp=9c9a77053aa597e6b418f69d5efd6c2306a92eb6;hb=c28c4dad3eb96d8ad3a01ea68aa1c29c4fbddce9;hpb=aee59ae1e856b0f51f4806fdadfdb6ecda01609e diff --git a/icedeb.js b/icedeb.js index 9c9a770..4111777 100644 --- a/icedeb.js +++ b/icedeb.js @@ -30,6 +30,7 @@ function trim(word) { word = word.replace(/^[^a-zA-Z0-9]+/, ''); word = word.replace(/[^a-zA-Z0-9]+$/, ''); word = word.replace(/^Bug#/i, ''); + word = word.replace(/^#/, ''); } while ( oldword != word ); return word; @@ -117,8 +118,6 @@ function link_clicked(e) { } let clip_input = document.getElementById("clipboard"); - if(clip_input.value == '') - get_clipboard_contents(); let clip = trim(clip_input.value); if(clip_input.value == '') return; @@ -139,17 +138,24 @@ 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; + clip = clip.replace(' ', '-'); + clip = clip.toUpperCase(); + url = 'https://security-tracker.debian.org/tracker/' + clip; + break; + case 'piuparts': + url = `https://piuparts.debian.org/sid/source/${clip.substring(0,1)}/${clip}.html`; + break; + case 'r-b': + url = 'https://tests.reproducible-builds.org/debian/rb-pkg/' + clip + '.html'; break; } @@ -165,21 +171,62 @@ function link_clicked(e) { return false; } -function get_clipboard_contents() { - document.getElementById('error').classList.add('hidden'); +function check_likely_inputs(q) { + let cnt = document.getElementById('button-list-container').classList; + + cnt.remove('like-b', 'like-p', 'like-m', 'like-i', 'like-s'); + document.querySelectorAll('.likely') + .forEach((el) => { + el.classList.remove('likely'); + }); + + q = q.replace(/^\s+/, ''); + q = q.replace(/\s+$/, ''); + + 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'); + + if ( /^d[sl]a[- ]\d+(-\d+)?$/i.test(q) ) + cnt.add('like-s'); - let clip_pot = document.getElementById('clip-pot'); + document.querySelectorAll('.like-b .hint.b, .like-p .hint.p, .like-m .hint.m, .like-i .hint.i, .like-s .hint.s') + .forEach((el) => { + el.parentElement.parentElement.classList.add('likely'); + } ); +} + +function react_to_clipboard_text(text) { let clip_input = document.getElementById("clipboard"); - clip_pot.focus(); - if (!document.execCommand("Paste")) { - let err = document.getElementById('error'); - err.textContent = 'Error retrieving clipboard contents'; - err.classList.remove('hidden'); + clip_input.value = text; + clip_input.focus(); + clip_input.setSelectionRange(0, clip_input.value.length); + + check_likely_inputs(text); +} + +function get_clipboard_contents() { + if (navigator.clipboard && navigator.clipboard.readText) { + navigator.clipboard.readText().then(function(q){ + react_to_clipboard_text(q); + }); } else { - clip_input.value = clip_pot.textContent.trim(); - clip_input.focus(); - clip_input.setSelectionRange(0, clip_input.value.length) + 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(); + react_to_clipboard_text(q); + } } } @@ -189,6 +236,11 @@ window.addEventListener('DOMContentLoaded', (e) => { 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') ) return; @@ -200,3 +252,5 @@ window.addEventListener('DOMContentLoaded', (e) => { window.requestAnimationFrame(get_clipboard_contents); }); }); + +// vim: sw=2