Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
akoya-tomo committed Nov 6, 2018
2 parents 68934de + 6009d59 commit d7f5be5
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 29 deletions.
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,37 @@
NGにしたい文字列を選択してからツールバーボタンを押すとNGワード入力欄に反映されます。
- 設定の変更やNGワードの登録が直ぐにスレに反映されるように変更
スレを更新しなくても設定の変更やNGワードの登録が直ぐに反映されます。
- ![\(New\)](images/new.png "New") NGワードのインポート・エクスポート機能を追加
- NGワードのインポート・エクスポート機能を追加
登録したNGワードをエクスポートして保存したり、インポートして戻すことができます。
- ![\(New\)](images/new.png "New") NGワードの設定に「一時的に登録」を追加
ブラウザを閉じたり再起動すると「一時的に登録」にチェックされたNGワードが削除されます。
IDや塩のファイル名など短時間でNGの効果が無くなるNGワードにご利用ください。
- ![\(New\)](images/new.png "New") コンテキストメニューからID・IPをNGワードに直接登録する機能を追加(デフォルト:無効)
NGにしたいID(IP)のレスの上で右クリックしてコンテキストメニューから「NG登録:ID(IP):~」を選択するとNGワードとして登録されます。
IDとIPでそれぞれ一時的に登録するかオプションで設定できます。

## インストール
**GitHub**
[![インストールボタン](images/install_button.png "クリックでアドオンをインストール")](https://github.com/akoya-tomo/koshian_ng_kai/releases/download/v1.4.0/koshian_ng_kai-1.4.0-fx.xpi)
[![インストールボタン](images/install_button.png "クリックでアドオンをインストール")](https://github.com/akoya-tomo/koshian_ng_kai/releases/download/v1.5.0/koshian_ng_kai-1.5.0-fx.xpi)

※「接続エラーのため、アドオンをダウンロードできませんでした。」と表示されてインストール出来ないときはインストールボタンを右クリックしてxpiファイルをダウンロードし、メニューのツール→アドオン(またはCtrl+Shift+A)で表示されたアドオンマネージャーのページにxpiファイルをドラッグ&ドロップして下さい。

## 追加機能の補足
* NGワードを登録した後でも「本文」「メール欄など」「大文字・小文字を区別しない」のチェックは自由に変更できます。「本文」「メ欄」のチェックを外せば、NGワードを登録したまま無効にすることもできます
* NGワードを登録した後でも「本文」「メール欄など」「大文字・小文字を区別しない」「一時的に登録」のチェックは自由に変更できます。「本文」「メ欄」のチェックを外せば、NGワードを登録したまま無効になります
* NGワードに登録済みと同じワードを登録すると重複せず新しい設定に上書きされます。
* ![\(New\)](images/new.png "New") コンテキストメニューからのID・IPのNG登録はレス以外(スレ本文・引用ポップアップ・IDポップアップなど)では表示されません。
* ![\(New\)](images/new.png "New") [futaba ID+IP popup](https://greasyfork.org/ja/scripts/8189-futaba-id-ip-popup/)使用時、IPは赤字の部分のみ登録されます。
* ![\(New\)](images/new.png "New") 本アドオンが自動または手動で更新されると一時的に登録されたNGワードは削除されます。

## 注意事項
* 本アドオンを有効にしたときはオリジナル版を無効にするか削除して下さい。
* オリジナル版とは別アドオンなので設定は初期値に戻ります。
再度設定をお願い致します。

## 今後の予定
* 一時的なNGワードの登録
- 永続的な登録を必要としないIDやIPの登録を想定しています。

## 更新履歴
* v1.5.0 2018-11-06
- 「一時的に登録」機能を追加
- コンテキストメニューからID・IPをNGワード登録する機能を追加
* v1.4.0 2018-09-30
- NGワードのインポート・エクスポート機能を追加
* v1.3.1 2018-09-26
Expand Down
47 changes: 47 additions & 0 deletions koshian_ng/bg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
let ng_word_list = [];

function removeMenu(){
browser.contextMenus.remove("koshian_ng");
}

browser.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === "koshian_ng") {
let tab_id = tab.id;
browser.tabs.sendMessage(
tab_id,
{id:"koshian_ng_context"}
);
}
});

browser.contextMenus.onHidden.addListener(removeMenu);

browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.id == "koshian_ng_idip") {
browser.contextMenus.create({
id: "koshian_ng",
title: `NG登録:${message.text}`,
contexts: ["page"],
documentUrlPatterns: ["*://*.2chan.net/*/res/*"]
});
browser.contextMenus.refresh();
}
});

function onLoadSetting(result) {
ng_word_list = safeGetValue(result.ng_word_list, []);
// 一時的な登録を削除
ng_word_list = ng_word_list.filter((value) => {
return !value[4];
});

browser.storage.local.set({
ng_word_list: ng_word_list
});
}

function safeGetValue(value, default_value) {
return value === undefined ? default_value : value;
}

browser.storage.local.get().then(onLoadSetting, (err) => {});
10 changes: 7 additions & 3 deletions koshian_ng/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"name":"KOSHIAN NG 改",

"version":"1.4.0",
"version":"1.5.0",

"applications": {
"gecko": {
Expand All @@ -29,9 +29,13 @@
"js":["res.js"]
}
],


"background": {
"scripts": ["bg.js"]
},

"permissions":[
"storage"
"storage", "contextMenus"
],

"options_ui":{
Expand Down
16 changes: 14 additions & 2 deletions koshian_ng/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,17 @@
<input type="number" id="hide_size" min="1" max>
<label for="hide_size">[隠す]ボタンのサイズ</label>
</p>
<ul style="list-style-type: none">
<p>
<input type="checkbox" id="use_contextmenu">
<label for="use_contextmenu">コンテキストメニューからID・IPをNGワード登録する</label>
<br>
<input type="checkbox" id="regist_id_temp">
<label for="regist_id_temp">IDは一時的に登録する</label>
<br>
<input type="checkbox" id="regist_ip_temp">
<label for="regist_ip_temp">IPは一時的に登録する</label>
</p>
<ul style="list-style-type: none">
<p>
NGワード (正規表現が使えます)<br>
<input type="text" id="ng_input" placeholder="NGワードを入力" autofocus>
Expand All @@ -42,8 +52,10 @@
<label for="check_header">メール欄など </label>
<input type="checkbox" id="ignore_case">
<label for="ignore_case" >大文字/小文字を区別しない </label>
<input type="checkbox" id="temporary_regist">
<label for="temporary_regist" >一時的に登録 </label>
</p>
<p><div class="col_btn"> </div><div class="col_check">本文</div><div class="col_check">メ欄</div><div class="col_check">大/小</div><div class="col_text"> NGワード</div></p>
<p><div class="col_btn"> </div><div class="col_check">本文</div><div class="col_check">メ欄</div><div class="col_check">大/小</div><div class="col_check">一時</div><div class="col_text"> NGワード</div></p>
<p id="ng_list">
</p>
</ul>
Expand Down
43 changes: 37 additions & 6 deletions koshian_ng/options.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const check_box_num = 3; // NGワードのワード当たりのチェックボックスの数
const check_box_num = 4; // NGワードのワード当たりのチェックボックスの数

let g_hide_completely = null;
let g_ng_input = null;
Expand All @@ -8,8 +8,12 @@ let g_ng_word_list = [];
let g_check_body = null;
let g_check_header = null;
let g_ignore_case = null;
let g_temporary_regist = null;
let g_put_hide_button = null;
let g_hide_size = null;
let g_use_contextmenu = null;
let g_regist_id_temp = null;
let g_regist_ip_temp = null;
let g_file = null;
let g_import = null;
let g_alert = null;
Expand All @@ -34,7 +38,10 @@ function saveSetting() {
hide_completely: g_hide_completely.checked,
ng_word_list: g_ng_word_list,
put_hide_button: g_put_hide_button.checked,
hide_size: g_hide_size.value
hide_size: g_hide_size.value,
use_contextmenu: g_use_contextmenu.checked,
regist_id_temp: g_regist_id_temp.checked,
regist_ip_temp: g_regist_ip_temp.checked
});
}

Expand Down Expand Up @@ -103,8 +110,14 @@ function setCurrentChoice(result) {
g_hide_completely.checked = safeGetValue(result.hide_completely, false);
g_put_hide_button.checked = safeGetValue(result.put_hide_button, true);
g_hide_size.value = safeGetValue(result.hide_size, 16);
g_use_contextmenu.checked = safeGetValue(result.use_contextmenu, false);
g_regist_id_temp.checked = safeGetValue(result.regist_id_temp, true);
g_regist_ip_temp.checked = safeGetValue(result.regist_ip_temp, true);
g_ng_word_list = safeGetValue(result.ng_word_list, []);

g_regist_id_temp.disabled = !g_use_contextmenu.checked;
g_regist_ip_temp.disabled = !g_use_contextmenu.checked;

for (let i = 0; i < g_ng_word_list.length; ++i) {
let check =[];
for (let j = 0; j < check_box_num; j++) {
Expand All @@ -121,9 +134,13 @@ function onLoad() {
g_ng_list = document.getElementById("ng_list");
g_put_hide_button = document.getElementById("put_hide_button");
g_hide_size = document.getElementById("hide_size");
g_use_contextmenu = document.getElementById("use_contextmenu");
g_regist_id_temp = document.getElementById("regist_id_temp");
g_regist_ip_temp = document.getElementById("regist_ip_temp");
g_check_body = document.getElementById("check_body");
g_check_header = document.getElementById("check_header");
g_ignore_case = document.getElementById("ignore_case");
g_temporary_regist = document.getElementById("temporary_regist");
g_file = document.getElementById("file");
g_import = document.getElementById("import");
g_alert = document.getElementById("alert");
Expand All @@ -133,10 +150,15 @@ function onLoad() {
g_check_body.checked = "checked";

g_hide_completely.addEventListener("change", saveSetting);

g_put_hide_button.addEventListener("change", saveSetting);

g_hide_size.addEventListener("change", saveSetting);
g_use_contextmenu.addEventListener("change", () => {
g_regist_id_temp.disabled = !g_use_contextmenu.checked;
g_regist_ip_temp.disabled = !g_use_contextmenu.checked;
saveSetting();
});
g_regist_id_temp.addEventListener("change", saveSetting);
g_regist_ip_temp.addEventListener("change", saveSetting);

g_ng_input.addEventListener("keypress", (e) => {
if (e.key == "Enter") addNgWord();
Expand Down Expand Up @@ -168,8 +190,8 @@ function onLoad() {
// NGリストの表示を更新
refreshNgList();

addItem(g_ng_input.value, [g_check_body.checked, g_check_header.checked, g_ignore_case.checked]);
g_ng_word_list.push([g_ng_input.value, g_check_body.checked, g_check_header.checked, g_ignore_case.checked]);
addItem(g_ng_input.value, [g_check_body.checked, g_check_header.checked, g_ignore_case.checked, g_temporary_regist.checked]);
g_ng_word_list.push([g_ng_input.value, g_check_body.checked, g_check_header.checked, g_ignore_case.checked, g_temporary_regist.checked]);
g_ng_input.value = "";
saveSetting();
}
Expand Down Expand Up @@ -266,6 +288,15 @@ function onSettingChanged(changes, areaName) {
if (item == "hide_size") {
g_hide_size.value = safeGetValue(changes.hide_size.newValue, 16);
}
if (item == "use_contextmenu") {
g_use_contextmenu.checked = safeGetValue(changes.use_contextmenu.newValue, false);
}
if (item == "regist_id_temp") {
g_regist_id_temp.checked = safeGetValue(changes.regist_id_temp.newValue, true);
}
if (item == "regist_ip_temp") {
g_regist_ip_temp.checked = safeGetValue(changes.regist_ip_temp.newValue, true);
}
}
refreshNgList();
}
Expand Down
5 changes: 4 additions & 1 deletion koshian_ng/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
<br>
<input type="checkbox" id="ignore_case">
<label for="ignore_case" >大文字/小文字を区別しない </label>
</div>
<br>
<input type="checkbox" id="temporary_regist">
<label for="temporary_regist" >一時的に登録 </label>
</div>
</body>

</html>
8 changes: 5 additions & 3 deletions koshian_ng/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ let g_ng_word_list = [];
let g_check_body = null;
let g_check_header = null;
let g_ignore_case = null;
let g_temporary_regist = null;

function onError(error) {
}
Expand All @@ -18,7 +19,7 @@ function safeGetValue(value, default_value) {

function saveSetting() {
browser.storage.local.set({
ng_word_list: g_ng_word_list,
ng_word_list: g_ng_word_list
});
}

Expand All @@ -32,6 +33,7 @@ function onLoad() {
g_check_body = document.getElementById("check_body");
g_check_header = document.getElementById("check_header");
g_ignore_case = document.getElementById("ignore_case");
g_temporary_regist = document.getElementById("temporary_regist");

g_check_body.checked = "checked";

Expand All @@ -42,7 +44,7 @@ function onLoad() {
g_ng_submit.addEventListener("click", addNgWord);

browser.tabs.query({active: true}, function(tab) {
browser.tabs.sendMessage(tab[0].id, {}, function(response) {
browser.tabs.sendMessage(tab[0].id, {id:"koshian_ng_popup"}, function(response) {
g_ng_input.value = response.selection.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&");
});
});
Expand All @@ -59,7 +61,7 @@ function onLoad() {
return value[0] != g_ng_input.value;
});

g_ng_word_list.push([g_ng_input.value, g_check_body.checked, g_check_header.checked, g_ignore_case.checked]);
g_ng_word_list.push([g_ng_input.value, g_check_body.checked, g_check_header.checked, g_ignore_case.checked, g_temporary_regist.checked]);
g_ng_input.value = "";
saveSetting();
alert("NGワードを登録しました");
Expand Down
Loading

0 comments on commit d7f5be5

Please sign in to comment.