Skip to content

Commit 42b9adb

Browse files
committed
实现菜单debug & 修复脚本缓存问题
1 parent ce7ebbe commit 42b9adb

File tree

5 files changed

+23
-19
lines changed

5 files changed

+23
-19
lines changed

docs/changelog.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
## v0.3.4
22

3-
* 新建脚本默认开启
3+
* 新建脚本默认开启(从远程安装的后端脚本依旧默认为不开启)
44
* 管理面板简单的分页功能
55
* 增加开机启动自动运行
66
* 支持`@require-css`直接引入css文件
77
* 支持`document-menu`执行方式
8-
* 修复若干bug
98
* 支持`@include``@exclude`
9+
* 移除`@debug`,新增菜单条
10+
* 修复若干bug
1011

1112
## v0.3.0
1213
> 开始支持油猴脚本了

src/apps/script/manager.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,11 @@ export class ScriptManager {
376376

377377
public loadScriptByUrl(url: string): Promise<ScriptUrlInfo | undefined> {
378378
return new Promise(resolve => {
379-
axios.get(url).then((response): ScriptUrlInfo | undefined => {
379+
axios.get(url, {
380+
headers: {
381+
'Cache-Control': 'no-cache'
382+
}
383+
}).then((response): ScriptUrlInfo | undefined => {
380384
if (response.status != 200) {
381385
return undefined;
382386
}

src/types/main.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ interface IUpdateMeta {
2828
interface ISave {
2929
scriptId: number;
3030
currentCode: string;
31+
debug: boolean;
3132
}
3233

3334
interface IInitialScript {

src/views/pages/Option/tabs/ScriptTab/Editor.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,11 @@ export default class CloseButton extends Vue {
125125
{
126126
action: "调试",
127127
handler: () => {
128-
console.log("菜单action");
128+
eventBus.$emit<ISave>(EventType.Save, {
129+
scriptId: this.scriptId,
130+
currentCode: this.editor.getValue(),
131+
debug: true,
132+
});
129133
},
130134
tooltip: "调试后台脚本",
131135
},
@@ -154,6 +158,7 @@ export default class CloseButton extends Vue {
154158
eventBus.$emit<ISave>(EventType.Save, {
155159
scriptId: this.scriptId,
156160
currentCode: this.editor.getValue(),
161+
debug: false,
157162
});
158163
});
159164
@@ -177,4 +182,4 @@ export default class CloseButton extends Vue {
177182
color: rgb(128, 128, 128);
178183
cursor: not-allowed;
179184
}
180-
</style>
185+
</style>

src/views/pages/Option/tabs/ScriptTab/index.vue

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export default class ScriptTab extends Vue {
125125
this.handleInitialSctipt(payload);
126126
}
127127
});
128-
eventBus.$on<ISave>("save", (payload) => {
128+
eventBus.$on<ISave>(EventType.Save, (payload) => {
129129
if (payload.scriptId === this.scriptId) {
130130
this.handleSave(payload);
131131
}
@@ -163,7 +163,7 @@ export default class ScriptTab extends Vue {
163163
this.script = script;
164164
this.metaBuffer = this.prepareMetaBuffer(this.script.metadata);
165165
166-
eventBus.$emit<IChangeTitle>("change-title", {
166+
eventBus.$emit<IChangeTitle>(EventType.ChangeTitle, {
167167
title: script.name,
168168
scriptId: this.scriptId ?? this.localScriptId,
169169
});
@@ -187,7 +187,7 @@ export default class ScriptTab extends Vue {
187187
this.onMetaChange = false;
188188
}
189189
190-
async handleSave({ currentCode }: ISave) {
190+
async handleSave({ currentCode, debug }: ISave) {
191191
// todo 保存时候错误处理
192192
let [newScript, oldScript] = await this.scriptMgr.prepareScriptByCode(
193193
currentCode,
@@ -225,21 +225,14 @@ export default class ScriptTab extends Vue {
225225
await this.handleInitialSctipt({} as any);
226226
227227
// 还原unsavdChange状态的title
228-
eventBus.$emit<IChangeTitle>("change-title", {
228+
eventBus.$emit<IChangeTitle>(EventType.ChangeTitle, {
229229
title: `${this.script.name}`,
230230
scriptId: this.scriptId ?? this.localScriptId,
231231
});
232232
233-
if (oldScript) {
234-
// 后台脚本才可以调用
235-
if (this.script.metadata["debug"] != undefined) {
236-
this.scriptMgr.execScript(this.script, true);
237-
}
238-
} else {
239-
// eventBus.$emit<INewScript>("new-script", {
240-
// scriptId: this.scriptId ?? this.localScriptId,
241-
// });
242-
// this.$router.push({ path: "/" });
233+
// 后台脚本才可以调用
234+
if (debug) {
235+
this.scriptMgr.execScript(this.script, true);
243236
}
244237
245238
this.$refs.editor.hasUnsavedChange = false;

0 commit comments

Comments
 (0)