本WIKI于2021年03月04日通过了时雨音的接管申请,编辑权限开放。

欢迎收藏本WIKI防止迷路,也希望有爱的小伙伴和我们一起编辑哟~

建议使用PC版页面访问本WIKI以获得更佳体验!

编辑帮助WIKI建议加入我们使用哔哩哔哩APP打开WIKI

全站通知:

用户:646195980/Cafe.js

来自坎特伯雷公主与骑士唤醒冠军之剑的奇幻冒险WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
  • Opera:Ctrl-F5
/**
 * Cafe.js | Inspiration comes from https://wiki.biligame.com/gt/?curid=9966
 * Author: 飞小RAN (https://wiki.biligame.com/gt/User:646195980)
 * License: See https://wiki.biligame.com/gt/User:646195980#License
 * 懒得搬咖啡馆。
 **/
(async function() {
    'use strict';
    try {
        // 1. 获取内容
        const cafe = document.querySelector('.daumcafe');
        const response = await fetch(`https://eo.hitfun.top/bbs_read?grpid=1YmAL&fldid=${cafe.dataset.fldid}&datanum=${cafe.dataset.num}`);
        if (!response.ok) throw new Error(`[CafeDaum] ${response.status}`);
        const html = await response.text();
        // 2. 解析 HTML
        const parser = new DOMParser();
        const doc = await parser.parseFromString(html, 'text/html');
        const xmp = doc.querySelector('#template_xmp');
        let content = await parser.parseFromString(xmp.innerHTML, 'text/html');
        // 3. 处理图片
        let imgs = content.querySelectorAll('img');
        imgs.forEach(img => {
            img.removeAttribute('width');
            img.removeAttribute('height');
            if (img.src.startsWith('https://t1.daumcdn.net')) {
                img.src = img.src.replace('https://t1.daumcdn.net', 'https://eo.hitfun.top');
            }
        });
        // 4. 替换内容
        cafe.innerHTML = content.querySelector('body').innerHTML;
        console.log('[CafeDaum] 成功加载!');
    } catch (error) {
        console.error('[CafeDaum] 处理失败:', error);
    }
})();