Skip to content

Commit

Permalink
Added option to delay first/every page of site
Browse files Browse the repository at this point in the history
Added option for user to choose whether every page or only first
accessed page of site is blocked when using delaying page.
  • Loading branch information
proginosko committed Jan 22, 2016
1 parent 42cc582 commit 6015667
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 21 deletions.
32 changes: 23 additions & 9 deletions chrome/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,16 @@ LeechBlock.onPageLoad = function (event) {
return;
}

// Clear preference for allowed host (unless this page is on allowed host)
if (/^http|file|about/.test(parsedURL.protocol)
&& (win.frameElement == null)
&& parsedURL.host != LeechBlock.getUniCharPref("ah")) {
LeechBlock.clearUserPref("ah");
// Clear preference for allowed origin/page if this is different origin/page
let ao = LeechBlock.getUniCharPref("ao");
let ap = LeechBlock.getUniCharPref("ap");
if (/^http|file|about/.test(parsedURL.protocol) && (win.frameElement == null)) {
if (parsedURL.origin != ao) {
LeechBlock.clearUserPref("ao");
}
if (parsedURL.page != ap) {
LeechBlock.clearUserPref("ap");
}
}

// Hide extension in about:addons (if option selected)
Expand Down Expand Up @@ -233,6 +238,7 @@ LeechBlock.onPageLoad = function (event) {
let countdown = {
win: win,
blockedURL: blockedURL,
blockedSet: blockedSet,
delaySecs: delaySecs
};
doc.leechblockCountdownInterval = setInterval(
Expand Down Expand Up @@ -288,8 +294,10 @@ LeechBlock.checkWindow = function (parsedURL, win, isRepeat) {
return;
}

// Quick exit for allowed host
if (parsedURL.host == LeechBlock.getUniCharPref("ah")) {
// Quick exit for allowed origin/page
let ao = LeechBlock.getUniCharPref("ao");
let ap = LeechBlock.getUniCharPref("ap");
if (parsedURL.origin == ao || parsedURL.page == ap) {
return;
}

Expand Down Expand Up @@ -785,8 +793,14 @@ LeechBlock.onCountdownTimer = function (countdown) {
// Get parsed URL for blocked page
let parsedURL = LeechBlock.getParsedURL(countdown.blockedURL);

// Set preference for allowed host
LeechBlock.setUniCharPref("ah", parsedURL.host);
// Set preference for allowed origin/page
if (LeechBlock.getBitPref("delayFirst", countdown.blockedSet)) {
LeechBlock.setUniCharPref("ao", parsedURL.origin);
LeechBlock.clearUserPref("ap");
} else {
LeechBlock.setUniCharPref("ap", parsedURL.page);
LeechBlock.clearUserPref("ao");
}

// Continue to blocked page
win.location = countdown.blockedURL;
Expand Down
19 changes: 11 additions & 8 deletions chrome/content/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,23 @@ LeechBlock.updatePreferences = function () {
// Returns parsed URL (page address, arguments, and hash)
//
LeechBlock.getParsedURL = function (url) {
const PARSE_URL = /^((\w+):\/*(\w+(?::\w+)?@)?([\w-\.]+)(?::(\d+))?([^\?#]*))(\?[^#]*)?(#.*)?$/;
const PARSE_URL = /^(((\w+):\/*(\w+(?::\w+)?@)?([\w-\.]+)(?::(\d*))?)([^\?#]*))(\?[^#]*)?(#.*)?$/;

let results = PARSE_URL.exec(url);
if (results != null) {
let page = results[1];
let protocol = results[2];
let userinfo = results[3];
let host = results[4];
let port = results[5];
let path = results[6];
let query = results[7];
let fragment = results[8];
let origin = results[2];
let protocol = results[3];
let userinfo = results[4];
let host = results[5];
let port = results[6];
let path = results[7];
let query = results[8];
let fragment = results[9];
return {
pageNoArgs: page,
page: (query == null) ? page : (page + query),
origin: origin,
protocol: protocol,
host: host,
path: path,
Expand All @@ -172,6 +174,7 @@ LeechBlock.getParsedURL = function (url) {
return {
pageNoArgs: null,
page: null,
origin: null,
protocol: null,
host: null,
path: null,
Expand Down
5 changes: 3 additions & 2 deletions chrome/content/lockdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ LeechBlock.lockdownOK = function () {
LeechBlock.setCharPref("timedata" + set, timedata.join(","));
}

// Clear preference for allowed host
LeechBlock.clearUserPref("ah");
// Clear preference for allowed origin/page
LeechBlock.clearUserPref("ao");
LeechBlock.clearUserPref("ap");

return true;
}
Expand Down
15 changes: 14 additions & 1 deletion chrome/content/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ LeechBlock.optionsInit = function () {
let prevAddons = LeechBlock.getBitPref("prevAddons", set);
let prevConfig = LeechBlock.getBitPref("prevConfig", set);
let countFocus = LeechBlock.getBitPref("countFocus", set);
let delayFirst = LeechBlock.getBitPref("delayFirst", set);
let delaySecs = LeechBlock.getCharPref("delaySecs" + set);
let times = LeechBlock.getCharPref("times" + set);
let limitMins = LeechBlock.getCharPref("limitMins" + set);
Expand All @@ -151,6 +152,7 @@ LeechBlock.optionsInit = function () {
document.getElementById("lb-prev-addons" + set).checked = prevAddons;
document.getElementById("lb-prev-config" + set).checked = prevConfig;
document.getElementById("lb-count-focus" + set).checked = countFocus;
document.getElementById("lb-delay-first" + set).checked = delayFirst;
document.getElementById("lb-delay-secs" + set).value = delaySecs;
document.getElementById("lb-times" + set).value = times;
document.getElementById("lb-limit-mins" + set).value = limitMins;
Expand Down Expand Up @@ -256,6 +258,7 @@ LeechBlock.optionsOK = function () {
let prevAddons = document.getElementById("lb-prev-addons" + set).checked;
let prevConfig = document.getElementById("lb-prev-config" + set).checked;
let countFocus = document.getElementById("lb-count-focus" + set).checked;
let delayFirst = document.getElementById("lb-delay-first" + set).checked;
let delaySecs = document.getElementById("lb-delay-secs" + set).value;
let times = document.getElementById("lb-times" + set).value;
let limitMins = document.getElementById("lb-limit-mins" + set).value;
Expand Down Expand Up @@ -289,6 +292,7 @@ LeechBlock.optionsOK = function () {
LeechBlock.setBitPref("prevAddons", set, prevAddons);
LeechBlock.setBitPref("prevConfig", set, prevConfig);
LeechBlock.setBitPref("countFocus", set, countFocus);
LeechBlock.setBitPref("delayFirst", set, delayFirst);
LeechBlock.setCharPref("delaySecs" + set, delaySecs);
LeechBlock.setUniCharPref("blockRE" + set, regexps.block);
LeechBlock.setUniCharPref("allowRE" + set, regexps.allow);
Expand Down Expand Up @@ -341,7 +345,7 @@ LeechBlock.optionsCancel = function () {
LeechBlock.disableSetOptions = function (set) {
let items = [
"sites", "sites-URL",
"active-block", "count-focus", "delay-secs",
"active-block", "count-focus", "delay-first", "delay-secs",
"times", "all-day",
"limit-mins", "limit-period", "mode",
"day0", "day1", "day2", "day3", "day4", "day5", "day6", "every-day",
Expand Down Expand Up @@ -479,6 +483,7 @@ LeechBlock.exportOptions = function () {
let prevAddons = document.getElementById("lb-prev-addons" + set).checked;
let prevConfig = document.getElementById("lb-prev-config" + set).checked;
let countFocus = document.getElementById("lb-count-focus" + set).checked;
let delayFirst = document.getElementById("lb-delay-first" + set).checked;
let delaySecs = document.getElementById("lb-delay-secs" + set).value;
let times = document.getElementById("lb-times" + set).value;
let limitMins = document.getElementById("lb-limit-mins" + set).value;
Expand All @@ -499,6 +504,7 @@ LeechBlock.exportOptions = function () {
text += "prevAddons" + set + "=" + prevAddons+ "\n";
text += "prevConfig" + set + "=" + prevConfig + "\n";
text += "countFocus" + set + "=" + countFocus + "\n";
text += "delayFirst" + set + "=" + delayFirst + "\n";
text += "delaySecs" + set + "=" + delaySecs + "\n";
text += "times" + set + "=" + times + "\n";
text += "limitMins" + set + "=" + limitMins + "\n";
Expand Down Expand Up @@ -591,6 +597,7 @@ LeechBlock.importOptions = function () {
let prevAddons = opts["prevAddons" + set];
let prevConfig = opts["prevConfig" + set];
let countFocus = opts["countFocus" + set];
let delayFirst = opts["delayFirst" + set];
let delaySecs = opts["delaySecs" + set];
let times = opts["times" + set];
let limitMins = opts["limitMins" + set]
Expand Down Expand Up @@ -649,6 +656,12 @@ LeechBlock.importOptions = function () {
element.checked = isTrue(countFocus);
}
}
if (delayFirst != undefined) {
let element = document.getElementById("lb-delay-first" + set);
if (!element.disabled) {
element.checked = isTrue(delayFirst);
}
}
if (delaySecs != undefined) {
let element = document.getElementById("lb-delay-secs" + set);
if (!element.disabled) {
Expand Down
30 changes: 30 additions & 0 deletions chrome/content/options.xul
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@
label="&options.countFocusLabel;"/>
<spacer flex="1"/>
</hbox>
<hbox align="center">
<checkbox id="lb-delay-first1"
label="&options.delayFirstLabel;"/>
<spacer flex="1"/>
</hbox>
<hbox align="center">
<description>&options.delaySecsDesc1;</description>
<textbox id="lb-delay-secs1" size="2"/>
Expand Down Expand Up @@ -475,6 +480,11 @@
label="&options.countFocusLabel;"/>
<spacer flex="1"/>
</hbox>
<hbox align="center">
<checkbox id="lb-delay-first2"
label="&options.delayFirstLabel;"/>
<spacer flex="1"/>
</hbox>
<hbox align="center">
<description>&options.delaySecsDesc1;</description>
<textbox id="lb-delay-secs2" size="2"/>
Expand Down Expand Up @@ -692,6 +702,11 @@
label="&options.countFocusLabel;"/>
<spacer flex="1"/>
</hbox>
<hbox align="center">
<checkbox id="lb-delay-first3"
label="&options.delayFirstLabel;"/>
<spacer flex="1"/>
</hbox>
<hbox align="center">
<description>&options.delaySecsDesc1;</description>
<textbox id="lb-delay-secs3" size="2"/>
Expand Down Expand Up @@ -909,6 +924,11 @@
label="&options.countFocusLabel;"/>
<spacer flex="1"/>
</hbox>
<hbox align="center">
<checkbox id="lb-delay-first4"
label="&options.delayFirstLabel;"/>
<spacer flex="1"/>
</hbox>
<hbox align="center">
<description>&options.delaySecsDesc1;</description>
<textbox id="lb-delay-secs4" size="2"/>
Expand Down Expand Up @@ -1126,6 +1146,11 @@
label="&options.countFocusLabel;"/>
<spacer flex="1"/>
</hbox>
<hbox align="center">
<checkbox id="lb-delay-first5"
label="&options.delayFirstLabel;"/>
<spacer flex="1"/>
</hbox>
<hbox align="center">
<description>&options.delaySecsDesc1;</description>
<textbox id="lb-delay-secs5" size="2"/>
Expand Down Expand Up @@ -1343,6 +1368,11 @@
label="&options.countFocusLabel;"/>
<spacer flex="1"/>
</hbox>
<hbox align="center">
<checkbox id="lb-delay-first6"
label="&options.delayFirstLabel;"/>
<spacer flex="1"/>
</hbox>
<hbox align="center">
<description>&options.delaySecsDesc1;</description>
<textbox id="lb-delay-secs6" size="2"/>
Expand Down
1 change: 1 addition & 0 deletions chrome/locale/cs-CZ/leechblock.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<!ENTITY options.homePageLabel "Domovská stránka">
<!ENTITY options.activeBlockLabel "Aktivně blokovat otevřené stránky jakmile začne vybrané období nebo uplyne časový limit">
<!ENTITY options.countFocusLabel "Počítat čas strávený na stránkách pouze pokud je panel aktivní">
<!ENTITY options.delayFirstLabel "Block only first accessed page of site when delaying page is used">
<!ENTITY options.delaySecsDesc1 "Odložit přístup na stránky o">
<!ENTITY options.delaySecsDesc2 "sekund při použití stránky odložení">
<!ENTITY options.advancedWarnDesc1 "Upozornění!">
Expand Down
1 change: 1 addition & 0 deletions chrome/locale/en-US/leechblock.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<!ENTITY options.homePageLabel "Home Page">
<!ENTITY options.activeBlockLabel "Actively block pages on these sites once time period is entered or time limit is exceeded">
<!ENTITY options.countFocusLabel "Count time spent on these sites only when browser tab is active">
<!ENTITY options.delayFirstLabel "Block only first accessed page of site when delaying page is used">
<!ENTITY options.delaySecsDesc1 "Delay access to sites by">
<!ENTITY options.delaySecsDesc2 "seconds when delaying page is used">
<!ENTITY options.advancedWarnDesc1 "Warning!">
Expand Down
1 change: 1 addition & 0 deletions chrome/locale/fr-FR/leechblock.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<!ENTITY options.homePageLabel "Page d'accueil">
<!ENTITY options.activeBlockLabel "Bloquer les sites sans attendre leur réactualisation quand les conditions de blocage sont réunies">
<!ENTITY options.countFocusLabel "Décompter le temps passé sur les sites seulement quand leur onglet est actif">
<!ENTITY options.delayFirstLabel "Block only first accessed page of site when delaying page is used">
<!ENTITY options.delaySecsDesc1 "Retarder momentanément l'accès aux sites de">
<!ENTITY options.delaySecsDesc2 "secondes quand la page de blocage momentané est sélectionnée">
<!ENTITY options.advancedWarnDesc1 "Attention !">
Expand Down
1 change: 1 addition & 0 deletions chrome/locale/pt-BR/leechblock.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<!ENTITY options.homePageLabel "Página Inicial">
<!ENTITY options.activeBlockLabel "Bloquear ativamente as páginas desses sites assim que o horário começar ou quando o limite de tempo for excedido.">
<!ENTITY options.countFocusLabel "Contar o tempo gasto nesses sites apenas quando a aba do navegador estiver ativa">
<!ENTITY options.delayFirstLabel "Block only first accessed page of site when delaying page is used">
<!ENTITY options.delaySecsDesc1 "Atrasar o acesso aos sites em">
<!ENTITY options.delaySecsDesc2 "segundos quando a página de atraso for utilizada">
<!ENTITY options.advancedWarnDesc1 "Aviso!">
Expand Down
1 change: 1 addition & 0 deletions chrome/locale/zh-CN/leechblock.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<!ENTITY options.homePageLabel "主页">
<!ENTITY options.activeBlockLabel "动态的阻止这些网站的网页,一旦到了时间段或者超过时间限制">
<!ENTITY options.countFocusLabel "仅在相应的浏览器标签活动时计算在网站上使用的时间">
<!ENTITY options.delayFirstLabel "Block only first accessed page of site when delaying page is used">
<!ENTITY options.delaySecsDesc1 "延迟访问网站的时间">
<!ENTITY options.delaySecsDesc2 "使用延迟页面的秒数">
<!ENTITY options.advancedWarnDesc1 "警告!">
Expand Down
1 change: 1 addition & 0 deletions chrome/locale/zh-TW/leechblock.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<!ENTITY options.homePageLabel "主頁">
<!ENTITY options.activeBlockLabel "在時間段或者超過時間限制主動封鎖這些網站">
<!ENTITY options.countFocusLabel "僅於使用該網頁時計算在消耗時間">
<!ENTITY options.delayFirstLabel "Block only first accessed page of site when delaying page is used">
<!ENTITY options.delaySecsDesc1 "延遲存取網站的時間">
<!ENTITY options.delaySecsDesc2 "使用延遲頁面的秒數">
<!ENTITY options.advancedWarnDesc1 "警告!">
Expand Down
5 changes: 4 additions & 1 deletion defaults/preferences/leechblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pref("extensions.leechblock.blockURL5", "chrome://leechblock/content/blocked.xht
pref("extensions.leechblock.blockURL6", "chrome://leechblock/content/blocked.xhtml?$S&$U");
pref("extensions.leechblock.activeBlock", 0);
pref("extensions.leechblock.countFocus", 63);
pref("extensions.leechblock.delayFirst", 63);
pref("extensions.leechblock.delaySecs1", "60");
pref("extensions.leechblock.delaySecs2", "60");
pref("extensions.leechblock.delaySecs3", "60");
Expand Down Expand Up @@ -95,7 +96,8 @@ pref("extensions.leechblock.timedata6", "");
pref("extensions.leechblock.repeatCheckPeriod", 5000);
pref("extensions.leechblock.lockdownDuration", 0);
pref("extensions.leechblock.lockdownSets", 0);
pref("extensions.leechblock.ah", "");
pref("extensions.leechblock.ao", "");
pref("extensions.leechblock.ap", "");
pref("services.sync.prefs.sync.extensions.leechblock.setName1", true);
pref("services.sync.prefs.sync.extensions.leechblock.setName2", true);
pref("services.sync.prefs.sync.extensions.leechblock.setName3", true);
Expand Down Expand Up @@ -165,6 +167,7 @@ pref("services.sync.prefs.sync.extensions.leechblock.blockURL5", true);
pref("services.sync.prefs.sync.extensions.leechblock.blockURL6", true);
pref("services.sync.prefs.sync.extensions.leechblock.activeBlock", true);
pref("services.sync.prefs.sync.extensions.leechblock.countFocus", true);
pref("services.sync.prefs.sync.extensions.leechblock.delayFirst", true);
pref("services.sync.prefs.sync.extensions.leechblock.delaySecs1", true);
pref("services.sync.prefs.sync.extensions.leechblock.delaySecs2", true);
pref("services.sync.prefs.sync.extensions.leechblock.delaySecs3", true);
Expand Down

0 comments on commit 6015667

Please sign in to comment.