SOURCE

function _beforeNotify(id, data) {
    const old_data = JSON.parse(data.preData.text);
    const new_data = JSON.parse(data.curData.text);

    const oldLiveIds = new Set();
    const oldAllMap = new Map();
    // 解析历史数据,记录所有主播ID+名称,以及正在开播的ID
    old_data.data.forEach(item => {
        oldAllMap.set(item.id, item.name);
        if (item.status === 1) {
            oldLiveIds.add(item.id);
        }
    });

    const newLiveIds = new Set();
    const newAllMap = new Map();
    // 解析最新数据
    new_data.data.forEach(item => {
        newAllMap.set(item.id, item.name);
        if (item.status === 1) {
            newLiveIds.add(item.id);
        }
    });

    // 新开播:旧状态未开播,新状态开播
    const newLiveList = new_data.data.filter(item => {
        return item.status === 1 && !oldLiveIds.has(item.id);
    });

    // 已关播:旧状态开播,新状态未开播
    const closeLiveList = old_data.data.filter(item => {
        return item.status === 1 && !newLiveIds.has(item.id);
    });

    // 无任何变动则忽略通知
    if (newLiveList.length === 0 && closeLiveList.length === 0) {
        data.ignored = true;
    } else {
        let titleArr = [];
        if (newLiveList.length > 0) {
            const newNames = newLiveList.map(v => v.name);
            titleArr.push(`�� 新开播:${newNames.join('、')}`);
            // 优先取新开播第一个链接
            data.config.url = newLiveList[0].url;
        }
        if (closeLiveList.length > 0) {
            const closeNames = closeLiveList.map(v => v.name);
            titleArr.push(`�� 已关播:${closeNames.join('、')}`);
            // 若无新开播,取关播第一个链接
            if (!newLiveList.length) {
                data.config.url = closeLiveList[0].url;
            }
        }
        data.config.title = titleArr.join('\n');
    }

    _callback(id, data);
}
console 命令行工具 X clear

                    
>
console