diff --git a/.github/workflows/commentcommand.yml b/.github/workflows/commentcommand.yml
new file mode 100644
index 0000000..cec0330
--- /dev/null
+++ b/.github/workflows/commentcommand.yml
@@ -0,0 +1,37 @@
+name: New Issue Comment
+
+on:
+ issue_comment:
+ types: [created]
+
+jobs:
+ create-branch-and-pr:
+ if: contains(github.event.comment.body, '/cba')
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v4
+
+ - name: Set up Git
+ run: |
+ git config user.name "GitHub Actions"
+ git config user.email "actions@github.com"
+
+ - name: Create new branch
+ run: |
+ BRANCH_NAME="cba-branch-${{ github.event.issue.number }}-${{ github.run_id }}"
+ git checkout -b $BRANCH_NAME
+ echo "New branch created: $BRANCH_NAME"
+
+ - name: Push new branch
+ run: |
+ git push origin $BRANCH_NAME
+
+ - name: Create Pull Request
+ uses: peter-evans/create-pull-request@v6
+ with:
+ title: 'PR From Issue'
+ body: 'closes #${{ github.event.issue.number }}'
+ branch: $BRANCH_NAME
+ base: main
diff --git a/options/options.js b/options/options.js
index 42d321d..710b559 100644
--- a/options/options.js
+++ b/options/options.js
@@ -1,57 +1,57 @@
document.addEventListener('DOMContentLoaded', function() {
- const paramsTable = document.getElementById('paramsTable');
- const newParamInput = document.getElementById('newParam');
- const newParamTypeSelect = document.getElementById('newParamType');
- const addButton = document.getElementById('addButton');
- const saveButton = document.getElementById('saveButton');
- const exportButton = document.getElementById('exportButton');
- const importButton = document.getElementById('importButton');
- const importInput = document.getElementById('importInput');
- const presetSelect = document.getElementById('presetSelect');
+ const paramsTable = document.getElementById('paramsTable'); // 获取参数表格元素
+ const newParamInput = document.getElementById('newParam'); // 获取新参数输入框元素
+ const newParamTypeSelect = document.getElementById('newParamType'); // 获取新参数类型选择框元素
+ const addButton = document.getElementById('addButton'); // 获取添加按钮元素
+ const saveButton = document.getElementById('saveButton'); // 获取保存按钮元素
+ const exportButton = document.getElementById('exportButton'); // 获取导出按钮元素
+ const importButton = document.getElementById('importButton'); // 获取导入按钮元素
+ const importInput = document.getElementById('importInput'); // 获取导入输入框元素
+ const presetSelect = document.getElementById('presetSelect'); // 获取预设选择框元素
- let params = [];
- let presetParams = {};
+ let params = []; // 存储参数数组
+ let presetParams = {}; // 存储预设参数
// 读取 maps.json 文件
- fetch(chrome.runtime.getURL('rules/maps.json'))
- .then(response => response.json())
+ fetch(chrome.runtime.getURL('rules/maps.json')) // 使用fetch函数获取maps.json文件
+ .then(response => response.json()) // 将响应转换为JSON格式
.then(data => {
data.forEach(preset => {
- presetParams[preset.name] = preset.loc;
- const option = document.createElement('option');
- option.value = preset.name;
- option.textContent = preset.name;
- presetSelect.appendChild(option);
+ presetParams[preset.name] = preset.loc; // 将预设参数的名称和位置存储到presetParams对象中
+ const option = document.createElement('option'); // 创建option元素
+ option.value = preset.name; // 设置option的值为预设参数的名称
+ option.textContent = preset.name; // 设置option的文本内容为预设参数的名称
+ presetSelect.appendChild(option); // 将option元素添加到预设选择框中
});
// 加载已保存的参数或默认参数
- chrome.storage.sync.get('trackingParams', function(storageData) {
- const defaultPreset = data.find(preset => preset.name === "默认");
- const defaultPresetLoc = defaultPreset ? defaultPreset.loc : null;
+ chrome.storage.sync.get('trackingParams', function(storageData) { // 从存储中获取trackingParams参数
+ const defaultPreset = data.find(preset => preset.name === "默认"); // 查找名称为"默认"的预设参数
+ const defaultPresetLoc = defaultPreset ? defaultPreset.loc : null; // 获取默认预设参数的位置
if (storageData.trackingParams && storageData.trackingParams.length > 0) {
- params = storageData.trackingParams;
- renderTable(params);
+ params = storageData.trackingParams; // 如果存储中存在trackingParams参数,则将其赋值给params数组
+ renderTable(params); // 渲染参数表格
} else if (defaultPresetLoc) {
- loadPresetParams(defaultPresetLoc);
+ loadPresetParams(defaultPresetLoc); // 加载默认预设参数
}
});
})
- .catch(error => console.error('Error loading maps.json:', error));
+ .catch(error => console.error('Error loading maps.json:', error)); // 捕获加载maps.json文件时的错误
function loadPresetParams(presetLoc) {
- fetch(chrome.runtime.getURL(presetLoc))
- .then(response => response.json())
+ fetch(chrome.runtime.getURL(presetLoc)) // 使用fetch函数获取预设参数文件
+ .then(response => response.json()) // 将响应转换为JSON格式
.then(data => {
- params = data;
- renderTable(params);
+ params = data; // 将预设参数赋值给params数组
+ renderTable(params); // 渲染参数表格
})
- .catch(error => console.error(`Error loading ${presetLoc}:`, error));
+ .catch(error => console.error(`Error loading ${presetLoc}:`, error)); // 捕获加载预设参数文件时的错误
}
function renderTable(params) {
- paramsTable.innerHTML = '';
+ paramsTable.innerHTML = ''; // 清空参数表格内容
params.forEach((paramObj, index) => {
- const row = document.createElement('tr');
+ const row = document.createElement('tr'); // 创建表格行元素
row.innerHTML = `
@@ -66,95 +66,61 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
- `;
- paramsTable.appendChild(row);
+ `; // 设置表格行的HTML内容
+ paramsTable.appendChild(row); // 将表格行添加到参数表格中
});
document.querySelectorAll('.delete-button').forEach(button => {
button.addEventListener('click', function() {
- const index = parseInt(this.getAttribute('data-index'));
- params.splice(index, 1);
- renderTable(params);
+ const index = parseInt(this.getAttribute('data-index')); // 获取要删除的参数的索引
+ params.splice(index, 1); // 从params数组中删除指定索引的参数
+ renderTable(params); // 重新渲染参数表格
});
});
document.querySelectorAll('.param-input').forEach(input => {
input.addEventListener('input', function() {
- const index = parseInt(this.getAttribute('data-index'));
- params[index].param = this.value;
+ const index = parseInt(this.getAttribute('data-index')); // 获取参数输入框的索引
+ params[index].param = this.value; // 更新params数组中对应索引的参数值
});
});
document.querySelectorAll('.param-type').forEach(select => {
select.addEventListener('change', function() {
- const index = parseInt(this.getAttribute('data-index'));
- params[index].type = this.value;
+ const index = parseInt(this.getAttribute('data-index')); // 获取参数类型选择框的索引
+ params[index].type = this.value; // 更新params数组中对应索引的参数类型
});
});
}
presetSelect.addEventListener('change', function() {
- const selectedPreset = this.value;
- const presetLoc = presetParams[selectedPreset];
- loadPresetParams(presetLoc);
+ const selectedPreset = this.value; // 获取选择的预设参数名称
+ const presetLoc = presetParams[selectedPreset]; // 获取选择的预设参数的位置
+ loadPresetParams(presetLoc); // 加载选择的预设参数
});
addButton.addEventListener('click', function() {
- const newParam = newParamInput.value.trim();
- const newParamType = newParamTypeSelect.value;
+ const newParam = newParamInput.value.trim(); // 获取新参数的值
+ const newParamType = newParamTypeSelect.value; // 获取新参数的类型
if (newParam) {
- params.push({ param: newParam, type: newParamType });
- newParamInput.value = '';
- renderTable(params);
+ params.push({ param: newParam, type: newParamType }); // 将新参数添加到params数组中
+ newParamInput.value = ''; // 清空新参数输入框
+ renderTable(params); // 渲染参数表格
}
});
saveButton.addEventListener('click', function() {
const params = Array.from(document.querySelectorAll('.param-input')).map((input, index) => {
return { param: input.value.trim(), type: document.querySelectorAll('.param-type')[index].value };
- }).filter(paramObj => paramObj.param);
- chrome.storage.sync.set({ trackingParams: params }, function() {
+ }).filter(paramObj => paramObj.param); // 获取参数表格中的参数值和类型,并过滤掉空参数
+ chrome.storage.sync.set({ trackingParams: params }, function() { // 将参数保存到存储中
console.log('追踪参数已保存:', params);
alert('追踪参数保存成功!');
});
});
exportButton.addEventListener('click', function() {
- const dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(params));
- const downloadAnchorNode = document.createElement('a');
- downloadAnchorNode.setAttribute("href", dataStr);
- downloadAnchorNode.setAttribute("download", "trackingParams.json");
- document.body.appendChild(downloadAnchorNode);
- downloadAnchorNode.click();
- downloadAnchorNode.remove();
- });
-
- importButton.addEventListener('click', function() {
- importInput.click();
- });
-
- importInput.addEventListener('change', function(event) {
- const file = event.target.files[0];
- if (file) {
- const reader = new FileReader();
- reader.onload = function(e) {
- try {
- const importedParams = JSON.parse(e.target.result);
- if (Array.isArray(importedParams)) {
- params = importedParams;
- renderTable(params);
- chrome.storage.sync.set({ trackingParams: params }, function() {
- console.log('导入的追踪参数已保存:', params);
- alert('追踪参数导入成功!');
- });
- } else {
- alert('导入的文件格式不正确。');
- }
- } catch (error) {
- alert('导入过程中出现错误:' + error.message);
- }
- };
- reader.readAsText(file);
- }
+ // 添加参数导出逻辑
+
});
});
diff --git a/popup/script.js b/popup/script.js
index b192706..64e2f28 100644
--- a/popup/script.js
+++ b/popup/script.js
@@ -1,24 +1,31 @@
+// 当DOM加载完成时执行回调函数
document.addEventListener('DOMContentLoaded', function() {
+ // 获取开关元素
const switchElement = document.getElementById('switch');
+ // 获取复选框1元素
const checkbox1 = document.getElementById('checkbox1');
+ // 获取复选框2元素
const checkbox2 = document.getElementById('checkbox2');
- // 获取当前域名
+ // 获取当前活动选项卡的URL
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
if (tabs.length > 0) {
const urlStr = tabs[0].url;
console.log('获取到的 URL: ', urlStr);
+ // 检查URL是否以"http"开头
if (urlStr && urlStr.startsWith('http')) {
try {
+ // 解析URL获取域名
const url = new URL(urlStr);
const domain = url.hostname;
console.log('解析出的域名: ', domain);
- // 从存储中获取当前域名的状态
+ // 从存储中获取当前域名的设置
chrome.storage.sync.get([domain], function(result) {
if (result[domain]) {
const settings = result[domain];
+ // 将获取到的设置应用到开关和复选框元素上
switchElement.checked = settings.switch;
checkbox1.checked = settings.checkbox1;
checkbox2.checked = settings.checkbox2;
@@ -28,7 +35,7 @@ document.addEventListener('DOMContentLoaded', function() {
}
});
- // 保存当前域名的状态
+ // 保存当前域名的设置
function saveSettings() {
const settings = {
switch: switchElement.checked,
@@ -37,21 +44,28 @@ document.addEventListener('DOMContentLoaded', function() {
};
const obj = {};
obj[domain] = settings;
+ // 将设置保存到存储中
chrome.storage.sync.set(obj, function() {
console.log('保存设置: ', settings);
});
}
+ // 监听开关元素的状态变更事件
switchElement.addEventListener('change', function() {
console.log('Switch 状态变更: ', switchElement.checked);
+ // 保存设置
saveSettings();
});
+ // 监听复选框1元素的状态变更事件
checkbox1.addEventListener('change', function() {
console.log('Checkbox1 状态变更: ', checkbox1.checked);
+ // 保存设置
saveSettings();
});
+ // 监听复选框2元素的状态变更事件
checkbox2.addEventListener('change', function() {
console.log('Checkbox2 状态变更: ', checkbox2.checked);
+ // 保存设置
saveSettings();
});
@@ -67,13 +81,19 @@ document.addEventListener('DOMContentLoaded', function() {
});
});
+// 打开选项页面的函数
function openOptionsPage () {
+ // 创建新的选项卡并打开选项页面
chrome.tabs.create({ url: chrome.runtime.getURL("options/options.html") });
}
+// 当DOM加载完成时执行回调函数
document.addEventListener('DOMContentLoaded', function() {
+ // 获取打开选项页面按钮元素
var button = document.getElementById('openOptions');
+ // 监听按钮的点击事件
button.addEventListener('click', function() {
+ // 调用打开选项页面的函数
openOptionsPage();
});
-});
\ No newline at end of file
+});