Skip to content

Commit

Permalink
✨ 秘匿情報を設定画面から設定できるようにして公開
Browse files Browse the repository at this point in the history
  • Loading branch information
windyakin committed Jun 6, 2021
1 parent 99ec910 commit b2945bc
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 0 deletions.
Binary file added icons/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions icons/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/icon48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/icon96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"manifest_version": 2,
"name": "かんかんみかん",
"version": "1.1.0",
"description": "TwitterのURLをWebhookに送信します",
"applications": {
"gecko": {
"id": "[email protected]"
}
},
"icons": {
"48": "icons/icon48.png",
"96": "icons/icon96.png"
},
"permissions": [
"contextMenus",
"storage"
],
"options_ui": {
"page": "options.html"
},
"background": {
"scripts": [
"mikan.js"
]
}
}
30 changes: 30 additions & 0 deletions mikan.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function postRequest(url, data) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open('POST', url);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.addEventListener('load', () => resolve(xhr));
xhr.addEventListener('error', () => reject(xhr));
xhr.send(JSON.stringify(data));
});
}


(async () => {
const pattern = new RegExp('^(https://twitter.com/(i/web|[a-zA-Z0-9_]+)/status/[0-9]+)', 'i');

browser.contextMenus.create({
type: 'normal',
title: 'リンクを koresuki に送信する',
contexts: ['link'],
onclick: async (info) => {
if (pattern.test(info.linkUrl)) {
const tweetLink = info.linkUrl.replace(pattern, '$1');
const setting = await browser.storage.sync.get(["url", "username"]);
await postRequest(setting.url, {
command: '/koresuki', user_name: setting.username, text: tweetLink
});
}
}
});
})();
26 changes: 26 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body { padding: 1rem 0; }
label { display: block; margin-bottom: 1rem; }
label > strong { display: block; margin-bottom: 0.3rem; }
label > input[type="text"] { display: block; width: 100%; }
</style>
</head>
<body>
<form>
<label>
<strong>Webhook URL</strong>
<input type="text" id="url" />
</label>
<label>
<strong>Username</strong>
<input type="text" id="username" />
</label>
<button type="submit">Save</button>
</form>
<script src="options.js"></script>
</body>
</html>
24 changes: 24 additions & 0 deletions options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function saveOptions(ev) {
ev.preventDefault();
browser.storage.sync.set({
url: document.getElementById("url").value,
username: document.getElementById("username").value
});
}

function setCurrentInput(result) {
document.getElementById("url").value = result.url || "";
document.getElementById("username").value = result.username || "";
}

function onError(error) {
console.log(`Error: ${error}`);
}

function restoreOptions() {
const getting = browser.storage.sync.get(["url", "username"]);
getting.then(setCurrentInput, onError);
}

document.addEventListener("DOMContentLoaded", restoreOptions);
document.querySelector("form").addEventListener("submit", saveOptions);

0 comments on commit b2945bc

Please sign in to comment.