# hexo-safego

开源地址

pnpm install hexo-safego --save

# 无法抓取waline评论区链接

++ 增加内联pug

// hexo-safago Waline评论区链接处理 - 内联脚本
script.
  (function() {
    // 从配置中读取白名单
    var whitelist = !{JSON.stringify(config.hexo_safego.whitelist.domain_whitelist)};
    
    function isInWhitelist(url) {
      return whitelist.some(function(domain) {
        return url.indexOf(domain) !== -1;
      });
    }
    
    function convertLink(link) {
      var href = link.getAttribute('href');
      if (!href || href.startsWith('/') || href.startsWith('mailto:') || href.startsWith('tel:')) {
        return;
      }
      
      // 检查白名单
      if (isInWhitelist(href)) {
        return;
      }
      
      if (link.dataset.safagoProcessed) {
        return;
      }
      
      try {
        var encodedUrl = btoa(href);
        var newHref = '/go.html?u=' + encodedUrl;
        link.setAttribute('href', newHref);
        link.setAttribute('target', '_blank');
        link.dataset.safagoProcessed = 'true';
      } catch(e) {
        console.error('[safago-inline] Error:', e);
      }
    }
    
    function processWalineLinks() {
      var links = document.querySelectorAll('.wl-nick a[href], .wl-card a[href]');
      links.forEach(convertLink);
    }
    
    // 初始处理
    if (document.readyState === 'loading') {
      document.addEventListener('DOMContentLoaded', processWalineLinks);
    } else {
      processWalineLinks();
    }
    
    // 延迟处理(备用)
    setTimeout(processWalineLinks, 2000);
    
    // 事件委托:在链接被点击时进行转换(最重要)
    document.addEventListener('click', function(e) {
      var link = e.target.closest('a[href]');
      if (link && (link.classList.contains('wl-nick') || link.closest('.wl-card'))) {
        convertLink(link);
      }
    }, true);
    
    // PJAX支持
    document.addEventListener('pjax:complete', processWalineLinks);
  })();
Edited on

Give me a cup of [coffee]~( ̄▽ ̄)~*

Vullfin WeChat Pay

WeChat Pay

Vullfin Alipay

Alipay