diff --git a/README.md b/README.md index 5000f2c..1647553 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,17 @@ Twitterが優遇するクソメディアはどんどん非表示にする予定 4. 完了 ## CHANGELOG +### Ver. 0.5.0 +- 謎の空白が表示されるのを修正 +- 互換性を維持すると結局スマートにはならなかった +### Ver. 0.4.0 +- フリーワード機能 +- データの持ち方を変更(フリーワードに対応するために・既存データとの互換性を検討中) ### Ver. 0.3.0 - 海外対応 +### Ver. 0.2.12 +- add 色々なメディア +- add コスモポリタン ### Ver. 0.2.11 - checkboxのバグ修正 by @umezaki1212 ### Ver. 0.2.10 diff --git a/src/main.js b/src/main.js index c209e14..ac62bd2 100644 --- a/src/main.js +++ b/src/main.js @@ -1,165 +1,272 @@ +const MUTE_LIST = [ + { + "id": "itm_nlab", + "default_value": false, + "mute_word": ["ねとらぼ"] + }, + { + "id": "ABEMATIMES", + "default_value": false, + "mute_word": ["ABEMA TIMES"] + }, + { + "id": "kyodo_official", + "default_value": false, + "mute_word": ["共同通信"] + }, + { + "id" : "Newsweek_JAPAN", + "default_value": false, + "mute_word": ["ニューズウィーク"] + }, + { + "id": "WomanExcite", + "default_value": false, + "mute_word": ["ウーマンエキサイト編集部"] + }, + { + "id": "iVoCE", + "default_value": false, + "mute_word": ["VOCE", "ヴォーチェ"] + }, + { + "id": "Kstyle_news", + "default_value": false, + "mute_word": ["Kstyle"] + }, + { + "id": "cosmopolitanjp", + "default_value": false, + "mute_word": ["Cosmopolitan", "コスモポリタン"] + }, + { + "id": "bizble_asahi", + "default_value": false, + "mute_word": ["bizble", "ビズブル"] + }, + { + "id": "mimollet2015", + "default_value": false, + "mute_word": ["mi-mollet", "ミモレ"] + }, + { + "id": "news_mynavi_jp", + "default_value": false, + "mute_word": ["マイナビニュース"] + }, + { + "id": "trend_covid19", + "default_value": false, + "mute_word": ["COVID-19"] + }, + { + "id": "oricon", + "default_value": false, + "mute_word": ["ORICON NEWS"] + }, + { + "id": "modelpress", + "default_value": false, + "mute_word": ["モデルプレス"] + }, + { + "id": "ld_blogos", + "default_value": false, + "mute_word": ["BLOGOS"] + }, + { + "id": "japanacademy", + "default_value": false, + "mute_word": ["日本アカデミー賞協会"] + }, + { + "id": "ntvnewszero", + "default_value": false, + "mute_word": ["news zero"] + }, + { + "id": "mamadaystv", + "default_value": false, + "mute_word": ["MAMADAYS", "ママデイズ"] + }, + { + "id": "BIJapan", + "default_value": false, + "mute_word": ["Business Insider Japan"] + }, + { + "id": "GINZA_magazine", + "default_value": false, + "mute_word": ["GINZA"] + }, + { + "id": "auto_scroll_by_1", + "default_value": false, + "mute_word": [] + }, + { + "id": "word_birthday", + "default_value": false, + "mute_word": ["誕生日"] + }, + { + "id": "mute_level_hard", + "default_value": false, + "mute_word": [] + }, + { + "id": "sankeibiz", + "default_value": false, + "mute_word": ["SankeiBiz"] + }, + { + "id": "nhk_news", + "default_value": false, + "mute_word": ["NHKニュース", "NHK NEWS"] + }, + { + "id": "word_china", + "default_value": false, + "mute_word": ["中国"] + }, + { + "id": "word_korea", + "default_value": false, + "mute_word": ["韓国"] + }, + { + "id": "tastyjapan", + "default_value": false, + "mute_word": ["Tasty Japan"] + }, + { + "id": "frau_tw", + "default_value": false, + "mute_word": ["FRaU"] + }, + { + "id": "gekisaka", + "default_value": false, + "mute_word": ["ゲキサカ"] + }, + { + "id": "gendai_biz", + "default_value": false, + "mute_word": ["現代ビジネス"] + }, + { + "id": "word_BTS", + "default_value": false, + "mute_word": ["BTS"] + }, + { + "id": "shin_R25", + "default_value": false, + "mute_word": ["新R25編集部"] + }, + { + "id": "crea_web", + "default_value": false, + "mute_word": ["CREA"] + }, + { + "id": "hst_tvasahi", + "default_value": false, + "mute_word": ["報道ステーション"] + }, + { + "id": "news24ntv", + "default_value": false, + "mute_word": ["日テレNEWS"] + }, + { + "id": "jijicom", + "default_value": false, + "mute_word": ["時事ドットコム"] + }, + { + "id": "trend_kpop", + "default_value": false, + "mute_word": ["K-POP · トレンド"] + }, + { + "id": "trend_seiji", + "default_value": false, + "mute_word": ["政治 · トレンド"] + }, + { + "id": "jijimedical", + "default_value": false, + "mute_word": ["時事メディカル"] + }, + { + "id": "numberweb", + "default_value": false, + "mute_word": ["Number編集部"] + }, + { + "id": "asahicom", + "default_value": false, + "mute_word": ["朝日新聞", "AREA"] + }, + { + "id": "toyokeizai", + "default_value": false, + "mute_word": ["東洋経済"] + }, + { + "id": "fnn", + "default_value": false, + "mute_word": ["FNN"] + }, + { + "id": "bunshun", + "default_value": false, + "mute_word": ["文春"] + }, + { + "id": "huffpost", + "default_value": true, + "mute_word": ["ハフポスト"] + }, + { + "id": "buzzfeed", + "default_value": true, + "mute_word": ["BuzzFeed", "バズフィード"] + }, + { + "id": "mode_overseas", + "default_value": false, + "mute_word": [] + }, + { + "id": "move_hard_translate_y_help", + "default_value": false, + "mute_word": [] + }, + { + "id": "apply_new_mute_list", + "default_value": false, + "mute_word": [] + } +]; +// --- let muteCounter = 0; -let twitterMute = { - buzzfeed: true, - huffpost: true, - bunshun: false, - fnn: false, - toyokeizai: false, - asahicom: false, - numberweb: false, - jijimedical: false, - trend_seiji: false, - trend_kpop: false, - jijicom: false, - news24ntv: false, - hst_tvasahi: false, - crea_web: false, - shin_R25: false, - word_BTS: false, - gendai_biz: false, - gekisaka: false, - frau_tw: false, - tastyjapan: false, - word_korea: false, - word_china: false, - nhk_news: false, - sankeibiz: false, - mute_level_hard: false, - word_birthday: false, - auto_scroll_by_1: false, - GINZA_magazine: false, - BIJapan: false, - mamadaystv: false, - ntvnewszero: false, - japanacademy: false, - ld_blogos: false, - modelpress: false, - oricon: false, - trend_covid19: false, - news_mynavi_jp: false, - bizble_asahi: false, - mode_overseas: false +let settings = { + mute_list: [] }; const filterFunc = (e) => { - var result = false; - if (twitterMute.buzzfeed) { - result = e.innerText.includes('BuzzFeed') || e.innerText.includes('バズフィード') || result; - } - if (twitterMute.huffpost) { - result = e.innerText.includes('ハフポスト') || result; - } - if (twitterMute.bunshun) { - result = e.innerText.includes('文春') || result; - } - if (twitterMute.fnn) { - result = e.innerText.includes('FNN') || result; - } - if (twitterMute.toyokeizai) { - result = e.innerText.includes('東洋経済') || result; - } - if (twitterMute.asahicom) { - result = e.innerText.includes('朝日新聞') || result; - } - if (twitterMute.numberweb) { - result = e.innerText.includes('Number編集部') || result; - } - if (twitterMute.jijimedical) { - result = e.innerText.includes('時事メディカル') || result; - } - if (twitterMute.trend_seiji) { - result = e.innerText.includes('政治 · トレンド') || result; - } - if (twitterMute.trend_kpop) { - result = e.innerText.includes('K-POP · トレンド') || result; - } - if (twitterMute.jijicom) { - result = e.innerText.includes('時事ドットコム') || result; - } - if (twitterMute.news24ntv) { - result = e.innerText.includes('日テレNEWS') || result; - } - if (twitterMute.hst_tvasahi) { - result = e.innerText.includes('報道ステーション') || result; - } - if (twitterMute.crea_web) { - result = e.innerText.includes('CREA') || result; - } - if (twitterMute.shin_R25) { - result = e.innerText.includes('新R25編集部') || result; - } - if (twitterMute.word_BTS) { - result = e.innerText.includes('BTS') || result; - } - if (twitterMute.gendai_biz) { - result = e.innerText.includes('現代ビジネス') || result; - } - if (twitterMute.gekisaka) { - result = e.innerText.includes('ゲキサカ') || result; - } - if (twitterMute.frau_tw) { - result = e.innerText.includes('FRaU') || result; - } - if (twitterMute.tastyjapan) { - result = e.innerText.includes('Tasty Japan') || result; - } - if (twitterMute.word_korea) { - result = e.innerText.includes('韓国') || result; - } - if (twitterMute.word_china) { - result = e.innerText.includes('中国') || result; - } - if (twitterMute.nhk_news) { - result = e.innerText.includes('NHKニュース') || e.innerText.includes('NHK NEWS') || result; - } - if (twitterMute.sankeibiz) { - result = e.innerText.includes('SankeiBiz') || result; + if (settings.mute_list) { + return settings.mute_list.some((keyword) => e.innerText.includes(keyword)); } - if (twitterMute.word_birthday) { - result = e.innerText.includes('誕生日') || result; - } - if (twitterMute.GINZA_magazine) { - result = e.innerText.includes('GINZA') || result; - } - if (twitterMute.BIJapan) { - result = e.innerText.includes('Business Insider Japan') || result; - } - if (twitterMute.mamadaystv) { - result = e.innerText.includes('MAMADAYS') || e.innerText.includes('ママデイズ') || result; - } - if (twitterMute.ntvnewszero) { - result = e.innerText.includes('news zero') || result; - } - if (twitterMute.japanacademy) { - result = e.innerText.includes('日本アカデミー賞協会') || result; - } - if (twitterMute.ld_blogos) { - result = e.innerText.includes('BLOGOS') || result; - } - if (twitterMute.modelpress) { - result = e.innerText.includes('モデルプレス') || result; - } - if (twitterMute.oricon) { - result = e.innerText.includes('ORICON NEWS') || result; - } - if (twitterMute.trend_covid19) { - result = e.innerText.includes('COVID-19') || result; - } - if (twitterMute.news_mynavi_jp) { - result = e.innerText.includes('マイナビニュース') || result; - } - if (twitterMute.mimollet2015) { - result = e.innerText.includes('mi-mollet') || e.innerText.includes('ミモレ') || result; - } - if (twitterMute.bizble_asahi) { - result = e.innerText.includes('bizble') || e.innerText.includes('ビズブル') || result; - } - return result; + return false; } const observer = new MutationObserver((mutations) => { muteCounter++; if (muteCounter % 3 !== 0) { return; } + console.log(settings); try { [...document.querySelectorAll('div[aria-label="タイムライン: トレンド"] > div > div')] .filter(filterFunc) @@ -167,14 +274,28 @@ const observer = new MutationObserver((mutations) => { [...document.querySelectorAll('div[aria-label="タイムライン: 話題を検索"] > div > div')] .filter(filterFunc) .forEach((e) => e.style.display = 'none'); - if (twitterMute.auto_scroll_by_1) { + + if (settings.move_hard_translate_y) { + [...document.querySelectorAll('div[aria-label="タイムライン: トレンド"] > div > div')] + .filter(filterFunc) + .forEach((e) => e.style.display = undefined); + [...document.querySelectorAll('div[aria-label="タイムライン: 話題を検索"] > div > div')] + .filter(filterFunc) + .forEach((e) => e.style.display = undefined); + [...document.querySelectorAll('div[aria-label="タイムライン: トレンド"] > div > div')] + .filter(filterFunc) + .forEach((e) => e.style.display = 'none'); + [...document.querySelectorAll('div[aria-label="タイムライン: 話題を検索"] > div > div')] + .filter(filterFunc) + .forEach((e) => e.style.display = 'none'); } + if (settings.auto_scroll_by_1) { window.scrollBy(0, 1); window.scrollBy(0, -1); } } catch (e) { console.error(e); } - if (twitterMute.mode_overseas) { + if (settings.mode_overseas) { try { [...document.querySelectorAll('section[aria-labelledby|="accessible-list"] > div > div > div[class]')] .filter(filterFunc) @@ -182,7 +303,7 @@ const observer = new MutationObserver((mutations) => { [...document.querySelectorAll('div > div:nth-child(2) > div > div > section[aria-labelledby^="accessible-list"] > div > div > div')] .filter(filterFunc) .forEach((e) => e.style.display = 'none'); - if (twitterMute.auto_scroll_by_1) { + if (settings.auto_scroll_by_1) { window.scrollBy(0, 1); window.scrollBy(0, -1); } @@ -190,7 +311,7 @@ const observer = new MutationObserver((mutations) => { console.error(e); } } - if (twitterMute.mute_level_hard) { + if (settings.mute_level_hard) { setTimeout(() => { try { [...document.querySelectorAll('div[aria-label="タイムライン: トレンド"] > div > div')] @@ -199,7 +320,7 @@ const observer = new MutationObserver((mutations) => { [...document.querySelectorAll('div[aria-label="タイムライン: 話題を検索"] > div > div')] .filter(filterFunc) .forEach((e) => e.style.display = 'none'); - if (twitterMute.auto_scroll_by_1) { + if (settings.auto_scroll_by_1) { window.scrollBy(0, 1); window.scrollBy(0, -1); } @@ -212,87 +333,32 @@ const observer = new MutationObserver((mutations) => { const config = { attributes: false, childList: true, characterData: false, subtree: true }; observer.observe(document.body, config); -chrome.storage.sync.get({ - buzzfeed: true, - huffpost: true, - bunshun: false, - fnn: false, - toyokeizai: false, - asahicom: false, - numberweb: false, - jijimedical: false, - trend_seiji: false, - trend_kpop: false, - jijicom: false, - news24ntv: false, - hst_tvasahi: false, - crea_web: false, - shin_R25: false, - word_BTS: false, - gendai_biz: false, - gekisaka: false, - frau_tw: false, - tastyjapan: false, - word_korea: false, - word_china: false, - nhk_news: false, - sankeibiz: false, - mute_level_hard: false, - word_birthday: false, +chrome.storage.sync.get(Object.assign({ + mute_list: ["BuzzFeed", "バズフィード", "ハフポスト"], auto_scroll_by_1: false, - GINZA_magazine: false, - BIJapan: false, - mamadaystv: false, - ntvnewszero: false, - japanacademy: false, - ld_blogos: false, - modelpress: false, - oricon: false, - trend_covid19: false, - news_mynavi_jp: false, - mimollet2015: false, - bizble_asahi: false, - mode_overseas: false -}, (items) => { - twitterMute.buzzfeed = items.buzzfeed; - twitterMute.huffpost = items.huffpost; - twitterMute.bunshun = items.bunshun; - twitterMute.fnn = items.fnn; - twitterMute.toyokeizai = items.toyokeizai; - twitterMute.asahicom = items.asahicom; - twitterMute.numberweb = items.numberweb; - twitterMute.jijimedical = items.jijimedical; - twitterMute.trend_seiji = items.trend_seiji; - twitterMute.trend_kpop = items.trend_kpop; - twitterMute.jijicom = items.jijicom; - twitterMute.news24ntv = items.news24ntv; - twitterMute.hst_tvasahi = items.hst_tvasahi; - twitterMute.crea_web = items.crea_web; - twitterMute.shin_R25 = items.shin_R25; - twitterMute.word_BTS = items.word_BTS; - twitterMute.gendai_biz = items.gendai_biz; - twitterMute.gekisaka = items.gekisaka; - twitterMute.frau_tw = items.frau_tw; - twitterMute.tastyjapan = items.tastyjapan; - twitterMute.word_korea = items.word_korea; - twitterMute.word_china = items.word_china; - twitterMute.nhk_news = items.nhk_news; - twitterMute.sankeibiz = items.sankeibiz; - twitterMute.mute_level_hard = items.mute_level_hard; - twitterMute.word_birthday = items.word_birthday; - twitterMute.auto_scroll_by_1 = items.auto_scroll_by_1; - twitterMute.GINZA_magazine = items.GINZA_magazine; - twitterMute.BIJapan = items.BIJapan; - twitterMute.mamadaystv = items.mamadaystv; - twitterMute.ntvnewszero = items.ntvnewszero; - twitterMute.japanacademy = items.japanacademy; - twitterMute.ld_blogos = items.ld_blogos; - twitterMute.modelpress = items.modelpress; - twitterMute.oricon = items.oricon; - twitterMute.trend_covid19 = items.trend_covid19; - twitterMute.news_mynavi_jp = items.news_mynavi_jp; - twitterMute.mimollet2015 = items.mimollet2015; - twitterMute.bizble_asahi = items.bizble_asahi; - twitterMute.mode_overseas = items.mode_overseas; -}); - + mute_level_hard: false, + mode_overseas: false, + move_hard_translate_y: false, + apply_new_mute_list: false +}, MUTE_LIST.reduce((a, c) => { + a[c.id] = c.default_value; + return a; +}, {})), (data) => { + if (!data.apply_new_mute_list) { + var mute_list = data.mute_list.concat(MUTE_LIST.reduce((a, c) => { + if (data[c.id]) { + a = a.concat(c.mute_word); + } + return a; + }, [])); + settings.mute_list = mute_list; + // options + settings.auto_scroll_by_1 = data.auto_scroll_by_1; + settings.mute_level_hard = data.mute_level_hard; + settings.mode_overseas = data.mode_overseas; + settings.move_hard_translate_y = data.move_hard_translate_y; + settings.apply_new_mute_list = data.apply_new_mute_list; + } else { + settings = Object.assign(settings, data); + } +}); \ No newline at end of file diff --git a/src/manifest.json b/src/manifest.json index da1eab1..df36925 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "twitter-mute-buzzfuff", - "version": "0.3.0", + "version": "0.5.0", "description": "鬱陶しいメディアを目に入らなくする", "icons": { "128": "img/128.png", diff --git a/src/options.html b/src/options.html index d3d519c..3ee0af2 100644 --- a/src/options.html +++ b/src/options.html @@ -7,234 +7,12 @@
-

非表示にしたいサイト

保存後、Twitterのページをリロードしてください。

-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
- -

トレンド

-
- - -
-
- - -
-
- - -
-

キーワード(試用)

-
- - -
-
- - -
-
- - -
-
- - -
-

ミュート強度

+

非表示にしたいサイト

+

トレンド

+

キーワード(試用)

+

設定

+

ミュート強度

-

描画補助

+

描画補助

-

+
+ + +
+ 非表示処理を2回適用するので画面がチラつく可能性があります +
+
+

フリーワード

+ +
+ 1行につき1ワード。改行で区切ってください。 +
+

diff --git a/src/options.js b/src/options.js index 12da940..5328320 100644 --- a/src/options.js +++ b/src/options.js @@ -1,46 +1,401 @@ +const MUTE_LIST = [ + { + "id": "itm_nlab", + "default_value": false, + "name": "ねとらぼ", + "section": 1, + "mute_word": ["ねとらぼ"] + }, + { + "id": "ABEMATIMES", + "default_value": false, + "name": "ABEMA TIMES", + "section": 1, + "mute_word": ["ABEMA TIMES"] + }, + { + "id": "kyodo_official", + "default_value": false, + "name": "共同通信公式", + "section": 1, + "mute_word": ["共同通信"] + }, + { + "id" : "Newsweek_JAPAN", + "default_value": false, + "name" : "ニューズウィーク日本版", + "section": 1, + "mute_word": ["ニューズウィーク"] + }, + { + "id": "WomanExcite", + "default_value": false, + "name": "ウーマンエキサイト編集部", + "section": 1, + "mute_word": ["ウーマンエキサイト編集部"] + }, + { + "id": "iVoCE", + "default_value": false, + "name" : "iVoCE", + "section": 1, + "mute_word": ["VOCE", "ヴォーチェ"] + }, + { + "id": "Kstyle_news", + "default_value": false, + "name": "Kstyle", + "section": 1, + "mute_word": ["Kstyle"] + }, + { + "id": "cosmopolitanjp", + "default_value": false, + "name": "Cosmopolitan/コスモポリタン", + "section": 1, + "mute_word": ["Cosmopolitan", "コスモポリタン"] + }, + { + "id": "bizble_asahi", + "default_value": false, + "name": "bizble(ビズブル)", + "section": 1, + "mute_word": ["bizble", "ビズブル"] + }, + { + "id": "mimollet2015", + "default_value": false, + "name": "mi-mollet/ミモレ", + "section": 1, + "mute_word": ["mi-mollet", "ミモレ"] + }, + { + "id": "news_mynavi_jp", + "default_value": false, + "name": "マイナビニュース", + "section": 1, + "mute_word": ["マイナビニュース"] + }, + { + "id": "trend_covid19", + "default_value": false, + "name": "COVID-19", + "section": 2, + "mute_word": ["COVID-19"] + }, + { + "id": "oricon", + "default_value": false, + "name": "ORICON NEWS(オリコンニュース)", + "section": 1, + "mute_word": ["ORICON NEWS"] + }, + { + "id": "modelpress", + "default_value": false, + "name": "モデルプレス", + "section": 1, + "mute_word": ["モデルプレス"] + }, + { + "id": "ld_blogos", + "default_value": false, + "name": "BLOGOS", + "section": 1, + "mute_word": ["BLOGOS"] + }, + { + "id": "japanacademy", + "default_value": false, + "name": "日本アカデミー賞協会", + "section": 1, + "mute_word": ["日本アカデミー賞協会"] + }, + { + "id": "ntvnewszero", + "default_value": false, + "name": "news zero", + "section": 1, + "mute_word": ["news zero"] + }, + { + "id": "mamadaystv", + "default_value": false, + "name": "MAMADAYS|ママデイズ", + "section": 1, + "mute_word": ["MAMADAYS", "ママデイズ"] + }, + { + "id": "BIJapan", + "default_value": false, + "name": "Business Insider Japan", + "section": 1, + "mute_word": ["Business Insider Japan"] + }, + { + "id": "GINZA_magazine", + "default_value": false, + "name": "GINZA", + "section": 1, + "mute_word": ["GINZA"] + }, + { + "id": "auto_scroll_by_1", + "default_value": false, + "name": "", + "section": 4, + "mute_word": [] + }, + { + "id": "word_birthday", + "default_value": false, + "name": "誕生日", + "section": 3, + "mute_word": ["誕生日"] + }, + { + "id": "mute_level_hard", + "default_value": false, + "name": "", + "section": 4, + "mute_word": [] + }, + { + "id": "sankeibiz", + "default_value": false, + "name": "SankeiBiz", + "section": 1, + "mute_word": ["SankeiBiz"] + }, + { + "id": "nhk_news", + "default_value": false, + "name": "NHKニュース", + "section": 1, + "mute_word": ["NHKニュース", "NHK NEWS"] + }, + { + "id": "word_china", + "default_value": false, + "name": "中国", + "section": 3, + "mute_word": ["中国"] + }, + { + "id": "word_korea", + "default_value": false, + "name": "韓国", + "section": 3, + "mute_word": ["韓国"] + }, + { + "id": "tastyjapan", + "default_value": false, + "name": "Tasty Japan", + "section": 1, + "mute_word": ["Tasty Japan"] + }, + { + "id": "frau_tw", + "default_value": false, + "name": "FRaU(フラウ)", + "section": 1, + "mute_word": ["FRaU"] + }, + { + "id": "gekisaka", + "default_value": false, + "name": "ゲキサカ", + "section": 1, + "mute_word": ["ゲキサカ"] + }, + { + "id": "gendai_biz", + "default_value": false, + "name": "現代ビジネス", + "section": 1, + "mute_word": ["現代ビジネス"] + }, + { + "id": "word_BTS", + "default_value": false, + "name": "BTS", + "section": 3, + "mute_word": ["BTS"] + }, + { + "id": "shin_R25", + "default_value": false, + "name": "新R25編集部", + "section": 1, + "mute_word": ["新R25編集部"] + }, + { + "id": "crea_web", + "default_value": false, + "name": "CREA", + "section": 1, + "mute_word": ["CREA"] + }, + { + "id": "hst_tvasahi", + "default_value": false, + "name": "報道ステーション+土日ステ", + "section": 1, + "mute_word": ["報道ステーション"] + }, + { + "id": "news24ntv", + "default_value": false, + "name": "日テレNEWS / 日本テレビのニュース・速報", + "section": 1, + "mute_word": ["日テレNEWS"] + }, + { + "id": "jijicom", + "default_value": false, + "name": "時事ドットコム(時事通信ニュース)", + "section": 1, + "mute_word": ["時事ドットコム"] + }, + { + "id": "trend_kpop", + "default_value": false, + "name": "K-POP", + "section": 2, + "mute_word": ["K-POP · トレンド"] + }, + { + "id": "trend_seiji", + "default_value": false, + "name": "政治", + "section": 2, + "mute_word": ["政治 · トレンド"] + }, + { + "id": "jijimedical", + "default_value": false, + "name": "時事メディカル", + "section": 1, + "mute_word": ["時事メディカル"] + }, + { + "id": "numberweb", + "default_value": false, + "name": "Number編集部", + "section": 1, + "mute_word": ["Number編集部"] + }, + { + "id": "asahicom", + "default_value": false, + "name": "朝日新聞", + "section": 1, + "mute_word": ["朝日新聞", "AREA"] + }, + { + "id": "toyokeizai", + "default_value": false, + "name": "東洋経済", + "section": 1, + "mute_word": ["東洋経済"] + }, + { + "id": "fnn", + "default_value": false, + "name": "FNN", + "section": 1, + "mute_word": ["FNN"] + }, + { + "id": "bunshun", + "default_value": false, + "name": "文春", + "section": 1, + "mute_word": ["文春"] + }, + { + "id": "huffpost", + "default_value": true, + "name": "ハフポスト", + "section": 1, + "mute_word": ["ハフポスト"] + }, + { + "id": "buzzfeed", + "default_value": true, + "name": "BuzzFeed", + "section": 1, + "mute_word": ["BuzzFeed", "バズフィード"] + }, + { + "id": "mode_overseas", + "default_value": false, + "name": "", + "section": 4, + "mute_word": [] + }, + { + "id": "move_hard_translate_y", + "default_value": false, + "name": "", + "section": 4, + "mute_word": [] + }, + { + "id": "apply_new_mute_list", + "default_value": false, + "name": "", + "section": 4, + "mute_word": [] + } +]; + +function generateCheckboxes(data) { + var formCheck = document.createElement('div'); + formCheck.classList.add('form-check'); + var input = document.createElement('input'); + input.classList.add('form-check-input'); + input.type = "checkbox"; + input.name = data.id; + input.id = data.id; + formCheck.appendChild(input); + var label = document.createElement('label'); + label.classList.add('form-check-label'); + label.for = data.id; + label.textContent = data.name; + formCheck.appendChild(label); + + if (data.section === 1) { + document.getElementById('section1').insertAdjacentElement('afterend', formCheck); + } else if (data.section === 2) { + document.getElementById('section2').insertAdjacentElement('afterend', formCheck); + } else if (data.section === 3) { + document.getElementById('section3').insertAdjacentElement('afterend', formCheck); + } +} + function saveOptions() { - chrome.storage.sync.set({ - buzzfeed: document.getElementById('buzzfeed').checked, - huffpost: document.getElementById('huffpost').checked, - bunshun: document.getElementById('bunshun').checked, - fnn: document.getElementById('fnn').checked, - toyokeizai: document.getElementById('toyokeizai').checked, - asahicom: document.getElementById('asahicom').checked, - numberweb: document.getElementById('numberweb').checked, - jijimedical: document.getElementById('jijimedical').checked, - trend_seiji: document.getElementById('trend_seiji').checked, - trend_kpop: document.getElementById('trend_kpop').checked, - jijicom: document.getElementById('jijicom').checked, - news24ntv: document.getElementById('news24ntv').checked, - hst_tvasahi: document.getElementById('hst_tvasahi').checked, - crea_web: document.getElementById('crea_web').checked, - shin_R25: document.getElementById('shin_R25').checked, - word_BTS: document.getElementById('word_BTS').checked, - gendai_biz: document.getElementById('gendai_biz').checked, - gekisaka: document.getElementById('gekisaka').checked, - frau_tw: document.getElementById('frau_tw').checked, - tastyjapan: document.getElementById('tastyjapan').checked, - word_korea: document.getElementById('word_korea').checked, - word_china: document.getElementById('word_china').checked, - nhk_news: document.getElementById('nhk_news').checked, - sankeibiz: document.getElementById('sankeibiz').checked, - mute_level_hard: document.getElementById('mute_level_hard').checked, - word_birthday: document.getElementById('word_birthday').checked, - auto_scroll_by_1: document.getElementById('auto_scroll_by_1').checked, - GINZA_magazine: document.getElementById('GINZA_magazine').checked, - BIJapan: document.getElementById('BIJapan').checked, - mamadaystv: document.getElementById('mamadaystv').checked, - ntvnewszero: document.getElementById('ntvnewszero').checked, - japanacademy: document.getElementById('japanacademy').checked, - ld_blogos: document.getElementById('ld_blogos').checked, - modelpress: document.getElementById('modelpress').checked, - oricon: document.getElementById('oricon').checked, - trend_covid19: document.getElementById('trend_covid19').checked, - news_mynavi_jp: document.getElementById('news_mynavi_jp').checked, - mimollet2015: document.getElementById('mimollet2015').checked, - bizble_asahi: document.getElementById('bizble_asahi').checked, - mode_overseas: document.getElementById('mode_overseas').checked - }, () => { + const syncData = MUTE_LIST.reduce((result, current) => { + let checkbox = document.getElementById(current.id); + if (checkbox) { + result[current.id] = checkbox.checked; + if (checkbox.checked) { + result.mute_list = result.mute_list.concat(current.mute_word); + } + } + return result; + }, { mute_list: [], apply_new_mute_list: true }); + + let freeword = document.getElementById('freeword_area').value; + if (freeword && freeword.length > 0) { + syncData.freeword = freeword.split('\n'); + syncData.mute_list = syncData.mute_list.concat(syncData.freeword); + } else { + syncData.freeword = []; + } + + chrome.storage.sync.set(syncData, () => { const status = document.getElementById('status'); status.textContent = '保存しました!'; setTimeout(() => { @@ -50,88 +405,25 @@ function saveOptions() { } function restoreOptions() { - chrome.storage.sync.get({ - buzzfeed: true, - huffpost: true, - bunshun: false, - fnn: false, - toyokeizai: false, - asahicom: false, - numberweb: false, - jijimedical: false, - trend_seiji: false, - trend_kpop: false, - jijicom: false, - news24ntv: false, - hst_tvasahi: false, - crea_web: false, - shin_R25: false, - word_BTS: false, - gendai_biz: false, - gekisaka: false, - frau_tw: false, - tastyjapan: false, - word_korea: false, - word_china: false, - nhk_news: false, - sankeibiz: false, - mute_level_hard: false, - word_birthday: false, - auto_scroll_by_1: false, - GINZA_magazine: false, - BIJapan: false, - mamadaystv: false, - ntvnewszero: false, - japanacademy: false, - ld_blogos: false, - modelpress: false, - oricon: false, - trend_covid19: false, - news_mynavi_jp: false, - mimollet2015: false, - bizble_asahi: false, - mode_overseas: false - }, (items) => { - document.getElementById('buzzfeed').checked = items.buzzfeed; - document.getElementById('huffpost').checked = items.huffpost; - document.getElementById('bunshun').checked = items.bunshun; - document.getElementById('fnn').checked = items.fnn; - document.getElementById('toyokeizai').checked = items.toyokeizai; - document.getElementById('asahicom').checked = items.asahicom; - document.getElementById('numberweb').checked = items.numberweb; - document.getElementById('jijimedical').checked = items.jijimedical; - document.getElementById('trend_seiji').checked = items.trend_seiji; - document.getElementById('trend_kpop').checked = items.trend_kpop; - document.getElementById('jijicom').checked = items.jijicom; - document.getElementById('news24ntv').checked = items.news24ntv; - document.getElementById('hst_tvasahi').checked = items.hst_tvasahi; - document.getElementById('crea_web').checked = items.crea_web; - document.getElementById('shin_R25').checked = items.shin_R25; - document.getElementById('word_BTS').checked = items.word_BTS; - document.getElementById('gendai_biz').checked = items.gendai_biz; - document.getElementById('gekisaka').checked = items.gekisaka; - document.getElementById('frau_tw').checked = items.frau_tw; - document.getElementById('tastyjapan').checked = items.tastyjapan; - document.getElementById('word_korea').checked = items.word_korea; - document.getElementById('word_china').checked = items.word_china; - document.getElementById('nhk_news').checked = items.nhk_news; - document.getElementById('sankeibiz').checked = items.sankeibiz; - document.getElementById('mute_level_hard').checked = items.mute_level_hard; - document.getElementById('word_birthday').checked = items.word_birthday; - document.getElementById('auto_scroll_by_1').checked = items.auto_scroll_by_1; - document.getElementById('GINZA_magazine').checked = items.GINZA_magazine; - document.getElementById('BIJapan').checked = items.BIJapan; - document.getElementById('mamadaystv').checked = items.mamadaystv; - document.getElementById('ntvnewszero').checked = items.ntvnewszero; - document.getElementById('japanacademy').checked = items.japanacademy; - document.getElementById('ld_blogos').checked = items.ld_blogos; - document.getElementById('modelpress').checked = items.modelpress; - document.getElementById('oricon').checked = items.oricon; - document.getElementById('trend_covid19').checked = items.trend_covid19; - document.getElementById('news_mynavi_jp').checked = items.news_mynavi_jp; - document.getElementById('mimollet2015').checked = items.mimollet2015; - document.getElementById('bizble_asahi').checked = items.bizble_asahi; - document.getElementById('mode_overseas').checked = items.mode_overseas; + MUTE_LIST.forEach((data) => { + generateCheckboxes(data); + }); + var defaultValues = MUTE_LIST.reduce((result, current) => { + result[current.id] = current.default_value; + return result; + }, { freeword: [] }); + chrome.storage.sync.get(defaultValues, (data) => { + MUTE_LIST.forEach((current) => { + let checkbox = document.getElementById(current.id); + if (checkbox) { + checkbox.checked = data[current.id]; + } + }); + + let freeword = document.getElementById('freeword_area'); + if (freeword) { + freeword.value = data.freeword.join('\n'); + } }); }