// ==UserScript== // @name 蓝湖优化 // @namespace Pudon // @match *://*.lanhuapp.com/* // @require https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/1.12.4/jquery.min.js // @version 0.0.1 // @grant none // @license MIT // @description 去除蓝湖顶部绑定手机提示bar,增加产品原型文档搜索 // @downloadURL none // ==/UserScript== (function() { document.addEventListener('DOMNodeInserted', (e) => { var _el = e.target // 清除顶部绑定手机bar if (_el.className === 'onboarding' || _el.className === 'onboarding-top') { _el.remove() } }, false) if (!document.querySelector('.whole')) { return } var vue = document.querySelector('.whole').__vue__ vue.$watch('$route', async function (to, from) { if (to.name === 'product' && from.name !== 'product' && !document.querySelector('#fileSearch')) { // 等change-menu渲染出来 while(!document.querySelector('.change-menu')) { await sleep(100) } addFn() } }) var addFn = function() { var _btn = '
' $('.change-menu').after(_btn) $('.file-list').children().attr('id', 'fileList') var _rpList = $('.file-list').children().children() function trigger(t, e) { var n = document.createEvent('HTMLEvents') n.initEvent(e, !0, !0) t.dispatchEvent(n) } $('body').on('compositionstart','#fileSearchInput', function(e) { e.target.composing = true }) $('body').on('compositionend','#fileSearchInput', function(e) { e.target.composing && (e.target.composing = false, trigger(e.target, 'input')) }) // 监听输入 $('body').on('input','#fileSearchInput', function(e) { if (e.target.composing) { return } // 控制清除按钮显示 $(this).val() ? $('#fileSearchClear').show() : $('#fileSearchClear').hide() var _val = $(this).val() var _resList = _rpList.filter(function() { return $(this).find('span').text().indexOf(_val) > -1 }) $('#fileList').html(_resList) }) // 监听清除按钮 $('body').on('click','#fileSearchClear', function(e) { $('#fileSearchInput').val('') $('#fileSearchClear').hide() $('#fileList').html(_rpList) }) } // 延迟函数 const sleep = ms => new Promise(r => setTimeout(r, ms)) })();