wip: code refine & refine debug way

This commit is contained in:
daief
2020-11-30 23:21:24 +08:00
parent 0a441e5423
commit 80a7fbd86e
8 changed files with 123 additions and 36 deletions

36
README.md Normal file
View File

@@ -0,0 +1,36 @@
### 调试、自动刷新
起个本地服务托管 `dist`,如 `live-server --port=777`,之后在油猴脚本中写入以下代码,当源码更新后可自动刷新:
```js
// ==UserScript==
// ... 其他必要的配置
// @grant unsafeWindow
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_log
// @grant GM_xmlhttpRequest
// @connect 127.0.0.1
// ==/UserScript==
const code = GM_getValue('code');
if (code) {
eval(code);
}
const loop = () => {
GM_xmlhttpRequest({
url: 'http://127.0.0.1:7777/index.js',
onload: e => {
console.log('check');
const res = e.responseText;
if (e.status === 200 && code !== res) {
GM_setValue('code', res);
location.reload();
}
},
});
};
setInterval(loop, 3000);
```

View File

@@ -61,7 +61,7 @@ const config: Configuration = {
new GMPlugin({
scriptConfig: [
['name', 'Response Proxy'],
['namespace', 'http://tampermonkey.net/'],
['namespace', pkg.author.name],
['version', pkg.version],
['description', pkg.description],
['author', pkg.author.name],

57
src/Setting/Panel.vue Normal file
View File

@@ -0,0 +1,57 @@
<template>
<div v-show="show" class="root" @click.self="show = false">
<div class="container">{{ state.matchedSetList.length }}1</div>
</div>
</template>
<script lang="ts">
import { ISet } from '@/data';
import { defineComponent, reactive } from 'vue';
export default defineComponent({
data() {
return {
show: false,
};
},
setup() {
const state = reactive<{
matchedSetList: ISet[];
}>({
matchedSetList: [],
});
return {
state,
};
},
});
</script>
<style scoped lang="less">
.root {
overflow: hidden auto;
right: 0;
bottom: 0;
top: 0;
left: 0;
outline: none;
position: fixed;
z-index: 1000;
background-color: rgba(0, 0, 0, 0.2);
}
.container {
position: absolute;
left: 50%;
box-sizing: border-box;
pointer-events: auto;
top: 40%;
transform: translate(-50%, -40%);
background: #fff;
border-radius: 4px;
box-shadow: 0 0 24px 0 rgba(102, 102, 102, 0.08);
min-height: 360px;
max-width: 100%;
width: 720px;
}
</style>

View File

@@ -1,8 +1,8 @@
import { createApp } from 'vue';
import App from './Panel.vue';
import Panel from './Panel.vue';
export function render(el: any) {
const vm = createApp(App);
const vm = createApp(Panel);
const $root = vm.mount(el);
return {

View File

@@ -1,22 +0,0 @@
<template>
<div v-if="show" @click="show = false">dsds {{ val }}</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
data() {
return {
val: 1,
show: false,
};
},
});
</script>
<style scoped lang="less">
div {
color: red;
}
</style>

View File

@@ -21,6 +21,11 @@ export const Store = {
res = Array.isArray(res) ? res : [];
return res;
},
getMatchedSetList(): ISet[] {
return Store.getSetList().filter(it =>
new RegExp(it.domainTest, 'ig').test(location.host)
);
},
findCurrentSet(): ISet {
const ruleSet = Store.getSetList().find(it =>
new RegExp(it.domainTest, 'ig').test(location.host)

View File

@@ -10,6 +10,9 @@
opacity: 0.5;
transition: opacity 0.3s;
box-shadow: 0 0 10px 0px rgb(0 0 0 / 35%);
display: flex;
align-items: center;
justify-content: center;
&:hover {
opacity: 1;

View File

@@ -4,19 +4,19 @@ import './global.less';
import { vmCtx } from './common';
// TODO change to async
import { render } from './SettingPanel';
// import(/* webpackChunkName: 'setting-panel' */ './SettingPanel');
import { render } from './Setting';
// import(/* webpackChunkName: 'setting' */ './Setting');
let handler: any;
let isDrag = false;
let isMove = false;
let tX = 0;
let tY = 0;
let elRect: DOMRect | null = null;
function bootstrap() {
let handler: any;
let isDrag = false;
let isMove = false;
let tX = 0;
let tY = 0;
let elRect: DOMRect | null = null;
vmCtx.addEventListener('DOMContentLoaded', () => {
const el = document.createElement('div');
el.innerText = '设置';
el.innerText = 'o_O||';
el.className = 'response-proxy-page-root-fixed-button';
function onClickEl(_e: MouseEvent) {
@@ -77,4 +77,12 @@ vmCtx.addEventListener('DOMContentLoaded', () => {
document.body.appendChild(el);
document.body.appendChild(elForMount);
});
}
if (document.readyState === 'loading') {
vmCtx.addEventListener('DOMContentLoaded', () => {
bootstrap();
});
} else {
bootstrap();
}