Skip to content

Commit

Permalink
バグ修正・コード最適化
Browse files Browse the repository at this point in the history
  • Loading branch information
GenbuHase committed Jun 17, 2018
1 parent 1327e24 commit 28ccf5d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
18 changes: 12 additions & 6 deletions views/lib/Instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,20 @@ class Instance {
* @param {String} url
*/
constructor (url) {
if (!url) throw new URIError("An argument, 'url' is required.");

//Throws error if provided url isn't absolutely one
new URL(url);
try {
if (url) new URL(url);
} catch (error) {
throw new URIError("An argument, 'url' must be absolutely formed.");
}

this.url = url;
Instance.detectType(url).then(type => this.type = type);
chrome.storage.local.get("token", items => Object.assign(this, items));
chrome.storage.local.get("token", items => this.token = items.token || "");

if (!url) {
this.type = "None";
} else {
Instance.detectType(url).then(type => this.type = type);
}
}

/**
Expand Down
13 changes: 12 additions & 1 deletion views/settings/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const throwError = errorKey => {
* @param {String} type
*/
const changeVisibilities = type => {
if (Instance.Type[type]) {
if (type && type !== Instance.Type.None && Instance.Type[type]) {
while (visibilitySelector.options.length > 0) visibilitySelector.options.remove(0);

for (let name of Instance.Visibility[type]) {
Expand Down Expand Up @@ -78,6 +78,17 @@ window.addEventListener("DOMContentLoaded", () => {
});

saveBtn.addEventListener("click", () => {
if (!instanceInputter.value) {
chrome.storage.local.set({
type: "None",
instance: "",
token: tokenInputter.value,
visibility: ""
});

return;
}

const instance = new Instance(instanceInputter.value);

instance.on("init", () => {
Expand Down

0 comments on commit 28ccf5d

Please sign in to comment.