MCPcopy
hub / github.com/ZToolsCenter/ZTools / renderItems

Function renderItems

resources/preload.js:1501–1580  ·  view source on GitHub ↗
(items, pluginPath)

Source from the content-addressed store, hash-verified

1499 }
1500
1501 function renderItems(items, pluginPath) {
1502 listState.items = items || []
1503 listState.selectedIndex = 0
1504 var container = listState.container
1505 if (!container) return
1506 syncMouseHoverState()
1507 container.innerHTML = ''
1508 for (var i = 0; i < listState.items.length; i++) {
1509 var item = listState.items[i]
1510 var div = document.createElement('div')
1511 div.className = 'ztools-li' + (i === 0 ? ' selected' : '')
1512 div.dataset.index = i
1513
1514 var iconDiv = document.createElement('div')
1515 iconDiv.className = 'ztools-li-icon'
1516 if (item.icon) {
1517 var img = document.createElement('img')
1518 // 解析图标路径
1519 var iconSrc = item.icon
1520 if (
1521 iconSrc &&
1522 !iconSrc.startsWith('http') &&
1523 !iconSrc.startsWith('file:') &&
1524 !iconSrc.startsWith('data:') &&
1525 pluginPath
1526 ) {
1527 iconSrc = 'file://' + pluginPath.replace(/\\/g, '/') + '/' + iconSrc
1528 }
1529 img.src = iconSrc
1530 img.draggable = false
1531 img.onerror = function () {
1532 this.style.display = 'none'
1533 }
1534 iconDiv.appendChild(img)
1535 }
1536 div.appendChild(iconDiv)
1537
1538 var bodyDiv = document.createElement('div')
1539 bodyDiv.className = 'ztools-li-body'
1540 var titleDiv = document.createElement('div')
1541 titleDiv.className = 'ztools-li-title'
1542 titleDiv.textContent = item.title || ''
1543 bodyDiv.appendChild(titleDiv)
1544 if (item.description) {
1545 var descDiv = document.createElement('div')
1546 descDiv.className = 'ztools-li-desc'
1547 descDiv.textContent = item.description
1548 bodyDiv.appendChild(descDiv)
1549 }
1550 div.appendChild(bodyDiv)
1551 ;(function (idx) {
1552 div.addEventListener('mousemove', function () {
1553 if (listState.ignoreMouseHover) {
1554 listState.ignoreMouseHover = false
1555 syncMouseHoverState()
1556 }
1557 if (listState.selectedIndex === idx) return
1558 listState.selectedIndex = idx

Callers 2

doSelectFunction · 0.85
callbackSetListFunction · 0.85

Calls 4

syncMouseHoverStateFunction · 0.85
updateSelectionFunction · 0.85
doSelectFunction · 0.85
updateHeightFunction · 0.85

Tested by

no test coverage detected