-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
112 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"manifest_version": 3, | ||
"background": { | ||
"service_worker": "service_worker/index.js" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
{ | ||
"browser_specific_settings": { | ||
"gecko": { | ||
"id": "mikan@example.com" | ||
"id": "kankan-mikan@napple.team" | ||
} | ||
}, | ||
"background": { | ||
"scripts": [ | ||
"background/index.js" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,10 +14,5 @@ | |
], | ||
"options_ui": { | ||
"page": "option/index.html" | ||
}, | ||
"background": { | ||
"scripts": [ | ||
"background/index.js" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import browser from 'webextension-polyfill'; | ||
import { Post as PostBase } from '../lib/post'; | ||
|
||
class Post extends PostBase { | ||
constructor() { | ||
super(); | ||
} | ||
|
||
async submit(url: string) { | ||
await fetch( | ||
this.postUrl, | ||
{ | ||
method: 'POST', | ||
body: this.generate(url), | ||
headers: { 'Content-Type': this.contentType } | ||
} | ||
); | ||
} | ||
} | ||
|
||
const post: Post = new Post(); | ||
|
||
(async () => { | ||
await post.sync(); | ||
})(); | ||
|
||
const notification = async (message: string) => { | ||
await browser.notifications.create(`kankan-mikan-${new Date().getTime()}`, { | ||
type: 'basic', | ||
title: 'kankan-mikan', | ||
iconUrl: 'icons/icon.png', | ||
message | ||
}); | ||
}; | ||
|
||
browser.contextMenus.create({ | ||
id: 'kankan-mikan', | ||
type: 'normal', | ||
title: 'Post url with kankan-mikan', | ||
contexts: ['link'], | ||
}); | ||
|
||
browser.contextMenus.onClicked.addListener(async (info) => { | ||
if (!post.isStandby) await notification('Please setup') | ||
try { | ||
if (info.linkUrl && (post.isFilteredUrl() || post.validate(info.linkUrl))) { | ||
await post.submit(info.linkUrl); | ||
await notification('Posted!'); | ||
} else { | ||
await notification('Invalid url'); | ||
} | ||
} catch (err: any) { | ||
await notification(`${err}`); | ||
} | ||
}); | ||
|
||
browser.runtime.onMessage.addListener(async (message, sender) => { | ||
if (sender.id === browser.runtime.id) { | ||
switch (message.cmd) { | ||
case 'configures/save': | ||
post.postUrl = message.postUrl; | ||
post.template = message.template; | ||
post.contentType = message.contentType; | ||
post.regexp = message.regexp; | ||
await post.save(); | ||
break; | ||
case 'configures/get': | ||
return Promise.resolve(post.get()); | ||
} | ||
} | ||
}); |