// ==UserScript== // @name wsmud_login1 // @namespace com.wsmud // @version 0.0.11 // @description 武神传说登录插件 // @author sq // @date 2020/08/26 // @modified 2020/11/07 // @license MIT // @match http://*.wsmud.com/* // @match http://*.wamud.com/* // @match http://mush.fun/* // @require https://cdn.staticfile.org/vue/2.6.11/vue.min.js // @exclude http://*.wsmud.com/news/* // @exclude http://*.wsmud.com/pay.html // @homepage https://greasyfork.org/zh-CN/scripts/443214 // @grant unsafeWindow // @grant GM_addStyle // @grant GM_getValue // @grant GM_setValue // @grant GM_listValues // @grant GM_setClipboard // @downloadURL https://update.greasyfork.icu/scripts/443214/wsmud_login1.user.js // @updateURL https://update.greasyfork.icu/scripts/443214/wsmud_login1.meta.js // ==/UserScript== (function () { 'use strict' class Myapi { constructor() { this.roles = this.getValue('roles') } set roles(value) { if (value instanceof Array) { value.sort((a, b) => a.sort - b.sort) value.forEach((item, index) => { if (item.server) item.sort = index + 1 else item.sort = 9999 }) this._roles = value } else { this._roles = [] } this.setValue('roles', this._roles) } get roles() { return this._roles } addStyle(css) { GM_addStyle(css) } cookie() { const cookies = document.cookie.split(';').reduce((accumulator, currentValue) => { const i = currentValue.indexOf('=') const name = currentValue.substr(0, i).trim() const value = currentValue.substr(i + 1) accumulator[name] = value return accumulator }, {}) const setCookie = (name, value) => document.cookie = name + '=' + value const deleteCookie = name => document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;' return new Proxy(cookies, { set: (target, name, value) => { setCookie(name, value) return Reflect.set(target, name, value) }, deleteProperty: (target, name) => { deleteCookie(name) return Reflect.deleteProperty(target, name) }, }) } setValue(key, value) { localStorage.setItem(key, JSON.stringify(value)) } getValue(key) { return JSON.parse(localStorage.getItem(key)) } deleteValue(key) { localStorage.removeItem(key) } } $(document).ready(function () { var WG = unsafeWindow.WG; var myapi = Vue.observable(new Myapi()) WG.add_hook('roles', function (data) { if (!(data.roles instanceof Array)) return data.roles.forEach(item => { const { id, name, title } = item const index = myapi.roles.findIndex(role => role.id === id) if (index === -1) { myapi.roles.push({ id, name, title, sort: 9999 }) } else { myapi.roles[index].name = name myapi.roles[index].title = title } }) myapi.roles = myapi.roles.slice(0) }) WG.add_hook('login', function (data) { const id = data.id if (myapi.id || !id) return myapi.id = id const index = myapi.roles.findIndex(role => role.id === id) myapi.name = myapi.roles[index].name const cookie = myapi.cookie() myapi.roles[index].u = cookie.u myapi.roles[index].p = cookie.p myapi.roles[index].s = cookie.s myapi.roles[index].server = ['一区', '二区', '三区', '四区', '测试'][cookie.s] myapi.roles = myapi.roles.slice(0) }) const autoLoginId = myapi.getValue('auto-login-id') if (autoLoginId) { myapi.deleteValue('auto-login-id') WG.add_hook(['roles'], function () { setTimeout(() => $(`.role-item[roleid=${autoLoginId}]`).click(), 1000) setTimeout(() => $('.panel_item[command=SelectRole]').click(), 2000) }) return } $('li.panel_item[command="SelectRole"]').after(`