Skip to content

Commit

Permalink
Update mainHost
Browse files Browse the repository at this point in the history
  • Loading branch information
AlttiRi committed Jun 21, 2024
1 parent cc75007 commit 7ba934e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
25 changes: 16 additions & 9 deletions dist/href-taker.user.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 += `<span class="url-pad"></span>`;
}
prev = url;
} catch (e) {
console.error(url, e);
if (mainHost(prev) !== mainHost(url)) {
resultHtml += `<span class="url-pad"></span>`;
}
prev = url;
}
const clicked = clickedUrls.has(url) ? " clicked" : "";
const html = `<div class="url-item${clicked}"><a href="${url}" ${anchorAttr}>${linkHtml}</a></div>`;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
23 changes: 15 additions & 8 deletions src/components/list-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 += `<span class="url-pad"></span>`;
}
prev = url;
} catch (e) {
console.error(url, e);
if (mainHost(prev) !== mainHost(url)) {
resultHtml += `<span class="url-pad"></span>`;
}
prev = url;
}
const clicked = clickedUrls.has(url) ? " clicked" : "";
const html = `<div class="url-item${clicked}"><a href="${url}" ${anchorAttr}>${linkHtml}</a></div>`;
Expand Down

0 comments on commit 7ba934e

Please sign in to comment.