From 7ba934e4cfbefd519acdc9c3382f395720681e99 Mon Sep 17 00:00:00 2001 From: AlttiRi <16310547+AlttiRi@users.noreply.github.com> Date: Fri, 21 Jun 2024 21:59:41 +0300 Subject: [PATCH] Update `mainHost` --- dist/href-taker.user.js | 25 ++++++++++++++++--------- package.json | 2 +- src/components/list-helper.js | 23 +++++++++++++++-------- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/dist/href-taker.user.js b/dist/href-taker.user.js index 4db67c6..d53adc4 100644 --- a/dist/href-taker.user.js +++ b/dist/href-taker.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name HrefTaker -// @version 0.12.3-2024.6.21-063a +// @version 0.12.4-2024.6.21-1560 // @namespace gh.alttiri // @description URL grabber popup // @license GPL-3.0 @@ -600,7 +600,18 @@ function storeStateInLS({id: lsName, onMove, onStop, reset, restore}) { function getListHelper(container, settings) { const headerElem = container.querySelector(`#result-list-header`); const contentElem = container.querySelector(`#result-list`); - const mainHost = url => new URL(url).hostname.split(".").slice(-2).join("."); + /** + * @param {string} url + * @return {string} + */ + const mainHost = url => { + try { + return new URL(url).hostname.split(".").slice(-2).join("."); + } catch (e) { + console.error(url, e); + return ""; + } + }; contentElem.addEventListener("click", onClickMarkUrlAsClicked); contentElem.addEventListener("contextmenu", onAltContextMenuUnmarkClickedUrl); @@ -704,14 +715,10 @@ function getListHelper(container, settings) { for (const url of urls) { let linkHtml = urlToHtml(url); if (settings.sort) { - try { - if (mainHost(prev) !== mainHost(url)) { - resultHtml += ``; - } - prev = url; - } catch (e) { - console.error(url, e); + if (mainHost(prev) !== mainHost(url)) { + resultHtml += ``; } + prev = url; } const clicked = clickedUrls.has(url) ? " clicked" : ""; const html = `
`; diff --git a/package.json b/package.json index cc74204..0d4c52d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "href-taker", "private": true, - "version": "0.12.3-2024.6.21-063a", + "version": "0.12.4-2024.6.21-1560", "type": "module", "scripts": { "dev": "vite --open demo.html --host", diff --git a/src/components/list-helper.js b/src/components/list-helper.js index df1a24b..5edc41f 100644 --- a/src/components/list-helper.js +++ b/src/components/list-helper.js @@ -7,7 +7,18 @@ import {hashString} from "../util.js"; export function getListHelper(container, settings) { const headerElem = container.querySelector(`#result-list-header`); const contentElem = container.querySelector(`#result-list`); - const mainHost = url => new URL(url).hostname.split(".").slice(-2).join("."); + /** + * @param {string} url + * @return {string} + */ + const mainHost = url => { + try { + return new URL(url).hostname.split(".").slice(-2).join("."); + } catch (e) { + console.error(url, e); + return ""; + } + }; contentElem.addEventListener("click", onClickMarkUrlAsClicked); contentElem.addEventListener("contextmenu", onAltContextMenuUnmarkClickedUrl); @@ -111,14 +122,10 @@ export function getListHelper(container, settings) { for (const url of urls) { let linkHtml = urlToHtml(url); if (settings.sort) { - try { - if (mainHost(prev) !== mainHost(url)) { - resultHtml += ``; - } - prev = url; - } catch (e) { - console.error(url, e); + if (mainHost(prev) !== mainHost(url)) { + resultHtml += ``; } + prev = url; } const clicked = clickedUrls.has(url) ? " clicked" : ""; const html = ``;