Skip to content

Commit

Permalink
feature: add prefix settings
Browse files Browse the repository at this point in the history
  • Loading branch information
takayamaki committed Sep 15, 2018
1 parent 6866426 commit 8a3a5b4
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
function onClicked(tab) {
var prefix = ' » '
const getSettings = (params) => {
return new Promise( (resolve) => {
chrome.storage.sync.get(params, (settings) => {
resolve(settings);
});
});
}

const onClicked = async(tab) => {
const settings = await getSettings({
prefix: ' \u00BB ',
});

var url = 'https://twitter.com/intent/tweet?'
+ 'text=' + encodeURIComponent(prefix) + encodeURIComponent(tab.title)
+ 'text=' + encodeURIComponent(settings.prefix) + encodeURIComponent(tab.title)
+ '&url=' + encodeURIComponent(tab.url);
var w = 640;
var h = 360;
Expand Down
5 changes: 5 additions & 0 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
"persistent": false,
"scripts": [ "background.js" ]
},
"options_ui": {
"page": "settings/settings.html",
"open_in_tab": false
},
"permissions": [
"storage",
"tabs"
]
}
12 changes: 12 additions & 0 deletions src/settings/settings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head><title>Just Tweet Settings</title></head>
<body>
prefix : <input type="text" id="prefix"/>

<div id="status"></div>
<button id="save">Save</button>

<script src="settings.js"></script>
</body>
</html>
25 changes: 25 additions & 0 deletions src/settings/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const save_options = () => {
const _prefix = document.getElementById('prefix').value;

chrome.storage.sync.set({
prefix: _prefix,
}, () => {
const status = document.getElementById('status');
status.textContent = 'saved!';
setTimeout( () => {
status.textContent = '';
}, 750);
}
);
}

const restore_options = () => {
chrome.storage.sync.get({
prefix: ' \u00BB '
}, (settings) => {
document.getElementById('prefix').value = settings.prefix;
});
}

document.addEventListener('DOMContentLoaded', restore_options);
document.getElementById('save').addEventListener('click',save_options);

0 comments on commit 8a3a5b4

Please sign in to comment.