From 223e230e4908e3794f0726dcb661cdbfa4d6384e Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sat, 29 Jul 2023 10:51:15 -0400 Subject: [PATCH] Fix looking up clickable URLs in code viewer Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/2759 --- src/js/code-viewer.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/js/code-viewer.js b/src/js/code-viewer.js index 6f6cdb55b..b2225013e 100644 --- a/src/js/code-viewer.js +++ b/src/js/code-viewer.js @@ -284,7 +284,25 @@ async function start() { }); dom.on('#content', 'click', '.cm-href', ev => { - setURL(ev.target.textContent); + const target = ev.target; + const urlParts = [ target.textContent ]; + let previous = target; + for (;;) { + previous = previous.previousSibling; + if ( previous === null ) { break; } + if ( previous.nodeType !== 1 ) { break; } + if ( previous.classList.contains('cm-href') === false ) { break; } + urlParts.unshift(previous.textContent); + } + let next = target; + for (;;) { + next = next.nextSibling; + if ( next === null ) { break; } + if ( next.nodeType !== 1 ) { break; } + if ( next.classList.contains('cm-href') === false ) { break; } + urlParts.push(next.textContent); + } + setURL(urlParts.join('')); }); }