Skip to content

Commit

Permalink
feat: allow desc of websites
Browse files Browse the repository at this point in the history
  • Loading branch information
teaSummer committed Aug 8, 2024
1 parent 5fcc1c7 commit 86eb43b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions assets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ details {
transition: all 1s;
}

details>*:not(summary) {
details a.button {
opacity: 0%;
pointer-events: none;
}
Expand All @@ -351,7 +351,7 @@ details[open] {
max-height: 1000px;
}

details[open]>*:not(summary) {
details[open] a.button {
opacity: 100%;
pointer-events: auto;
}
Expand Down
20 changes: 13 additions & 7 deletions scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,29 +398,35 @@ $('.searchable-input').typeahead(
);


// 网站板块生成
// 生成网站details板块
const pre_list = ((e) => {
const lineBlocks = [];
let blocks = JSON.parse($(e).html());
let dom = '';
const importantPattern = /((半价|免费|公益|折扣|限时|特惠|热门|新品|热销|推荐|礼品|[一二两三四五六七八九]折|打折|促销|超值|全新|便宜|披风)|\b(free|off|new|hot|recommend|top|discount|limit|cheap|present|gift|cape)\b)/gi;
const importantPattern = /((半价|免费|公益|折扣|限时|特惠|热门|新品|热销|促销|推荐|礼品|[一二两三四五六七八九]折|打折|超值|全新|便宜|披风)|\b(free|off|new|hot|recommend|top|discount|limit|cheap|present|gift|cape)\b)/gi;
for (const block of blocks) {
// 获取分类并处理
const category = Object.keys(block)[0];
if (category.endsWith('[open]')) {
dom += `<details class="keep" id="${category.replace('[open]', '').replace(/ .+/, '')}" open><summary>${category.replace('[open]', '')}</summary>`;
}
else dom += `<details id="${category.replace(/ .+/, '')}"><summary>${category}</summary>`;
let content;
// 生成元素
for (const [title, url] of block[category]) {
// 判断是否不为外部链接
for (const [title, url, description] of block[category]) {
let template = '|DOM|';
if (description) template = `<mdui-tooltip content="${description}">|DOM|</mdui-tooltip>`;
// 判断是否为内部链接
if (url.startsWith('#')) {
dom += `<a class="button noicon" href="${url}" onclick="hashChanged();">${title}</a>`;
// 内部链接
content = `<a class="button noicon" href="${url}" onclick="hashChanged();">${title}</a>`;
} else {
// 外部链接
if (importantPattern.test(title)) {
dom += `<a class="button important" href="${url}" target="_blank">${title.replace(importantPattern, '<text class="bold">$1</text>')}</a>`;
} else dom += `<a class="button" href="${url}" target="_blank">${title}</a>`;
content = `<a class="button important" href="${url}" target="_blank">${title.replace(importantPattern, '<text class="bold">$1</text>')}</a>`;
} else content = `<a class="button" href="${url}" target="_blank">${title}</a>`;
};
dom += template.replace('|DOM|', content);
};
dom += '</details><hr>';
};
Expand Down

0 comments on commit 86eb43b

Please sign in to comment.