// ==UserScript== // @name 【tapd】一键查询所有项目中的wiki // @namespace https://github.com/kiccer/tapd-search-wiki // @version 3.7.2 // @description 为了方便在tapd的wiki中查找接口而开发 // @author kiccer<1072907338@qq.com> // @copyright 2020, kiccer (https://github.com/kiccer) // @license MIT // @iconURL https://www.google.com/s2/favicons?domain=www.tapd.cn // @include /^https:\/\/www\.tapd\.cn\/\d+\/markdown_wikis\/(show\/|search\?.*)$/ // @require https://cdn.bootcdn.net/ajax/libs/vue/2.6.9/vue.js // @require https://cdn.bootcdn.net/ajax/libs/axios/0.21.0/axios.js // @require https://cdn.bootcdn.net/ajax/libs/tween.js/18.6.4/tween.umd.min.js // @require https://cdn.bootcdn.net/ajax/libs/Sortable/1.9.0/Sortable.min.js // @require https://cdn.bootcdn.net/ajax/libs/clipboard.js/2.0.6/clipboard.min.js // @noframes 这个千万别删掉!会出现死循环的! // @nocompat Chrome // @grant none // @downloadURL https://update.greasyfork.icu/scripts/418789/%E3%80%90tapd%E3%80%91%E4%B8%80%E9%94%AE%E6%9F%A5%E8%AF%A2%E6%89%80%E6%9C%89%E9%A1%B9%E7%9B%AE%E4%B8%AD%E7%9A%84wiki.user.js // @updateURL https://update.greasyfork.icu/scripts/418789/%E3%80%90tapd%E3%80%91%E4%B8%80%E9%94%AE%E6%9F%A5%E8%AF%A2%E6%89%80%E6%9C%89%E9%A1%B9%E7%9B%AE%E4%B8%AD%E7%9A%84wiki.meta.js // ==/UserScript== /* global Vue axios TWEEN takePartInWorkspaces $ Sortable ClipboardJS */ // https://www.tampermonkey.net/documentation.php // https://element.eleme.cn/#/zh-CN/component/button (() => { 'use strict' // 当前是否是 show 页面 const IN_SHOW_PAGE = /^https:\/\/www\.tapd\.cn\/\d+\/markdown_wikis\/show\/.*$/.test(location.href) // 当前是否是 search 页面 const IN_SEARCH_PAGE = /^https:\/\/www\.tapd\.cn\/\d+\/markdown_wikis\/search\?.*$/.test(location.href) // 当前项目id const CURR_PROJECT_ID = location.href.match(/(?<=https:\/\/www.tapd.cn\/)\d+(?=\/markdown_wikis\/)/g)[0] || '' // 随机字符串 const GM_ADD_STYLE_HASH = `GM_addStyle_${parseInt(Math.random() * Date.now())}` // 从 session 中获取缓存的搜索词 const SEARCH_WORD = sessionStorage.getItem('tapd-search-wiki/search_word') || '' // 页面 query 参数 const URL_QUERY = (() => { const queryStr = location.href.split('?')[1] if (queryStr) { const res = {} queryStr.split('&').forEach(n => { const [key, val] = n.split('=') res[key] = val }) return res } else { return {} } })() // GM_addStyle 方法 function GM_addStyle (css, dom = document.head, id = GM_ADD_STYLE_HASH) { const style = document.getElementById(id) || (() => { const style = document.createElement('style') style.type = 'text/css' style.id = id dom.appendChild(style) return style })() const sheet = style.sheet // sheet.insertRule(css, (sheet.rules || sheet.cssRules || []).length) css.split('\n\n').forEach(n => sheet.insertRule(n, (sheet.rules || sheet.cssRules || []).length)) } // 自写 Promise.all 方法 function PromiseAll (arr = []) { return new Promise((resolve, reject) => { const resVal = Array(arr.length).fill() arr.forEach((func, index) => { func().then(res => { resVal[index] = res if (resVal.every(n => n)) resolve(resVal) }).catch(err => { reject(err) }) }) }) } // 加载 element-ui script function elementScript () { return new Promise((resolve, reject) => { const vueListener = setInterval(() => { // 注册全局 Vue window.Vue || (window.Vue = Vue) if (window.Vue) { clearInterval(vueListener) const elScript = document.createElement('script') elScript.setAttribute('src', 'https://cdn.bootcdn.net/ajax/libs/element-ui/2.14.1/index.min.js') document.head.appendChild(elScript) elScript.addEventListener('load', resolve) elScript.addEventListener('error', reject) } }, 100) }) } // 加载 element-ui css function elementStyle () { return new Promise((resolve, reject) => { const elStyle = document.createElement('link') elStyle.setAttribute('href', 'https://cdn.bootcdn.net/ajax/libs/element-ui/2.14.1/theme-chalk/index.min.css') elStyle.setAttribute('rel', 'stylesheet') document.head.appendChild(elStyle) elStyle.addEventListener('load', resolve) elStyle.addEventListener('error', reject) }) } // 等待所有依赖项加载完毕后再执行 PromiseAll([ elementScript, elementStyle ]).then(() => { init() }).catch(err => { console.log(222, err) }) // vue 组件 (搜索框) Vue.component('search-input', { name: 'search-input', template: `