Skip to content

Commit

Permalink
[Update] v4.2リリース
Browse files Browse the repository at this point in the history
  • Loading branch information
GenbuHase committed Jun 6, 2018
1 parent f117eb5 commit 5a4faf0
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 54 deletions.
3 changes: 2 additions & 1 deletion _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"setting_privacy_unlisted": { "message": "Unlisted" },
"setting_privacy_private": { "message": "Private" },
"setting_privacy_limited": { "message": "Limited(Only for implemented instances)" },
"setting_privacy_direct": { "message": "Direct" },
"setting_save": { "message": "Save the changes" },
"setting_close": { "message": "Discard this change and close" }
"setting_close": { "message": "Discard the changes" }
}
3 changes: 2 additions & 1 deletion _locales/ja/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"setting_privacy_unlisted": { "message": "未収載" },
"setting_privacy_private": { "message": "非公開" },
"setting_privacy_limited": { "message": "限定公開(※一部のインスタンスのみ)" },
"setting_privacy_direct": { "message": "ダイレクト" },
"setting_save": { "message": "変更を保存" },
"setting_close": { "message": "変更を破棄して閉じる" }
"setting_close": { "message": "変更を破棄" }
}
104 changes: 60 additions & 44 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,37 @@ const notifyListeningInfo = (tabId) => {
chrome.storage.local.get(["enabled"], items => {
const { enabled } = items;

if (enabled) {
(function looper (tabId) {
chrome.tabs.get(tabId, tabInfo => {
const { status, title, url } = tabInfo;

if (status === "loading") {
setTimeout(looper(tabId), 200);
return;
}

chrome.notifications.create(null, {
type: chrome.notifications.TemplateType.BASIC,

title,
message: url,
iconUrl: "icons/icon48.png"
});
if (!enabled) return;

(function looper (tabId) {
chrome.tabs.get(tabId, tabInfo => {
const { status, title, url } = tabInfo;

if (status === "loading") {
setTimeout(looper(tabId), 200);
return;
}

chrome.notifications.create(null, {
type: chrome.notifications.TemplateType.BASIC,

tootListeningInfo(title, url);
title,
message: url,
iconUrl: "icons/icon48.png"
}, currentId => {
chrome.notifications.onClicked.addListener(notificationId => {
if (notificationId === currentId) {
chrome.tabs.highlight({ windowId: tabInfo.windowId, tabs: tabInfo.index });
chrome.notifications.clear(currentId);
}

chrome.notifications.onClicked.removeListener(event);
});
});
})(tabId);
}

tootListeningInfo(title, url);
});
})(tabId);
});
};

Expand All @@ -58,33 +67,32 @@ const notifyListeningInfo = (tabId) => {
const tootListeningInfo = (title, url) => {
chrome.storage.local.get(["enabled", "instance", "token", "privacy"], items => {
const { enabled, instance, token, privacy } = items;


if (!enabled) return;
if (!instance) throw new TypeError("A config, 'instance' is invalid.");
if (!token) throw new TypeError("A config, 'token' is invalid.");
if (!privacy) throw new TypeError("A config, 'privacy' is invalid.");

if (enabled) {
return fetch(`${instance}/api/v1/statuses`, {
method: "POST",

headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`
},

body: JSON.stringify({
status: [
"#WhatYouarePlaying",
"Now playing🎶",
"",
`【${title}】`,
url
].join("\n"),

visibility: privacy
})
});
}
return fetch(`${instance}/api/v1/statuses`, {
method: "POST",

headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`
},

body: JSON.stringify({
status: [
"#WhatYouarePlaying",
"Now playing🎶",
"",
`【${title}】`,
url
].join("\n"),

visibility: privacy
})
});
});
};

Expand Down Expand Up @@ -159,4 +167,12 @@ chrome.webNavigation.onHistoryStateUpdated.addListener(
URLMatchers.YouTube
]
}
);
);

chrome.storage.local.get(["enabled", "instance", "token"], items => {
let { enabled } = items;
const { instance, token } = items;

if (!instance || !token) enabled = false;
chrome.browserAction.setBadgeText({ text: enabled ? "ON" : "OFF" });
});
6 changes: 3 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

"name": "What You're Playing",
"description": "__MSG_app_description__",
"version": "4.1",
"version_name": "v4.1",
"version": "4.2",
"version_name": "v4.2",
"default_locale": "en",

"icons": {
Expand Down Expand Up @@ -36,7 +36,7 @@
"128": "icons/icon128.png"
},

"default_title": "Settings | What You're Playing",
"default_title": "What You're Playing",
"default_popup": "views/settings/index.html"
},

Expand Down
8 changes: 6 additions & 2 deletions views/settings/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
<Header Class = "navbar-fixed">
<Nav>
<Div Class = "nav-wrapper">
<Span Class = "brand-logo center">What You're Playing</Span>
<Span Class = "brand-logo center">
<Img Class = "logo-icon" Src = "/icons/icon128.png" />
What You're Playing
</Span>

<UL Class = "right">
<Li Class = "switch">
Expand Down Expand Up @@ -52,6 +55,7 @@
<Option Name = "privacy.unlisted" Value = "unlisted" Locale-Message = "setting_privacy_unlisted">Unlisted</Option>
<Option Name = "privacy.private" Value = "private" Locale-Message = "setting_privacy_private">Private</Option>
<Option Name = "privacy.limited" Value = "limited" Locale-Message = "setting_privacy_limited">Limited(Only for implemented instances)</Option>
<Option Name = "privacy.direct" Value = "direct" Locale-Message = "setting_privacy_direct">Direct</Option>
</Select>

<Label Locale-Message = "setting_privacy">Privacy</Label>
Expand All @@ -65,7 +69,7 @@

<Button ID = "btns_close" Class = "btn red waves-effect waves-light">
<I Class = "material-icons left">close</I>
<Locale Message = "setting_close">Discard this change and close</Locale>
<Locale Message = "setting_close">Discard the changes</Locale>
</Button>
</Div>
</Main>
Expand Down
5 changes: 5 additions & 0 deletions views/settings/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@

Main {
Padding: 1rem;
}

.logo-icon {
Height: 1em;
Vertical-Align: Middle;
}
9 changes: 6 additions & 3 deletions views/settings/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ window.addEventListener("DOMContentLoaded", () => {
});

enabledSwitch.addEventListener("change", event => {
chrome.storage.local.set({
enabled: event.target.checked
});
const enabled = event.target.checked;

chrome.storage.local.set({ enabled });
chrome.browserAction.setBadgeText({ text: enabled ? "ON" : "OFF" });
});

saveBtn.addEventListener("click", () => {
Expand All @@ -32,6 +33,8 @@ window.addEventListener("DOMContentLoaded", () => {
token: tokenInputter.value,
privacy: pricacySelector.value
});

window.close();
});

closeBtn.addEventListener("click", () => {
Expand Down

0 comments on commit 5a4faf0

Please sign in to comment.