| 3197 | |
| 3198 | // 创建或获取弹窗 |
| 3199 | function getModal() { |
| 3200 | if (!linkModal) { |
| 3201 | linkModal = document.createElement('div'); |
| 3202 | linkModal.className = 'nsn-link-modal'; |
| 3203 | linkModal.innerHTML = ` |
| 3204 | <div class="nsn-link-modal-content"> |
| 3205 | <div class="nsn-link-modal-header">链接操作</div> |
| 3206 | <div class="nsn-link-modal-url"></div> |
| 3207 | <div class="nsn-link-modal-buttons"> |
| 3208 | <button class="nsn-link-modal-btn primary" data-action="open">跳转</button> |
| 3209 | <button class="nsn-link-modal-btn secondary" data-action="edit">编辑</button> |
| 3210 | <button class="nsn-link-modal-btn danger" data-action="close">取消</button> |
| 3211 | </div> |
| 3212 | </div> |
| 3213 | `; |
| 3214 | document.body.appendChild(linkModal); |
| 3215 | |
| 3216 | // 绑定弹窗事件 |
| 3217 | linkModal.addEventListener('click', (e) => { |
| 3218 | const action = e.target.getAttribute('data-action'); |
| 3219 | if (action) { |
| 3220 | e.preventDefault(); |
| 3221 | e.stopPropagation(); |
| 3222 | |
| 3223 | const currentLink = linkModal._currentLink; |
| 3224 | if (!currentLink) return; |
| 3225 | |
| 3226 | hideModal(); |
| 3227 | |
| 3228 | if (action === 'open') { |
| 3229 | // 跳转链接 |
| 3230 | const url = currentLink.getAttribute('data-href'); |
| 3231 | if (url) { |
| 3232 | window.open(url, '_blank'); |
| 3233 | } |
| 3234 | } else if (action === 'edit') { |
| 3235 | // 编辑链接 |
| 3236 | const currentText = currentLink.textContent; |
| 3237 | const currentUrl = currentLink.getAttribute('data-href'); |
| 3238 | |
| 3239 | setTimeout(() => { |
| 3240 | const newText = prompt('编辑链接文本:', currentText); |
| 3241 | if (newText !== null && newText.trim()) { |
| 3242 | setTimeout(() => { |
| 3243 | const newUrl = prompt('编辑链接地址:', currentUrl); |
| 3244 | if (newUrl !== null && newUrl.trim()) { |
| 3245 | currentLink.textContent = newText.trim(); |
| 3246 | currentLink.setAttribute('data-href', newUrl.trim()); |
| 3247 | } |
| 3248 | }, 50); |
| 3249 | } |
| 3250 | }, 50); |
| 3251 | } |
| 3252 | } |
| 3253 | }); |
| 3254 | |
| 3255 | // 注释掉点击背景关闭弹窗的功能 |
| 3256 | // linkModal.addEventListener('click', (e) => { |