Skip to content

Commit

Permalink
Moved functions out of inline script nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
proginosko committed Aug 8, 2016
1 parent 268aafb commit eff4be8
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 92 deletions.
27 changes: 27 additions & 0 deletions chrome/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,33 @@ LeechBlock.openLockdownDialog = function () {
"leechblock-lockdown", "chrome,centerscreen");
}

// Shows alert dialog with block warning
//
LeechBlock.alertBlockWarning = function (set, setName, secsLeft) {
if (setName == "") {
setName = LeechBlock.locale_blockSet + " " + set;
}
LeechBlock.PROMPTS.alert(null,
LeechBlock.locale_warning_title,
LeechBlock.locale_warning_alertBlock
.replace(/\$B/, setName)
.replace(/\$S/, secsLeft));
}

// Returns label for item for add site menu
//
LeechBlock.getAddSiteMenuItemLabel = function (site, set, setName) {
if (setName != "") {
return LeechBlock.locale_menu_addThisSiteLabel
.replace(/\$S/, site)
.replace(/\$B/, setName);
} else {
return LeechBlock.locale_menu_addThisSiteLabel
.replace(/\$S/, site)
.replace(/\$B/, LeechBlock.locale_blockSet + " " + set);
}
}

// Prepares menu (either context menu or toolbar menu)
//
LeechBlock.prepareMenu = function (menu, win) {
Expand Down
20 changes: 4 additions & 16 deletions chrome/content/browser.xul
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,10 @@
<script type="application/x-javascript" src="browser.js"/>
<script type="application/x-javascript">

LeechBlock.alertBlockWarning = function (set, setName, secsLeft) {
if (setName == "") {
setName = "&blockSet; " + set;
}
LeechBlock.PROMPTS.alert(null,
"&warning.title;",
"&warning.alertBlock;".replace(/\$B/, setName).replace(/\$S/, secsLeft));
}

LeechBlock.getAddSiteMenuItemLabel = function (site, set, setName) {
if (setName != "") {
return "&menu.addThisSiteLabel;".replace(/\$S/, site).replace(/\$B/, setName);
} else {
return "&menu.addThisSiteLabel;".replace(/\$S/, site).replace(/\$B/, "&blockSet; " + set);
}
}
LeechBlock.locale_blockSet = "&blockSet;";
LeechBlock.locale_warning_title = "&warning.title;";
LeechBlock.locale_warning_alertBlock = "&warning.alertBlock;";
LeechBlock.locale_menu_addThisSiteLabel = "&menu.addThisSiteLabel;";

</script>

Expand Down
21 changes: 20 additions & 1 deletion chrome/content/lockdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ LeechBlock.lockdownInit = function () {
let lockdown = (sets & (1 << (set - 1))) != 0;
document.getElementById("lb-lockdown-set" + set).checked = lockdown;
document.getElementById("lb-lockdown-set" + set).label += " "
+ LeechBlock.getLockdownBlockSetLabel(set);
+ LeechBlock.getBlockSetName(set);
}
}

Expand Down Expand Up @@ -91,3 +91,22 @@ LeechBlock.lockdownOK = function () {
LeechBlock.lockdownCancel = function () {
return true;
}

// Shows alert dialog with end time
//
LeechBlock.alertLockdown = function (endTime) {
LeechBlock.PROMPTS.alert(null,
LeechBlock.locale_lockdown_title,
LeechBlock.locale_lockdown_alertLockdown + " " + endTime);
}

// Returns name of block set
//
LeechBlock.getBlockSetName = function (set) {
let setName = LeechBlock.getUniCharPref("setName" + set);
if (setName != "") {
return setName;
} else {
return LeechBlock.locale_blockSet + " " + set;
}
}
17 changes: 3 additions & 14 deletions chrome/content/lockdown.xul
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,9 @@
<script type="application/x-javascript" src="lockdown.js"/>
<script type="application/x-javascript">

LeechBlock.alertLockdown = function (endTime) {
LeechBlock.PROMPTS.alert(null,
"&lockdown.title;",
"&lockdown.alertLockdown; " + endTime);
}

LeechBlock.getLockdownBlockSetLabel = function (set) {
let setName = LeechBlock.getUniCharPref("setName" + set);
if (setName != "") {
return setName;
} else {
return "&blockSet; " + set;
}
}
LeechBlock.locale_blockSet = "&blockSet;";
LeechBlock.locale_lockdown_title = "&lockdown.title;";
LeechBlock.locale_lockdown_alertLockdown = "&lockdown.alertLockdown;";

</script>

Expand Down
70 changes: 70 additions & 0 deletions chrome/content/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -751,3 +751,73 @@ LeechBlock.importOptions = function () {
}
LeechBlock.updatePasswordOptions();
}

// Shows alert dialog for bad time periods entry
//
LeechBlock.alertBadTimes = function () {
LeechBlock.PROMPTS.alert(null,
LeechBlock.locale_options_title,
LeechBlock.locale_options_alertBadTimes);
}

// Shows alert dialog for bad time limit entry
//
LeechBlock.alertBadTimeLimit = function () {
LeechBlock.PROMPTS.alert(null,
LeechBlock.locale_options_title,
LeechBlock.locale_options_alertBadTimeLimit);
}

// Shows alert dialog for bad seconds entry
//
LeechBlock.alertBadSeconds = function () {
LeechBlock.PROMPTS.alert(null,
LeechBlock.locale_options_title,
LeechBlock.locale_options_alertBadSeconds);
}

// Shows confirmation dialog for preventing access to options all day
//
LeechBlock.confirmPrevOptsAllDay = function () {
let check = {value: false};
let flags =
LeechBlock.PROMPTS.BUTTON_POS_0 * LeechBlock.PROMPTS.BUTTON_TITLE_YES +
LeechBlock.PROMPTS.BUTTON_POS_1 * LeechBlock.PROMPTS.BUTTON_TITLE_NO;
let button = LeechBlock.PROMPTS.confirmEx(null,
LeechBlock.locale_options_title,
LeechBlock.locale_options_confPrevOptsAllDay,
flags, "", "", "", null, check);
return (button == 0);
}

// Shows confirmation dialog for canceling lockdown
//
LeechBlock.confirmCancelLockdown = function () {
let check = {value: false};
let flags =
LeechBlock.PROMPTS.BUTTON_POS_0 * LeechBlock.PROMPTS.BUTTON_TITLE_YES +
LeechBlock.PROMPTS.BUTTON_POS_1 * LeechBlock.PROMPTS.BUTTON_TITLE_NO;
let button = LeechBlock.PROMPTS.confirmEx(null,
LeechBlock.locale_options_title,
LeechBlock.locale_options_confCancelLockdown,
flags, "", "", "", null, check);
return (button == 0);
}

// Shows prompt dialog for password
//
LeechBlock.requestPassword = function (hide) {
let userpassword = {}, check = {};
if (hide) {
LeechBlock.PROMPTS.promptPassword(null,
LeechBlock.locale_options_title,
LeechBlock.locale_options_passwordPrompt,
userpassword, null, check);
} else {
LeechBlock.PROMPTS.prompt(null,
LeechBlock.locale_options_title,
LeechBlock.locale_options_passwordPrompt,
userpassword, null, check);
}
return userpassword.value;
}
64 changes: 7 additions & 57 deletions chrome/content/options.xul
Original file line number Diff line number Diff line change
Expand Up @@ -15,63 +15,13 @@
<script type="application/x-javascript" src="options.js"/>
<script type="application/x-javascript">

LeechBlock.alertBadTimes = function () {
LeechBlock.PROMPTS.alert(null,
"&options.title;",
"&options.alertBadTimes;");
}

LeechBlock.alertBadTimeLimit = function () {
LeechBlock.PROMPTS.alert(null,
"&options.title;",
"&options.alertBadTimeLimit;");
}

LeechBlock.alertBadSeconds = function () {
LeechBlock.PROMPTS.alert(null,
"&options.title;",
"&options.alertBadSeconds;");
}

LeechBlock.confirmPrevOptsAllDay = function () {
let check = {value: false};
let flags =
LeechBlock.PROMPTS.BUTTON_POS_0 * LeechBlock.PROMPTS.BUTTON_TITLE_YES +
LeechBlock.PROMPTS.BUTTON_POS_1 * LeechBlock.PROMPTS.BUTTON_TITLE_NO;
let button = LeechBlock.PROMPTS.confirmEx(null,
"&options.title;",
"&options.confPrevOptsAllDay;",
flags, "", "", "", null, check);
return (button == 0);
}

LeechBlock.confirmCancelLockdown = function () {
let check = {value: false};
let flags =
LeechBlock.PROMPTS.BUTTON_POS_0 * LeechBlock.PROMPTS.BUTTON_TITLE_YES +
LeechBlock.PROMPTS.BUTTON_POS_1 * LeechBlock.PROMPTS.BUTTON_TITLE_NO;
let button = LeechBlock.PROMPTS.confirmEx(null,
"&options.title;",
"&options.confCancelLockdown;",
flags, "", "", "", null, check);
return (button == 0);
}

LeechBlock.requestPassword = function (hide) {
let userpassword = {}, check = {};
if (hide) {
LeechBlock.PROMPTS.promptPassword(null,
"&options.title;",
"&options.passwordPrompt;",
userpassword, null, check);
} else {
LeechBlock.PROMPTS.prompt(null,
"&options.title;",
"&options.passwordPrompt;",
userpassword, null, check);
}
return userpassword.value;
}
LeechBlock.locale_options_title = "&options.title;";
LeechBlock.locale_options_alertBadTimes = "&options.alertBadTimes;";
LeechBlock.locale_options_alertBadTimeLimit = "&options.alertBadTimeLimit;";
LeechBlock.locale_options_alertBadSeconds = "&options.alertBadSeconds;";
LeechBlock.locale_options_confPrevOptsAllDay = "&options.confPrevOptsAllDay;";
LeechBlock.locale_options_confCancelLockdown = "&options.confCancelLockdown;";
LeechBlock.locale_options_passwordPrompt = "&options.passwordPrompt;";

</script>

Expand Down
2 changes: 1 addition & 1 deletion chrome/content/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ LeechBlock.statsRefresh = function () {

// Update block set name
if (setName == "") {
setName = LeechBlock.getDefaultSetName(set);
setName = LeechBlock.locale_blockSet + " " + set;
}
document.getElementById("lb-set-name" + set).value = setName;

Expand Down
4 changes: 1 addition & 3 deletions chrome/content/stats.xul
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
<script type="application/x-javascript" src="stats.js"/>
<script type="application/x-javascript">

LeechBlock.getDefaultSetName = function (set) {
return ("&blockSet; " + set);
}
LeechBlock.locale_blockSet = "&blockSet;";

</script>

Expand Down

0 comments on commit eff4be8

Please sign in to comment.