hexo-theme-stellar/source/js/services/sites.js

30 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-02-12 23:07:56 +08:00
utils.jq(() => {
$(function () {
2024-02-18 12:33:28 +08:00
const els = document.getElementsByClassName('ds-sites');
2024-02-12 23:07:56 +08:00
for (var i = 0; i < els.length; i++) {
const el = els[i];
const api = el.getAttribute('api');
if (api == null) {
continue;
}
const default_avatar = def.avatar;
const default_cover = def.cover;
// layout
utils.request(el, api, function(data) {
for (let item of data.content) {
var cell = `<div class="grid-cell site-card">`;
cell += `<a class="card-link" target="_blank" rel="external nofollow noopener noreferrer" href="${item.url}">`;
cell += `<img src="${item.cover || item.screenshot}" onerror="javascript:this.removeAttribute(\'data-src\');this.src=\'${default_cover}\';"/>`;
cell += `<div class="info">`;
cell += `<img src="${item.icon || item.avatar || default_avatar}" onerror="javascript:this.removeAttribute(\'data-src\');this.src=\'${default_avatar}\';"/>`;
cell += `<span class="title">${item.title}</span>`;
cell += `<span class="desc">${item.description || item.url}</span>`;
cell += `</div>`;
cell += `</a>`;
cell += `</div>`;
$(el).find('.grid-box').append(cell);
}
});
}
});
});