Skip to content

Commit

Permalink
ui: add options ui for auto-forwarding
Browse files Browse the repository at this point in the history
now we can auto forward to official web PTT
  • Loading branch information
walkingice committed Jan 3, 2018
1 parent 19d7b82 commit 6d77f80
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
14 changes: 13 additions & 1 deletion js/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(() => {
const INTERVAL = 250; // 0.25 second
const TIMEOUT = 5000; // 5 seconds

const OPTIONS_AUTO_ENABLED = 'enabled_auto_forward';

function searchUrlFromDisp() {
let doms = document.getElementsByClassName("record");
Expand All @@ -25,12 +25,24 @@
document.body.append(div);
}

function onUrlFound(url) {
browser.storage.local.get(OPTIONS_AUTO_ENABLED).then((result)=>{
if (!result[OPTIONS_AUTO_ENABLED]) {
return;
}

// auto forward to web PTT
window.location.assign(url);
});
}

// keep trying to search PTT url
let interval = setInterval(() => {
let url = searchUrlFromDisp();
if (url) {
prependUrl(url);
clearInterval(interval);
onUrlFound(url);
}
}, INTERVAL);

Expand Down
5 changes: 4 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
"run_at": "document_start"
}
],
"permissions": ["tabs", "activeTab"]
"options_ui": {
"page": "options/options.html"
},
"permissions": ["tabs", "activeTab", "storage"]
}
10 changes: 10 additions & 0 deletions options/options.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<div><input id="checkbox_auto_forward" type="checkbox">Auto forward to web PTT</input></div>
<script type="text/javascript" src="./options.js"></script>
</body>
</html>
16 changes: 16 additions & 0 deletions options/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(() => {
const OPTIONS_AUTO_ENABLED = 'enabled_auto_forward';

let checkbox = document.getElementById('checkbox_auto_forward');

browser.storage.local.get(OPTIONS_AUTO_ENABLED).then((r) => {
checkbox.checked = !!r[OPTIONS_AUTO_ENABLED];

checkbox.addEventListener('change', () => {
var obj = {};
obj[OPTIONS_AUTO_ENABLED] = checkbox.checked;
browser.storage.local.set(obj);
});
});

})();

0 comments on commit 6d77f80

Please sign in to comment.