Skip to content

Commit

Permalink
Merge pull request #3 from 53JIlLenWe11/fix/eslint_and_code
Browse files Browse the repository at this point in the history
Fix/eslint and code
  • Loading branch information
ten9miq authored Oct 12, 2019
2 parents cb9cb1f + a2b79ed commit 56c208e
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 43 deletions.
20 changes: 20 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"env": {
"browser": true,
"jquery": true,
"es6": true,
"webextensions": true
},
"parserOptions": {
"sourceType": "module", // ES Moduleを有効にする
"ecmaVersion": 2018 // async functionに対してparse error吐くので最新の記載に対応
},
"extends": [
"eslint:recommended", // ESLintが推奨するチェック項目でまとめてチェックする
"plugin:prettier/recommended" // ESLintでPrettierを実施し、ESLintと衝突ルールは回避する設定を有効にする
// デフォルトで.prettierrcの設定を読み込む
],
"rules": {
"no-console": 1 // consoleを警告する 2はエラーとする
}
}
15 changes: 0 additions & 15 deletions .eslintrc.json

This file was deleted.

3 changes: 1 addition & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
"singleQuote": true,
"semi": true,
"printWidth": 120,
"trailingComma": "all",
"trailingCommaPHP":"php5"
"trailingComma": "es5"
}
57 changes: 32 additions & 25 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ setInterval(function() {

function view_new_mail_count() {
(async () => {
let mail_count = await get_mail_count();
let mail_count = await mail_count_fetch_process();
console.log('mail_count', mail_count);

if (mail_count == 0) {
Expand All @@ -32,27 +32,29 @@ async function set_eappid() {
await connecter.get_method();
const text = await connecter.get_text();

const patterns = [
/eappid\u0022:\u0022(.+?)\u0022,\u0022/,
/eappid\\u0022:\\u0022(.+?)\\u0022,\\u0022/,
];
const patterns = [/eappid\u0022:\u0022(.+?)\u0022,\u0022/, /eappid\\u0022:\\u0022(.+?)\\u0022,\\u0022/];
let page_eappid = null;
for ( let pattern of patterns ) {
for (const pattern of patterns) {
page_eappid = text.match(pattern);
if ( page_eappid !== null ) {
if (page_eappid !== null) {
break;
}
}
console.log('取得したeappid', page_eappid);
if (page_eappid !== null) {
chrome.storage.local.set({ eappid: page_eappid[1] }, () => {});
chrome.storage.local.set(
{
eappid: page_eappid[1],
},
() => {}
);
return page_eappid[1];
}
} catch (error) {
console.log(error);
clear_eappid();
return null;
}
clear_eappid();
return null;
}

async function get_eappid() {
Expand All @@ -61,7 +63,12 @@ async function get_eappid() {
}

function clear_eappid() {
chrome.storage.local.set({ eappid: null }, () => {});
chrome.storage.local.set(
{
eappid: null,
},
() => {}
);
}

async function is_login() {
Expand All @@ -78,15 +85,15 @@ async function is_login() {
// - ID新規作成リンク: https://account.edit.yahoo.co.jp/registration?...
// - 登録情報: https://login.yahoo.co.jp/config/login?...
const a_in_login_box = html.querySelectorAll('#Login a');
for ( a of a_in_login_box ) {
if ( a.href.match(/^https:\/\/accounts.yahoo.co.jp\/profile\?/) ) {
for (const a of a_in_login_box) {
if (a.href.match(/^https:\/\/accounts.yahoo.co.jp\/profile\?/)) {
return true;
}
}
return false;
}

async function get_mail_count_core(eappid) {
async function get_mail_count(eappid) {
const connecter = new api_connecter(new_mail_count_url + eappid);
await connecter.get_method();
const json = await connecter.get_json();
Expand All @@ -96,40 +103,40 @@ async function get_mail_count_core(eappid) {

// すでに取得済みの eappid でメール件数の取得を試みる。
// ダメなら get_mail_count2 へ。
async function get_mail_count() {
async function mail_count_fetch_process() {
try {
const eappid = await get_eappid();
if ( eappid ) {
if (eappid) {
try {
return await get_mail_count_core(eappid);
return await get_mail_count(eappid);
} catch (error) {
return await get_mail_count2();
return await eaapid_reacquisition_after_get_mail_count();
}
} else {
return await get_mail_count2();
return await eaapid_reacquisition_after_get_mail_count();
}
} catch (error) {
console.log(error);
return 0;
return '-';
}
}

// ログイン判定、eaippidの取得をした後にメール件数の取得を試みる。
async function get_mail_count2() {
async function eaapid_reacquisition_after_get_mail_count() {
try {
if (!(await is_login())) {
// ログインしていない
clear_eappid();
return 'login';
}
const eappid = await set_eappid();
if ( ! eappid ) {
return 0;
if (!eappid) {
return '-';
}
return await get_mail_count_core(eappid);
return await get_mail_count(eappid);
} catch (error) {
console.log(error);
return 0;
return '-';
}
}

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ヤフーメール通知",
"version": "0.9",
"version": "0.10",
"manifest_version": 2,
"description": "ヤフーメール通知拡張 30秒に一度自動で確認 ログインしておく必要があります。",
"permissions": [
Expand Down

0 comments on commit 56c208e

Please sign in to comment.