Skip to content

Commit bbbdf82

Browse files
committed
Update config
* Remove unused settings * Drop edge section * Add targets section to specify urls * Move WARNING_WHEN_CLOSE_DIALOG to GLOBAL section
1 parent 2b6f33f commit bbbdf82

File tree

8 files changed

+62
-108
lines changed

8 files changed

+62
-108
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@
4141
* 書き込み権限がない場合、コマンドプロンプトを管理者権限で起動して作成する
4242
* `C:\Program Files\RepostConfirmationCanceler\RepostConfirmationCanceler.ini` のアクセス権を変更し、ユーザー権限での書き込みを許可した上で、以下のような内容を記載する
4343
* ```
44-
[Edge]
44+
[TARGETS]
4545
*
4646
```
4747
4848
## 動作解説
4949
50-
* ブラウザの拡張機能 RepostConfirmationCanceler が、`RepostConfirmationCanceler.ini`の`[Edge]`セクションに記載されているURLを開いているかを判定する
50+
* ブラウザの拡張機能 RepostConfirmationCanceler が、`RepostConfirmationCanceler.ini`の`[TARGETS]`セクションに記載されているURLを開いているかを判定する
5151
* サイトを開いたタイミングと、30秒ごとのポーリングで判定を行う
5252
* 指定のURLを開いていた場合、ブラウザの拡張機能が RepostConfirmationCancelerTalk.exe を呼び出す。
5353
* このとき、`Q Edge`というメッセージを送信する

RepostConfirmationCanceler/ConfigLoader.cs

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ namespace RepostConfirmationCanceler
1111
internal class Section
1212
{
1313
public string Name;
14-
public bool Disabled = false;
15-
public bool WarningWhenCloseDialog = false;
16-
public StringBuilder ExcludeGroups = new StringBuilder();
1714
public StringBuilder Excludes = new StringBuilder();
1815
public StringBuilder Patterns = new StringBuilder();
1916

@@ -27,12 +24,8 @@ internal class Config
2724
{
2825
public bool IgnoreQueryString = false;
2926
public bool OnlyMainFrame = false;
27+
public bool WarningWhenCloseDialog = false;
3028
public List<Section> SectionList = new List<Section>();
31-
32-
public Section GetEdgeSection()
33-
{
34-
return SectionList.FirstOrDefault(_ => _.Name.ToLowerInvariant() == "[edge]");
35-
}
3629
}
3730

3831
internal static class ConfigLoader
@@ -120,29 +113,9 @@ internal static Config ParseConf(string data)
120113
case '@':
121114
if (global)
122115
{
123-
if (line == "@TOP_PAGE_ONLY")
124-
{
125-
conf.IgnoreQueryString = true;
126-
}
127-
else if (line == "@ONLY_MAIN_FRAME")
128-
{
129-
conf.OnlyMainFrame = true;
130-
}
131-
}
132-
else if (section != null)
133-
{
134-
if (line == "@DISABLED")
135-
{
136-
section.Disabled = true;
137-
}
138-
else if (line == "@WARNING_WHEN_CLOSE_DIALOG")
139-
{
140-
section.WarningWhenCloseDialog = true;
141-
}
142-
else if (line.StartsWith("@EXCLUDE_GROUP:"))
116+
if (line == "@WARNING_WHEN_CLOSE_DIALOG")
143117
{
144-
section.ExcludeGroups.Append(line.Substring("@EXCLUDE_GROUP:".Length));
145-
section.ExcludeGroups.Append('\n');
118+
conf.WarningWhenCloseDialog = true;
146119
}
147120
}
148121
break;

RepostConfirmationCanceler/EdgeConfirmationDialogCanceler.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ internal static void CancelDialog(RuntimeContext context, AutomationElement edge
107107
return;
108108
}
109109

110-
var edgeConfig = context.Config.GetEdgeSection();
111-
if (edgeConfig?.WarningWhenCloseDialog ?? false)
110+
if (context.Config?.WarningWhenCloseDialog ?? false)
112111
{
113112
context.Logger.Log($"Display warning dialog");
114113
ShowWarningDialog();

RepostConfirmationCancelerTalk/cb_config.c

Lines changed: 11 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,13 @@
2525
*/
2626
struct section {
2727
char name[16];
28-
int disabled;
29-
struct strbuf exclude_groups;
3028
struct strbuf patterns;
3129
struct strbuf excludes;
3230
struct section *next; /* linked list */
3331
};
3432

3533
struct config {
36-
int only_main_frame;
37-
int ignore_query_string;
34+
int warning_when_close_dialog;
3835
struct section *section;
3936
};
4037

@@ -64,9 +61,9 @@ static struct section *new_section(char *line)
6461
* You can define variables/URLs in each section like this:
6562
*
6663
* [GLOBAL]
67-
* @TOP_PAGE_ONLY
64+
* @WARNING_WHEN_CLOSE_DIALOG
6865
*
69-
* [Edge]
66+
* [TARGETS]
7067
* https://example.com*
7168
* -https://test.example.com*
7269
*
@@ -77,7 +74,6 @@ static void parse_conf(char *data, struct config *conf)
7774
{
7875
char *line;
7976
int global;
80-
int _default;
8177
struct section *section;
8278
struct section **indirect = &conf->section;
8379

@@ -89,14 +85,10 @@ static void parse_conf(char *data, struct config *conf)
8985
break;
9086
case '[':
9187
global = 0;
92-
_default = 0;
9388

9489
if (strcmp(line, "[GLOBAL]") == 0) {
9590
global = 1;
9691
}
97-
else if (strcmp(line, "[Default]") == 0) {
98-
_default = 1;
99-
}
10092
else {
10193
section = new_section(line);
10294
*indirect = section;
@@ -105,20 +97,9 @@ static void parse_conf(char *data, struct config *conf)
10597
break;
10698
case '@':
10799
if (global) {
108-
if (strcmp(line, "@TOP_PAGE_ONLY") == 0) {
109-
conf->ignore_query_string = 1;
110-
}
111-
else if (strcmp(line, "@ONLY_MAIN_FRAME") == 0) {
112-
conf->only_main_frame = 1;
113-
}
114-
}
115-
else if (section) {
116-
if (strcmp(line, "@DISABLED") == 0) {
117-
section->disabled = 1;
118-
}
119-
else if (strstr(line, "@EXCLUDE_GROUP:") == line) {
120-
strbuf_concat(&section->exclude_groups, line + strlen("@EXCLUDE_GROUP:"));
121-
strbuf_putchar(&section->exclude_groups, '\n');
100+
if (line == "@WARNING_WHEN_CLOSE_DIALOG")
101+
{
102+
conf.warning_when_close_dialog = true;
122103
}
123104
}
124105
break;
@@ -150,22 +131,6 @@ static char *dump_section(struct section *section)
150131
strbuf_concat_jsonstr(&sb, section->name, strlen(section->name));
151132
strbuf_putchar(&sb, ',');
152133

153-
strbuf_concat(&sb, "\"ExcludeGroups\":[");
154-
if (section->exclude_groups.buf) {
155-
ptr = section->exclude_groups.buf;
156-
need_comma = 0;
157-
while (*ptr) {
158-
if (need_comma)
159-
strbuf_putchar(&sb, ',');
160-
161-
end = strchr(ptr, '\n');
162-
strbuf_concat_jsonstr(&sb, ptr, end - ptr);
163-
need_comma = 1;
164-
ptr = end + 1;
165-
}
166-
}
167-
strbuf_concat(&sb, "],");
168-
169134
/* URLPatterns */
170135
strbuf_concat(&sb, "\"Patterns\":[");
171136
if (section->patterns.buf) {
@@ -211,14 +176,9 @@ static char *dump_json(struct config *conf)
211176
char *json;
212177
int need_comma;
213178

214-
/* OnlyMainFrame */
215-
strbuf_concat(&sb, "{\"OnlyMainFrame\":");
216-
strbuf_concat(&sb, _itoa(conf->only_main_frame, buf, 10));
217-
strbuf_putchar(&sb, ',');
218-
219-
/* IgnoreQueryString */
220-
strbuf_concat(&sb, "\"IgnoreQueryString\":");
221-
strbuf_concat(&sb, _itoa(conf->ignore_query_string, buf, 10));
179+
/* WarningWhenCloseDialog */
180+
strbuf_concat(&sb, "\"WarningWhenCloseDialog\":");
181+
strbuf_concat(&sb, _itoa(conf->warning_when_close_dialog, buf, 10));
222182
strbuf_putchar(&sb, ',');
223183

224184
/* Sections */
@@ -227,8 +187,8 @@ static char *dump_json(struct config *conf)
227187
section = conf->section;
228188
need_comma = 0;
229189
while (section) {
230-
/* Disabled or no pattern defined */
231-
if (section->disabled || section->patterns.buf == NULL) {
190+
/* no pattern defined */
191+
if (section->patterns.buf == NULL) {
232192
section = section->next;
233193
continue;
234194
}

Resources/RepostConfirmationCanceler.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
## Configuration File for RepostConfirmationCanceler (ver1.0)
33
#####################################################################
44

5-
[Edge]
5+
[TARGETS]
66
*

doc/Sources/user-guide.md

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -355,27 +355,62 @@ RepostConfirmationCancelerセットアップ先のRepostConfirmationCanceler.ini
355355
356356
例) `C:\Program Files\RepostConfirmationCanceler\RepostConfirmationCanceler.ini`
357357
358+
## 設定ファイルの書式
359+
360+
設定ファイルは、以下のように`[GLOBAL]`セクションと`[TARGETS]`セクションに分かれています。
361+
362+
```
363+
[GLOBAL]
364+
@WARNING_WHEN_CLOSE_DIALOG
365+
366+
[TARGETS]
367+
https://example.com/*
368+
-https://example.com/test/
369+
```
370+
371+
各セクションに対して、必要な項目を設定します。
372+
358373
## 設定項目の一覧
359374
360-
Edgeでの動作については、`[Edge]`セクションに記載します。
375+
### 一般設定
376+
377+
一般設定については、`[GLOBAL]`セクションに記載します。
361378
362379
| 項目 | 設定内容 | 既定 |
363-
|------------|---------------------------------------|------|
364-
| 対象URL一覧(書式は後述) | 「フォームを再送信しますか?」ダイアログをキャンセルするURL|*(すべてのURL)|
365380
| @WARNING_WHEN_CLOSE_DIALOG | 「フォームを再送信しますか?」ダイアログをキャンセルしたとき、追加の警告ダイアログを表示する | 無効 |
366381
382+
#### @WARNING_WHEN_CLOSE_DIALOG
383+
384+
フォームを再送信しますか?」ダイアログをキャンセルしたとき、以下のような追加の警告ダイアログを表示します。
385+
386+
![](user-guide/media/image31.png)
387+
388+
以下のように値なしのパラメータとして指定します。
389+
390+
```
391+
[GLOBAL]
392+
@WARNING_WHEN_CLOSE_DIALOG
393+
```
394+
395+
### 対象URL一覧
396+
397+
対象URL一覧については、`[TARGETS]`セクションに記載します。
398+
399+
| 項目 | 設定内容 | 既定 |
400+
|------------|---------------------------------------|------|
401+
| 対象URL一覧(書式は後述) | 「フォームを再送信しますか?」ダイアログをキャンセルするURL|*(すべてのURL)|
367402
368403
注: いずれかのタブで対象URLを開いている場合に本プログラムが動作します。実際に開いているURLが対象URLでなくても、別のタブで対象URLを
369404
開いている場合、「フォームを再送信しますか?」ダイアログがキャンセルされます。
370405
371-
### 対象URL一覧書式
406+
#### 対象URL一覧書式
372407
373408
対象URL一覧は以下のようにURL全体を改行切りで指定します。
374409
375410
例)
376411
377412
```
378-
[Edge]
413+
[TARGETS]
379414
https://www.clear-code.com/
380415
https://example.com/
381416
```
@@ -402,26 +437,13 @@ https://example.com/
402437
例)
403438
404439
```
405-
[Edge]
440+
[TARGETS]
406441
https://example.com/*
407442
-https://example.com/test/
408443
```
409444
410445
これは「`https://example.com/`を含むサイトを対象とするが、`https://example.com/test/`は除外する」という設定です。
411446
412-
### @WARNING_WHEN_CLOSE_DIALOG
413-
414-
フォームを再送信しますか?」ダイアログをキャンセルしたとき、以下のような追加の警告ダイアログを表示します。
415-
416-
![](user-guide/media/image31.png)
417-
418-
以下のように値なしのパラメータとして指定します。
419-
420-
```
421-
[Edge]
422-
@WARNING_WHEN_CLOSE_DIALOG
423-
```
424-
425447
## グループポリシー(GPO)を利用した設定ファイルの配布手順
426448
427449
ADに所属している端末の設定を強制する場合、グループポリシー(GPO)で設定ファイルを配布することで強制します。

doc/verify/sources/TestTools/Senarios/scenario3.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[Edge]
1+
[TARGETS]
22
*://example.com/jp*
33
*://example.com/us/??/
44
https://www.clear-code.com/

webextensions/edge/background.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const RepostConfirmationCancelerTalkClient = {
8383

8484
/*
8585
* Request monitoring to Native Messaging Hosts.
86-
* * Request Example: "Q edge https://example.com/".
86+
* * Request Example: "Q edge".
8787
*/
8888
startMonitoring() {
8989
const query = new String('Q ' + BROWSER);
@@ -128,7 +128,7 @@ const RepostConfirmationCancelerTalkClient = {
128128

129129
console.log(`* Lookup sections for ${urlToMatch}`);
130130
for (const section of config.Sections) {
131-
if (section.Name.toLowerCase() !== "edge")
131+
if (section.Name.toLowerCase() !== "targets")
132132
{
133133
continue;
134134
}

0 commit comments

Comments
 (0)