Greasy Fork

Greasy Fork is available in English.

摹客增强插件

增强项目导航菜单,设置默认手型工具

当前为 2021-07-14 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         摹客增强插件
// @namespace    http://greasyfork.icu/zh-CN/scripts/429346
// @version      0.1.2
// @description  增强项目导航菜单,设置默认手型工具
// @author       Wilson
// @match        https://app.mockplus.cn/app/*/*
// @icon         https://app.mockplus.cn/favicon.ico
// @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function() {
    'use strict';

    //http请求
    function httpRequest(url, fn, method, data, header) {
        method = method || "get";
        data = data || "";
        header = header || {};
        GM_xmlhttpRequest({
            method: method,
            url: url,
            data: data,
            headers: header,
            onload: function(res){
                if(res.status === 200){
                    //console.log('sucess',method,url);
                    if(fn) fn(res);
                }else{
                    console.log('error',method,url);
                    console.log(res);
                    if(fn) fn(null);
                }
            },
            onerror : function(err){
                console.log('error',method,url);
                console.log(err);
                if(fn) fn(null);
            }
        });
    }

    let catUrl = "https://app.mockplus.cn/api/v1/app/allAppAndAppSet/pxnttpbsbb?needArchivedApp=true&source=all&needAppSet=true&rnd="+Math.random();
    httpRequest(catUrl, function(res){
        if(res && res.response){
            //get menu list
            let data = JSON.parse(res.response);
            // console.log(11111,catUrl,data);
            if(data.code != 0){
                console.log('error', data.message,catUrl,data);
                return;
            }
           data = data.payload.apps;
           //menu
            setTimeout(function(){
                //设置默认手型工具
                document.querySelector(".icon-_artboard_movehand").click();

                //获取项目菜单
                let list = "";
                for(let i in data){
                    let item = data[i];
                    let href = location.href.replace(/\/app\/.+\//i, '/app/'+item._id+'/');
                    let id = location.href.replace(/(.+\/app\/)(.+)(\/.+)/i, '$2');
                    if(id == item._id) continue;
                    let a = '<li class=""><a class="menu-item" href="'+href+'" >'+item.name+'</a></li>';
                    list += a;
                }
                let menu = `
  <div class="menu-mode-popup" style="display:none;">
   <ul class="dsm-c-drop" style="width: 225px;">
   `+list+`
   </ul>
  </div>
    `;
                //arrow
                let arrow = `
                <div class="down-arrow"><i class="dsm-c-icon idoc_iconfont icon-_tag_downarrow" style="font-size: 16px; width: 16px; height: 16px; visibility: visible;"></i></div>
                `;
                //show/hide
                let menuwrap = null;
                function oMenuWrap(){
                    menuwrap = menuwrap || $(".app-header .logo .dsm-c-tooltip .menu-mode-popup");
                    return menuwrap;
                }
                let lia = null;
                function oLiA(){
                    lia = lia || $(".app-header .logo .dsm-c-tooltip .menu-mode-popup li a.menu-item");
                    return lia;
                }
                $(".app-header .logo .dsm-c-tooltip").append(arrow).append(menu).click(function(e){
                    let act = location.href.replace(/(.+\/app\/)(.+)(\/)(.+)$/i, '$4');
                    oLiA().each(function(){
                        let me = $(this);
                        let href = me.attr("href");
                        href = href.replace(/(.+\/app\/.+\/)(.+)$/i, '$1'+act);
                        me.attr("href", href);
                    });
                    oMenuWrap().show();
                    e.stopPropagation();
                }).on('mouseleave', function(){
                    oMenuWrap().hide();
                });
                $("body").click(function(){
                    oMenuWrap().hide();
                });
            }, 800);
        }
    });
})();