Created
December 20, 2021 18:59
-
-
Save zew13/049b51a66c5efcc2c6388a74e2c07895 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Generated by CoffeeScript 2.6.1 | |
| // ==UserScript== | |
| // @grant GM_getResourceText | |
| // @grant GM_addStyle | |
| // @grant GM_xmlhttpRequest | |
| // @name 外卖采集账户绑定 | |
| // @namespace https://wmdyy.coding.net/p/dyy/d/tampermonkey | |
| // @version 0.0.26 | |
| // @author xpure@foxmail.com | |
| // @updateURL https://wmdyy.coding.net/p/dyy/d/tampermonkey/git/raw/master/version | |
| // @downloadURL https://wmdyy.coding.net/p/dyy/d/tampermonkey/git/raw/master/lib/main.js | |
| // @require https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/localforage/1.9.0/localforage.min.js | |
| // @require https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/3.5.1/jquery.min.js | |
| // @require https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/js-cookie/2.2.1/js.cookie.min.js | |
| // @require https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/axios/0.21.1/axios.min.js | |
| // @include https://*.shop.ele.me/* | |
| // @include https://e.waimai.meituan.com/* | |
| // ==/UserScript== | |
| //cookie = new Map(i.split('=',2) for i from document.cookie.split(/; */)) | |
| var API, _css, escape, html_elem; | |
| API = "http://127.0.0.1:5999/"; | |
| // loginShopId "98787169" | |
| // loginShopName "小肥羊加盟店" | |
| // username "xfyjm9999" | |
| escape = (str) => { | |
| return str.replaceAll('&', "&").replaceAll('<', "<").replaceAll('>', ">"); | |
| }; | |
| _css = (css) => { | |
| var i, id, results, sheet, style; | |
| id = "cssDyy"; | |
| style = document.getElementById(id) || (() => { | |
| style = document.createElement('style'); | |
| style.type = 'text/css'; | |
| style.id = id; | |
| document.head.appendChild(style); | |
| return style; | |
| })(); | |
| sheet = style.sheet; | |
| if (!Array.isArray(css)) { | |
| css = [css]; | |
| } | |
| results = []; | |
| for (i of css) { | |
| results.push(sheet.insertRule(i, (sheet.rules || sheet.cssRules || []).length)); | |
| } | |
| return results; | |
| }; | |
| html_elem = (li) => { | |
| var template; | |
| template = document.createElement('template'); | |
| template.innerHTML = li.join('').trim(); | |
| return template.content.firstChild; | |
| }; | |
| $(async() => { | |
| var dyy, exist, host, interval, ksid, li, loginShopId, loginShopName, login_path, pathname, username; | |
| ({host, pathname} = location); | |
| if (host.includes(".ele.me")) { | |
| dyy = localforage.createInstance({ | |
| name: 'dyy' | |
| }); | |
| login_path = "/login"; | |
| if (pathname === login_path) { | |
| li = []; | |
| await dyy.iterate((val, key) => { | |
| var s; | |
| s = val[0]; | |
| li.push(`<a rel=${key}>${escape(s.loginShopName)}(${s.username})</a>`); | |
| }); | |
| if (li.length) { | |
| _css([".dyy a{display:block;border:1px solid #999;margin:0 0 1rem;padding: .5rem 1rem;background:#fff}", "body,html{overflow-y:auto;}"]); | |
| li.unshift('<div class="dyy">'); | |
| li.push('</div>'); | |
| $("#app>div").prepend(html_elem(li)); | |
| } | |
| $('.dyy a').click(async function() { | |
| var cookie, k, ref, store, v, x; | |
| [store, cookie] = (await dyy.getItem(this.rel)); | |
| localStorage.clear(); | |
| Object.assign(localStorage, store); | |
| ref = Object.entries(cookie); | |
| for (x of ref) { | |
| [k, v] = x; | |
| Cookies.set(k, JSON.stringify(v)); | |
| } | |
| return location.pathname = "/"; | |
| }); | |
| return; | |
| } | |
| ({ksid, loginShopId, loginShopName, username} = localStorage); | |
| if (!loginShopId) { | |
| return; | |
| } | |
| interval = setInterval(() => { | |
| var change, exit, user; | |
| user = $(".anticon-user"); | |
| if (!user[0]) { | |
| return; | |
| } | |
| user.click(); | |
| exit = $("li[role=menuitem]:contains('退出登录')"); | |
| if (exit[0]) { | |
| exit.hide(); | |
| change = $('<li class="ant-dropdown-menu-item ant-dropdown-menu-item-only-child" role="menuitem">切换账户</li>'); | |
| change.click(() => { | |
| localStorage.clear(); | |
| return location.pathname = login_path; | |
| }); | |
| exit.before(change); | |
| clearInterval(interval); | |
| } | |
| user.click(); | |
| }, 100); | |
| setInterval(() => { | |
| return clearInterval(interval); | |
| }, 6000); | |
| [exist] = (await dyy.getItem(loginShopId)) || [{}]; | |
| if (exist.ksid !== ksid) { | |
| await axios.post(API + 'ele', [loginShopId, ksid, loginShopName, username]); | |
| } | |
| await dyy.setItem(loginShopId, [{...localStorage}, Cookies.getJSON()]); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment