美团外卖菜单转换

获取美团外卖菜单页并指定格式输出 目前仅支持美团PC页面 后续会完成全外卖公司的转换功能 / 如果使用有问题 请安装最新Chrome浏览器 / Designed for my best university bro.

目前為 2016-12-15 提交的版本,檢視 最新版本

// ==UserScript==
// @name       美团外卖菜单转换
// @namespace  http://meituan.com
// @version    0.0.1
// @description  获取美团外卖菜单页并指定格式输出 目前仅支持美团PC页面 后续会完成全外卖公司的转换功能 / 如果使用有问题 请安装最新Chrome浏览器 / Designed for my best university bro.
// @include    *://waimai.meituan.com/restaurant/*

// @copyright  2016
// ==/UserScript==


getMeituanMenu();

function getMeituanMenu() {
    const body = document.body;
    const btn = document.createElement('button');
    btn.style.cssText = "position:fixed;z-index:100;left:0;bottom:400px;";
    btn.innerHTML = "菜单信息/"
    body.appendChild(btn);

    const textarea = document.createElement('textarea');
    textarea.style.cssText = "position:fixed;z-index:100;left:0;bottom:0px;height:380px;";
    body.appendChild(textarea);

    btn.onclick = () => {
        let info = '';
        const category = document.querySelectorAll('.food-nav .category');
        for (let i = 0, categoryLength = category.length; i < categoryLength; i++) {
            const foodTypeName = category[i].querySelector('.title > span').textContent.trim();
            info += "\n#" + foodTypeName + "\n";

            const item = category[i].querySelectorAll('.pic-food');
            for (let j = 0, itemLength = item.length; j < itemLength; j++) {
                const foodName = item[j].querySelector('.np .name').getAttribute('title').trim();
                const foodPrice = item[j].querySelector('.labels .price .only').textContent.split('/')[0].substring(1).trim();
                info += foodName + ' ' + foodPrice + '\n';
                textarea.value = info;
            }
        }
    }
}