Skip to content

Commit 1ffd5bf

Browse files
authored
Merge pull request #18 from JSREI/dev
feat: 增加配置页面
2 parents ce43a73 + b2694de commit 1ffd5bf

25 files changed

+1931
-536
lines changed

fuck-hot-update.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
# 热编译好像有点问题,这是一个折中的方案
4+
while true; do
5+
# 执行 yarn build 命令
6+
yarn build
7+
# 等待1秒
8+
sleep 1
9+
done

package-lock.json

Lines changed: 525 additions & 361 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@
88
"document": "https://github.com/JSREI/js-script-hook.git",
99
"scripts": {
1010
"build": "NODE_ENV=production webpack --config webpack.prod.js",
11-
"watch": "webpack --watch --config webpack.dev.js",
12-
"test": "mocha --recursive"
11+
"watch": "webpack --watch --config webpack.dev.js"
1312
},
1413
"author": "CC11001100 <[email protected]>",
1514
"license": "MIT",
1615
"devDependencies": {
17-
"webpack": "^5.88.2",
16+
"current-script-polyfill": "^1.0.0",
17+
"webpack": "5.94.0",
1818
"webpack-cli": "^5.1.4",
19-
"webpack-merge": "^5.9.0",
20-
"idb": "^8.0.0",
21-
"current-script-polyfill": "^1.0.0"
19+
"webpack-merge": "^5.9.0"
2220
}
2321
}

src/analyzer/request-analyzer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class RequestAnalyzer {
5353
}
5454
let jsonpScore = 100;
5555

56+
// TODO 2024-12-22 01:32:28 如果是名称完全等于callback和包含callback,得到的分值是不是不应该一样?
5657
// 判断参数中的jsonp参数特征,参数名
5758
const paramName = param.name.toLowerCase();
5859
if (paramName.indexOf("callback") !== -1) {

src/config/config.js

Lines changed: 91 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
const {DebuggerTester} = require("../debugger/debugger-tester");
2+
const {Debugger} = require("../debugger/debugger");
3+
const GM_config_name = "js-script-hook-config-name";
4+
15
/**
26
* 支持的相关配置
37
*/
48
class Config {
59

6-
/**
7-
*
8-
* @param urlPattern {String | RegExp} 用于与script类型的请求的URL做匹配进入断点
9-
* @param callbackFunctionParamName {String} 传递jsonp回调函数名字的参数,比如 "callback"
10-
*/
11-
constructor(urlPattern, callbackFunctionParamName) {
10+
constructor() {
11+
12+
// 默认为英文的操作界面
13+
this.language = "english";
1214

1315
// 让用户能够自己指定前缀,也许会有一些拥有感?之前ast hook好像就有个哥们喜欢这样干...
1416
this.prefix = "CC11001100";
@@ -18,13 +20,94 @@ class Config {
1820

1921
// 是否忽略不是jsonp的请求
2022
this.isIgnoreNotJsonpRequest = true;
23+
24+
// 在打开配置页面的时候自动跳转到项目主页
25+
this.autoJumpProjectSiteOnConfiguraion = true;
26+
27+
// 所有的断点
28+
this.debuggers = [];
29+
}
30+
31+
findDebuggerById(id) {
32+
for (let debuggerInformation of this.debuggers) {
33+
if (debuggerInformation.id === id) {
34+
return debuggerInformation;
35+
}
36+
}
37+
return null;
38+
}
39+
40+
addDebugger(debuggerInformation) {
41+
// TODO 2024-12-22 05:06:15 断点的有效性校验
42+
this.debuggers.push(debuggerInformation);
43+
}
44+
45+
removeDebuggerById(id) {
46+
const newDebuggers = [];
47+
for (let debuggerInformation of this.debuggers) {
48+
if (debuggerInformation.id !== id) {
49+
newDebuggers.push(debuggerInformation);
50+
}
51+
}
52+
this.debuggers = newDebuggers;
2153
}
2254

55+
load() {
56+
const configJsonString = GM_getValue(GM_config_name);
57+
if (!configJsonString) {
58+
return this;
59+
}
60+
const o = JSON.parse(configJsonString);
61+
this.language = o.language;
62+
this.prefix = o.prefix;
63+
this.isIgnoreJsSuffixRequest = o.isIgnoreJsSuffixRequest;
64+
this.isIgnoreNotJsonpRequest = o.isIgnoreNotJsonpRequest;
65+
this.autoJumpProjectSiteOnConfiguraion = o.autoJumpProjectSiteOnConfiguraion;
66+
this.debuggers = [];
67+
for (let debuggerInformationObject of o.debuggers) {
68+
const debuggerInformation = new Debugger();
69+
debuggerInformation.id = debuggerInformationObject.id;
70+
debuggerInformation.enable = debuggerInformationObject.enable;
71+
debuggerInformation.urlPattern = debuggerInformationObject.urlPattern;
72+
debuggerInformation.enableRequestDebugger = debuggerInformationObject.enableRequestDebugger;
73+
debuggerInformation.enableResponseDebugger = debuggerInformationObject.enableResponseDebugger;
74+
debuggerInformation.callbackFunctionParamName = debuggerInformationObject.callbackFunctionParamName;
75+
debuggerInformation.comment = debuggerInformationObject.comment;
76+
this.debuggers.push(debuggerInformation);
77+
}
78+
return this;
79+
}
80+
81+
persist() {
82+
const configJsonString = JSON.stringify(this);
83+
GM_setValue(GM_config_name, configJsonString);
84+
}
85+
86+
/**
87+
* 执行测试所有断点,看看是否有条件命中啥的
88+
*
89+
* @param scriptContext {ScriptContext}
90+
*/
91+
testAll(scriptContext) {
92+
for (let jsonpDebugger of this.debuggers) {
93+
new DebuggerTester().test(this, jsonpDebugger, scriptContext);
94+
}
95+
}
96+
97+
}
98+
99+
let globalConfig = new Config();
100+
101+
function initConfig() {
102+
globalConfig.load();
23103
}
24104

25-
const globalConfig = new Config();
105+
function getGlobalConfig() {
106+
return globalConfig;
107+
}
26108

27109
module.exports = {
28110
Config,
29-
globalConfig
111+
initConfig,
112+
getGlobalConfig
30113
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const {GlobalOptionsComponent} = require("./global-options-component");
2+
const {DebuggerManagerComponent} = require("./debugger-manager-component");
3+
const {getGlobalConfig} = require("../../config");
4+
const {getLanguage} = require("./language");
5+
6+
/**
7+
* 使用之前要签署用户协议
8+
*/
9+
class ConfigurationComponent {
10+
11+
constructor() {
12+
this.modalHTML = `
13+
<div id="cc11001100-js-script-hook-configuration-modal-window" style="display:none !important; position:fixed !important; left:0 !important; top:0 !important; width:100% !important; height:100% !important; background-color:rgba(0,0,0,0.85) !important; z-index:2147483646 !important; overflow-y:auto !important;">
14+
<div class="js-script-hook-scrollable-div" style="display: flex; width: 930px !important; text-align: center !important; padding: 30px !important; margin: 10px !important; position:absolute !important; left:50% !important; top:50% !important; transform:translate(-50%, -50%) !important; background:white !important; border-radius:5px !important; box-shadow: 0 4px 8px rgba(0,0,0,0.1) !important; max-width:80% !important; text-align:center !important; z-index:99999999999; !important">
15+
<button id="cc11001100-js-script-hook-configuration-close-btn" style="position:absolute; right:8px; top:8px; cursor:pointer; padding:3px 6px; border:none; background-color:#f44336; color:white; border-radius:50%; font-size:10px;">×</button>
16+
<div id="js-script-hook-configuration-content"></div>
17+
</div>
18+
</div>
19+
`;
20+
}
21+
22+
/**
23+
* 展示配置界面
24+
*/
25+
show() {
26+
27+
// i18n配置语言
28+
let language = getLanguage(getGlobalConfig().language);
29+
30+
// 将模态框添加到body元素中
31+
$(document.body).append($(this.modalHTML));
32+
33+
// 全局配置参数
34+
const globalOptionsComponent = new GlobalOptionsComponent();
35+
$("#js-script-hook-configuration-content").append(globalOptionsComponent.render(language, getGlobalConfig()));
36+
37+
// 断点参数
38+
const debuggerManager = new DebuggerManagerComponent();
39+
$("#js-script-hook-configuration-content").append(debuggerManager.render(language, getGlobalConfig().debuggers));
40+
41+
// 关闭按钮事件处理
42+
document.getElementById("cc11001100-js-script-hook-configuration-close-btn").addEventListener('click', this.closeModalWindow);
43+
document.getElementById("cc11001100-js-script-hook-configuration-modal-window").style.display = 'flex';
44+
}
45+
46+
/**
47+
* 隐藏模态框的函数
48+
*/
49+
closeModalWindow() {
50+
const element = document.getElementById("cc11001100-js-script-hook-configuration-modal-window");
51+
if (element) {
52+
element.parentNode.removeChild(element);
53+
}
54+
}
55+
56+
}
57+
58+
module.exports = {
59+
ConfigurationComponent
60+
}
61+
62+

0 commit comments

Comments
 (0)