Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
proginosko committed Feb 2, 2025
2 parents 01db712 + e518f38 commit cde9740
Show file tree
Hide file tree
Showing 26 changed files with 440 additions and 156 deletions.
13 changes: 13 additions & 0 deletions VERSIONS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Version 1.6.8.2 (26 Jan 2025)
* Fixed issue with counting time on active tab (Android).
* Fixed issue with export/import of multiline strings.
* Closed some escape hatches.

# Version 1.6.8 (09 Jan 2025)
* Added option for custom style (CSS) for blocking/delaying page.
* Bug fixes.

# Version 1.6.7 (22 Dec 2024)
* Added support for keyboard shortcuts.
* Bug fixes and under-the-hood improvements.

# Version 1.6.6 (21 Oct 2024)
* Added Vietnamese localization (thanks to anhkhoakz).
* Added option to enter custom message on blocking/delaying page.
Expand Down
99 changes: 90 additions & 9 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var gFocusWindowId = 0;
var gClockOffset = 0;
var gIgnoreJumpSecs = 0;
var gAllFocused = false;
var gUseDocFocus = true;
var gOverrideIcon = false;
var gSaveSecsCount = 0;

Expand All @@ -49,6 +50,7 @@ function initTab(id) {
url: "about:blank",
incog: false,
audible: false,
focused: false,
loaded: false,
loadedTime: 0
};
Expand Down Expand Up @@ -217,6 +219,7 @@ function retrieveOptions(update) {
gClockOffset = +gOptions["clockOffset"];
gIgnoreJumpSecs = +gOptions["ignoreJumpSecs"];
gAllFocused = gOptions["allFocused"];
gUseDocFocus = gOptions["useDocFocus"];

createRegExps();
refreshMenus();
Expand Down Expand Up @@ -404,7 +407,8 @@ function processTabs(active) {
for (let tab of tabs) {
initTab(tab.id);

let focus = tab.active && (gAllFocused || !gFocusWindowId || tab.windowId == gFocusWindowId);
let focus = tab.active && (gAllFocused || !gFocusWindowId || tab.windowId == gFocusWindowId)
&& (!gIsAndroid || !gUseDocFocus || gTabs[tab.id].focused);

gTabs[tab.id].incog = tab.incognito;
gTabs[tab.id].audible = tab.audible;
Expand Down Expand Up @@ -855,14 +859,19 @@ function clockPageTime(id, open, focus) {

// Update time data if necessary
if (secsOpen > 0 || secsFocus > 0) {
updateTimeData(gTabs[id].url, gTabs[id].referrer, gTabs[id].audible, secsOpen, secsFocus);
updateTimeData(id, secsOpen, secsFocus);
}
}

// Update time data for specified page
//
function updateTimeData(url, referrer, audible, secsOpen, secsFocus) {
//log("updateTimeData: " + url + " " + secsOpen + " " + secsFocus);
function updateTimeData(id, secsOpen, secsFocus) {
//log("updateTimeData: " + id + " " + secsOpen + " " + secsFocus);

let referrer = gTabs[id].referrer;
let url = gTabs[id].url;
let incog = gTabs[id].incog;
let audible = gTabs[id].audible;

// Get parsed URL for this page
let parsedURL = getParsedURL(url);
Expand All @@ -881,6 +890,10 @@ function updateTimeData(url, referrer, audible, secsOpen, secsFocus) {
let referRE = gRegExps[set].refer;
if (!blockRE && !referRE) continue; // no block for this set

// Check incognito mode
let incogMode = gOptions[`incogMode${set}`];
if ((incogMode == 1 && incog) || (incogMode == 2 && !incog)) continue;

// Get option for counting time only when tab is playing audio
let countAudio = gOptions[`countAudio${set}`];
if (countAudio && !audible) continue; // no audio playing
Expand Down Expand Up @@ -1041,13 +1054,16 @@ function createBlockInfo(id, url) {
// Get theme
let theme = gOptions["theme"];

// Get custom style
let customStyle = gOptions["customStyle"];

// Get parsed URL
let parsedURL = getParsedURL(url);
let pageURL = parsedURL.page;

if (parsedURL.args == null || parsedURL.args.length < 2) {
warn("Cannot create block info: not enough arguments in URL.");
return { theme: theme };
return { theme: theme, customStyle: customStyle };
}

// Get block set and URL (including hash part) of blocked page
Expand Down Expand Up @@ -1099,6 +1115,7 @@ function createBlockInfo(id, url) {

return {
theme: theme,
customStyle: customStyle,
blockedSet: blockedSet,
blockedSetName: blockedSetName,
blockedURL: blockedURL,
Expand Down Expand Up @@ -1509,11 +1526,20 @@ function addSitesToSet(siteList, set) {
// Get sites for this set
let sites = gOptions[`sites${set}`];

// Add sites if not exceptions and not already included
// Get keyword info
let keywordRE = gOptions[`keywordRE${set}`];
let allowKeywords = gOptions[`allowKeywords${set}`];

// Add sites to list
let patterns = sites.split(/\s+/);
for (let site of siteList.split(/\s+/)) {
if (site.charAt(0) != "+" && patterns.indexOf(site) < 0) {
patterns.push(site);
let firstChar = site.charAt(0);
// Add item only if not exception and not already in list
if (firstChar != "+" && patterns.indexOf(site) < 0) {
// Add keywords only if keywords already there (and not as allow-condition)
if (firstChar != "~" || (keywordRE && !allowKeywords)) {
patterns.push(site);
}
}
}

Expand Down Expand Up @@ -1563,6 +1589,46 @@ function handleMenuClick(info, tab) {
}
}

function handleCommand(command) {
//log("handleCommand: " + command);

switch(command) {

case "lb-options":
browser.runtime.openOptionsPage();
break;

case "lb-statistics":
openExtensionPage("stats.html");
break;

case "lb-lockdown":
openExtensionPage("lockdown.html");
break;

case "lb-override":
openExtensionPage("override.html");
break;

case "lb-cancel-override":
applyOverride(0);
break;

case "lb-add-sites":
openExtensionPage("add-sites.html");
break;

case "lb-reset-rollover":
resetRolloverTime();
break;

case "lb-discard-time":
discardRemainingTime();
break;

}
}

function handleMessage(message, sender, sendResponse) {
if (!sender) {
warn("No sender!");
Expand Down Expand Up @@ -1607,6 +1673,11 @@ function handleMessage(message, sender, sendResponse) {
discardRemainingTime();
break;

case "focus":
// Tab focus event received
gTabs[sender.tab.id].focused = message.focus;
break;

case "loaded":
// Register that content script has been loaded
gTabs[sender.tab.id].loaded = true;
Expand Down Expand Up @@ -1682,7 +1753,11 @@ function handleTabUpdated(tabId, changeInfo, tab) {
return;
}

let focus = tab.active && (gAllFocused || !gFocusWindowId || tab.windowId == gFocusWindowId);
let focus = tab.active && (gAllFocused || !gFocusWindowId || tab.windowId == gFocusWindowId)
&& (!gIsAndroid || !gUseDocFocus || gTabs[tab.id].focused);

gTabs[tab.id].incog = tab.incognito;
gTabs[tab.id].audible = tab.audible;

if (changeInfo.url) {
gTabs[tabId].url = getCleanURL(changeInfo.url);
Expand All @@ -1709,6 +1784,8 @@ function handleTabActivated(activeInfo) {

initTab(tabId);

gTabs[tabId].focused = true;

if (!gGotOptions) {
return;
}
Expand Down Expand Up @@ -1810,6 +1887,10 @@ if (browser.contextMenus) {
browser.contextMenus.onClicked.addListener(handleMenuClick);
}

if (browser.commands) {
browser.commands.onCommand.addListener(handleCommand);
}

browser.runtime.onMessage.addListener(handleMessage);

browser.tabs.onCreated.addListener(handleTabCreated);
Expand Down
17 changes: 9 additions & 8 deletions blocked.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,37 @@
<link rel="stylesheet" href="/fonts.css" type="text/css">
<link rel="stylesheet" href="/style.css" type="text/css">
<link id="themeLink" rel="stylesheet">
<style id="customStyle"></style>
</head>

<body>

<!-- logo -->
<div>
<img src="/images/leechblock_logo.svg" class="logo" alt="LeechBlock logo" title="LeechBlock">
<div id="lbLogoDiv">
<a href="https://www.proginosko.com/leechblock/"><img id="lbLogoImg" src="/images/leechblock_logo.svg" class="logo" alt="LeechBlock logo" title="LeechBlock"></a>
</div>

<!-- warning message -->
<div>
<div id="lbWarningMsgDiv">
<h1>The page you're trying to access has been blocked by <a href="https://www.proginosko.com/leechblock/">LeechBlock</a>.</h1>
</div>

<!-- blocked site info -->
<div>
<div id="lbBlockedDiv">
<a id="lbBlockedURLLink" target="_self"><span id="lbBlockedURL"></span></a>
(<span id="lbBlockedSet">Block Set</span>)
<p id="lbKeywordMatched">Keyword matched: <strong><span id="lbKeywordMatch"></span></strong></p>
<p>The page will be unblocked at: <strong><span id="lbUnblockTime">the end of time</span></strong></p>
<p id="lbKeywordMatched">Keyword matched: <span id="lbKeywordMatch" class="keyword"></span></p>
<p id="lbUnblockText">The page will be unblocked at: <span id="lbUnblockTime" class="time">the end of time</span></p>
</div>

<!-- custom message (optional) -->
<div id="lbCustomMsgDiv">
<p>A message from yourself:</p>
<strong><blockquote id="lbCustomMsg"></blockquote></strong>
<blockquote id="lbCustomMsg"></blockquote>
</div>

<!-- support info -->
<div class="support">
<div id="lbSupportDiv" class="support">
LeechBlock will always be free to use, but if it has improved your life,<br>
please consider supporting its continued development by<br>
<a href="https://www.paypal.me/JamesNAnderson">making a contribution</a> or
Expand Down
12 changes: 9 additions & 3 deletions blocked.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ function processBlockInfo(info) {
gBlockedURL = info.blockedURL;

// Set theme
let link = document.getElementById("themeLink");
if (link) {
link.href = "/themes/" + (info.theme ? `${info.theme}.css` : "default.css");
let themeLink = document.getElementById("themeLink");
if (themeLink) {
themeLink.href = "/themes/" + (info.theme ? `${info.theme}.css` : "default.css");
}

// Set custom style
let customStyle = document.getElementById("customStyle");
if (customStyle) {
customStyle.innerText = info.customStyle;
}

let blockedURL = document.getElementById("lbBlockedURL");
Expand Down
2 changes: 2 additions & 0 deletions common.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const GENERAL_OPTIONS = {
numSets: { type: "string", def: "6", id: "numSets" }, // default: 6 block sets
sync: { type: "boolean", def: false, id: "syncStorage" }, // default: use local storage
theme: { type: "string", def: "", id: "theme" }, // default: light theme
customStyle: { type: "string", def: "", id: "customStyle" }, // default: no custom style
oa: { type: "string", def: "0", id: "optionsAccess" }, // default: no password or code
password: { type: "string", def: "", id: "accessPassword" }, // default: blank
hpp: { type: "boolean", def: true, id: "hidePassword" }, // default: hidden
Expand Down Expand Up @@ -107,6 +108,7 @@ const GENERAL_OPTIONS = {
clockOffset: { type: "string", def: "", id: "clockOffset" }, // default: no offset
ignoreJumpSecs: { type: "string", def: "", id: "ignoreJumpSecs" }, // default: do not ignore time jumps
allFocused: { type: "boolean", def: false, id: "allFocused" }, // default: disabled
useDocFocus: { type: "boolean", def: true, id: "useDocFocus" }, // default: enabled
processTabsSecs: { type: "string", def: "1", id: "processTabsSecs" }, // default: every second
processActiveTabs: { type: "boolean", def: false, id: "processActiveTabs" }, // default: disabled
accessCodeImage: { type: "boolean", def: false, id: "accessCodeImage" }, // default: disabled
Expand Down
15 changes: 13 additions & 2 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ function applyFilter(name) {
"sepia": "sepia(100%)"
};
if (name && filters[name]) {
document.body.style.filter = filters[name];
document.documentElement.style.filter = filters[name];
} else {
document.body.style.filter = "none";
document.documentElement.style.filter = "none";
}
}

Expand Down Expand Up @@ -180,6 +180,17 @@ function handleMessage(message, sender, sendResponse) {

}

function onFocus(event) {
browser.runtime.sendMessage({ type: "focus", focus: true });
}

function onBlur(event) {
browser.runtime.sendMessage({ type: "focus", focus: false });
}

browser.runtime.onMessage.addListener(handleMessage);

notifyLoaded();

window.addEventListener("focus", onFocus);
window.addEventListener("blur", onBlur);
21 changes: 14 additions & 7 deletions de/blocked.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,37 @@
<link rel="stylesheet" href="/fonts.css" type="text/css">
<link rel="stylesheet" href="/style.css" type="text/css">
<link id="themeLink" rel="stylesheet">
<style id="customStyle"></style>
</head>

<body>

<!-- logo -->
<div>
<img src="/images/leechblock_logo.svg" class="logo" alt="LeechBlock logo" title="LeechBlock">
<div id="lbLogoDiv">
<a href="https://www.proginosko.com/leechblock/"><img id="lbLogoImg" src="/images/leechblock_logo.svg" class="logo" alt="LeechBlock logo" title="LeechBlock"></a>
</div>

<!-- warning message -->
<div>
<div id="lbWarningMsgDiv">
<h1>Die Seite, die du aufrufen willst, wurde von <a href="https://www.proginosko.com/leechblock/">LeechBlock</a> gesperrt.</h1>
</div>

<!-- blocked site info -->
<div>
<div id="lbBlockedDiv">
<a id="lbBlockedURLLink" target="_self"><span id="lbBlockedURL"></span></a>
(<span id="lbBlockedSet">Blocksatz</span>)
<p id="lbKeywordMatched">Schlüsselwort gefunden: <strong><span id="lbKeywordMatch"></span></strong></p>
<p>Die Seite wird entsperrt ab: <strong><span id="lbUnblockTime">das Ende der Zeit</span></strong></p>
<p id="lbKeywordMatched">Schlüsselwort gefunden: <span id="lbKeywordMatch" class="keyword"></span></p>
<p id="lbUnblockText">Die Seite wird entsperrt ab: <span id="lbUnblockTime" class="time">das Ende der Zeit</span></p>
</div>

<!-- custom message (optional) -->
<div id="lbCustomMsgDiv">
<p>Eine Nachricht von dir selbst:</p>
<blockquote id="lbCustomMsg"></blockquote>
</div>

<!-- support info -->
<div class="support">
<div id="lbSupportDiv" class="support">
Die Nutzung von LeechBlock wird immer kostenlos sein, aber wenn es dein Leben verbessert<br>
hat, solltest du in Erwägung ziehen, die Weiterentwicklung zu unterstützen indem du einen<br>
<a href="https://www.paypal.me/JamesNAnderson">Spendenbeitrag leistest</a> oder
Expand Down
Loading

0 comments on commit cde9740

Please sign in to comment.