-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsketch_meaxure_toolkit.js
More file actions
131 lines (130 loc) · 4.05 KB
/
sketch_meaxure_toolkit.js
File metadata and controls
131 lines (130 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// ==UserScript==
// @name Sketch MeaXure Cleaner
// @namespace SublimeCT
// @version 0.1
// @description 屏蔽 MeaXure 脑残的快捷键设置;
// @author SublimeCT
// @include https://*
// @include http://*
// @include file://*
// @icon http://www.sketchcn.com/images/sketch%E4%B8%AD%E6%96%87%E7%BD%91-favicon.ico
// @grant none
// ==/UserScript==
; (() => {
class ToolkitModule {
constructor() { }
isActive = true
get isMeaxurePage() {
return window.meaxure
}
}
class Store {
static getOptions() {
const options = localStorage.getItem('SketchMeaXureToolkit_options')
if (!options) return {}
try {
return JSON.parse(options) || {}
} catch (err) {
console.log(err)
return {}
}
}
static setOption(options) {
localStorage.setItem('SketchMeaXureToolkit_options', JSON.stringify(options))
}
static updateOptions(options) {
const allOptions = Store.getOptions()
Object.assign(allOptions, options)
Store.setOption(allOptions)
}
}
/**
* 加入自定义样式
*/
class HotKeyModule extends ToolkitModule {
static get FLOW_BUTTON() {
return document.querySelector('.flow-mode')
}
async init() {
if (!this.isMeaxurePage) return
await this.disabledHotKey()
}
async disabledHotKey() {
const MAX_TIMES = 50
for (let time = MAX_TIMES; time--;) {
if (HotKeyModule.FLOW_BUTTON) break
await Toolkit.delay()
}
if (!HotKeyModule.FLOW_BUTTON) throw new Error('[HotKeyModel] Flow button not found')
HotKeyModule.FLOW_BUTTON.innerHTML = ' 💀 kill:flow '
}
}
/**
* 加入自定义样式
*/
class SheetsToolkitModule extends ToolkitModule {
static isActive = false
static _getSheets() {
return `
/* 自定义样式 */
`
}
init(ctx) {
ctx.log('加入自定义样式')
// SheetsToolkitModule.appendSheets()
}
// 通过注入 css 实现隐藏广告并固定布局
static appendSheets() {
const sheet = document.createTextNode(SheetsToolkitModule._getSheets())
const el = document.createElement('style')
el.id = 'handle-sheets'
el.appendChild(sheet)
document.getElementsByTagName('head')[0].appendChild(el)
}
onload(ctx) {
ctx.log('加入自定义样式')
SheetsToolkitModule.appendSheets()
}
}
/**
* 工具类
*/
class Toolkit {
debug = true
options = {}
users = {}
constructor(options = {}) {
Object.assign(this.options, options)
this.emitHook('init')
}
/**
* 工具集
*/
static modules = []
/**
* 注册工具模块
*/
static use(moduleItem) {
// 禁用未激活的模块
if (!moduleItem.isActive) return
Array.isArray(moduleItem) ? moduleItem.map(item => Toolkit.use(item)) : Toolkit.modules.push(moduleItem)
}
/**
* 触发钩子函数
* @param {string}} hook 钩子函数名
*/
emitHook(hook) {
this.log('触发钩子函数: ' + hook, Toolkit.modules.length)
Toolkit.modules.map(module => module[hook] && typeof module[hook] === 'function' && module[hook](this))
}
log(...args) {
console.log('%c[GraphQL Toolkit] LOG: ', 'color:teal', ...args)
}
static delay(timeout = 200) {
return new Promise(resolve => setTimeout(resolve, timeout))
}
}
Toolkit.use(new SheetsToolkitModule())
Toolkit.use(new HotKeyModule())
window._$SketchMeaXureToolkit = new Toolkit()
})();