From 82b33289cb1e060aa3d4e798497f49f03a992f05 Mon Sep 17 00:00:00 2001 From: louy2 <2263580+louy2@users.noreply.github.com> Date: Sun, 26 Apr 2020 08:57:04 -0400 Subject: [PATCH 1/2] Redirect correctly when URL matches multiple rows We find the row in infobox with URL by regex matching on URL or Website. This commit handles the edge case that some infoboxes mentions URL or Website before the actual URL row. The test case is recorded in a new testcases.txt file. --- browser-extension/common.js | 8 +++++++- browser-extension/testcases.txt | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 browser-extension/testcases.txt diff --git a/browser-extension/common.js b/browser-extension/common.js index 0cf9ca6..9de1e10 100644 --- a/browser-extension/common.js +++ b/browser-extension/common.js @@ -17,7 +17,13 @@ function redirect(searchQuery) { var wikiUrlRow = infoboxRows.filter(x => x.innerText.match(/(?:URL)|(?:Website)/)); if (wikiUrlRow[0]) { - return wikiUrlRow[0].querySelector('a').href; + for (var i in wikiUrlRow) { + var a = wikiUrlRow[i].querySelector('a'); + if (a) { + return a.href; + } + } + return wikiUrl; } else { return wikiUrl; } diff --git a/browser-extension/testcases.txt b/browser-extension/testcases.txt new file mode 100644 index 0000000..8583d8d --- /dev/null +++ b/browser-extension/testcases.txt @@ -0,0 +1 @@ +virustotal.idk \ No newline at end of file From bc76fcb521d68c35dc6edf191546a7af70f8d3c2 Mon Sep 17 00:00:00 2001 From: Yufan Lou <2263580+louy2@users.noreply.github.com> Date: Fri, 10 May 2024 14:16:37 +0800 Subject: [PATCH 2/2] Use let over var Co-authored-by: Ajit Panigrahi --- browser-extension/common.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/browser-extension/common.js b/browser-extension/common.js index 9de1e10..fe72641 100644 --- a/browser-extension/common.js +++ b/browser-extension/common.js @@ -17,8 +17,8 @@ function redirect(searchQuery) { var wikiUrlRow = infoboxRows.filter(x => x.innerText.match(/(?:URL)|(?:Website)/)); if (wikiUrlRow[0]) { - for (var i in wikiUrlRow) { - var a = wikiUrlRow[i].querySelector('a'); + for (let i in wikiUrlRow) { + let a = wikiUrlRow[i].querySelector('a'); if (a) { return a.href; }