forked from proginosko/LeechBlockNG
-
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
1 parent
122ee42
commit adc8199
Showing
6 changed files
with
271 additions
and
5 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,93 @@ | ||
<!DOCTYPE html> | ||
|
||
<html lang="us"> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<title>LeechBlock Lockdown</title> | ||
<link href="jquery-ui/jquery-ui.min.css" rel="stylesheet"> | ||
<link href="options.css" rel="stylesheet"> | ||
<link href="icons/leechblock16.ico" rel="icon" type="image/x-icon"> | ||
<link href="icons/leechblock16.ico" rel="shortcut icon" type="image/x-icon"> | ||
</head> | ||
|
||
<body> | ||
|
||
<div id="form-container"> | ||
|
||
<form id="form" style="display: none;"> | ||
|
||
<fieldset class="ui-widget ui-widget-content"> | ||
<legend>Lockdown Options</legend> | ||
<p> | ||
<label>Enter the duration of the lockdown:</label><br> | ||
<div> | ||
<input id="hours" type="text" size="2" list="hours-list"> | ||
<datalist id="hours-list"> | ||
<option value="0"> | ||
<option value="1"> | ||
<option value="2"> | ||
<option value="3"> | ||
<option value="4"> | ||
<option value="5"> | ||
<option value="6"> | ||
<option value="12"> | ||
<option value="18"> | ||
<option value="24"> | ||
</datalist> | ||
<label for="hours">hour(s)</label> | ||
<input id="mins" type="text" size="2" list="mins-list"> | ||
<datalist id="mins-list"> | ||
<option value="0"> | ||
<option value="5"> | ||
<option value="10"> | ||
<option value="15"> | ||
<option value="20"> | ||
<option value="25"> | ||
<option value="30"> | ||
<option value="35"> | ||
<option value="40"> | ||
<option value="45"> | ||
<option value="50"> | ||
<option value="55"> | ||
</datalist> | ||
<label for="mins">minute(s)</label> | ||
</div> | ||
</p> | ||
<hr> | ||
<p> | ||
<label>Select the sites to block during the lockdown:</label><br> | ||
<div id="sites"> | ||
<p> | ||
<input id="site1" type="checkbox"><label id="siteLabel1" for="site1">Sites specified in Block Set 1</label> | ||
</p> | ||
</div> | ||
</p> | ||
</fieldset> | ||
|
||
<p style="text-align: center;"> | ||
<button id="activate" type="button">Activate Lockdown</button> | ||
<button id="cancel" type="button">Cancel</button> | ||
</p> | ||
|
||
</form> | ||
|
||
</div> | ||
|
||
<div id="alerts" style="display: none;"> | ||
<div id="alertNoDuration" title="LeechBlock Lockdown"> | ||
<p>Please enter the duration of the lockdown.</p> | ||
</div> | ||
<div id="alertNoSets" title="LeechBlock Lockdown"> | ||
<p>Please select the sites to lockdown.</p> | ||
</div> | ||
</div> | ||
|
||
<script src="jquery-ui/external/jquery/jquery.js"></script> | ||
<script src="jquery-ui/jquery-ui.min.js"></script> | ||
<script src="common.js"></script> | ||
<script src="lockdown.js"></script> | ||
|
||
</body> | ||
|
||
</html> |
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,110 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
function log(message) { console.log("[LBNG] " + message); } | ||
function warn(message) { console.warn("[LBNG] " + message); } | ||
|
||
// Initializes form | ||
// | ||
function initializeForm() { | ||
//log("initializeForm"); | ||
|
||
browser.storage.local.get().then(onGot, onError); | ||
|
||
function onGot(options) { | ||
for (let set = 1; set <= NUM_SETS; set++) { | ||
// Append custom set name to check box label (if specified) | ||
let setName = options[`setName${set}`]; | ||
if (setName) { | ||
document.querySelector(`#siteLabel${set}`).innerText += ` (${setName})`; | ||
} | ||
} | ||
} | ||
|
||
function onError(error) { | ||
warn("Cannot get options: " + error); | ||
} | ||
} | ||
|
||
// Handles activate button click | ||
// | ||
function onActivate() { | ||
//log("onActivate"); | ||
|
||
// Get lockdown duration | ||
let hours = document.querySelector("#hours").value; | ||
let mins = document.querySelector("#mins").value; | ||
let duration = hours * 3600 + mins * 60; | ||
|
||
if (!duration) { | ||
$("#alertNoDuration").dialog("open"); | ||
return; | ||
} | ||
|
||
// Calculate end time for lockdown | ||
let endTime = Math.floor(Date.now() / 1000) + duration; | ||
|
||
// Request lockdown for each selected set | ||
let noneSelected = true; | ||
for (let set = 1; set <= NUM_SETS; set++) { | ||
let selected = document.querySelector(`#site${set}`).checked; | ||
if (selected) { | ||
noneSelected = false; | ||
let message = { | ||
type: "lockdown", | ||
endTime: endTime, | ||
set: set | ||
}; | ||
// Request lockdown for this set | ||
browser.runtime.sendMessage(message); | ||
} | ||
} | ||
|
||
if (noneSelected) { | ||
$("#alertNoSets").dialog("open"); | ||
return; | ||
} | ||
|
||
// Request tab close | ||
browser.runtime.sendMessage({ type: "close" }); | ||
} | ||
|
||
// Handles cancel button click | ||
// | ||
function onCancel() { | ||
//log("onCancel"); | ||
|
||
// Request tab close | ||
browser.runtime.sendMessage({ type: "close" }); | ||
} | ||
|
||
// Use HTML for first check box to create other check boxes | ||
let siteHTML = $("#sites").html(); | ||
for (let set = 2; set <= NUM_SETS; set++) { | ||
let nextSiteHTML = siteHTML | ||
.replace(/Block Set 1/g, `Block Set ${set}`) | ||
.replace(/(id|for)="(\w+)1"/g, `$1="$2${set}"`); | ||
$("#sites").append(nextSiteHTML); | ||
} | ||
|
||
// Set up JQuery UI widgets | ||
$("#activate").button(); | ||
$("#activate").click(onActivate); | ||
$("#cancel").button(); | ||
$("#cancel").click(onCancel); | ||
|
||
let alerts = ["alertNoDuration", "alertNoSets"]; | ||
for (let alert of alerts) { | ||
$(`#${alert}`).dialog({ | ||
autoOpen: false, | ||
modal: true, | ||
buttons: { | ||
OK: function() { $(this).dialog("close"); } | ||
} | ||
}); | ||
} | ||
|
||
$("#form").show(); | ||
|
||
document.addEventListener("DOMContentLoaded", initializeForm); |
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 |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
|
||
"permissions": [ | ||
"alarms", | ||
"menus", | ||
"storage", | ||
"tabs", | ||
"webNavigation" | ||
|
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