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 0c07e2e + 5690e9c commit e518f38
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 12 deletions.
7 changes: 6 additions & 1 deletion VERSIONS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Version 1.6.8 (09 Jan 2024)
# 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.

Expand Down
31 changes: 26 additions & 5 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 @@ -1522,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 @@ -1660,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 @@ -1735,7 +1753,8 @@ 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;
Expand Down Expand Up @@ -1765,6 +1784,8 @@ function handleTabActivated(activeInfo) {

initTab(tabId);

gTabs[tabId].focused = true;

if (!gGotOptions) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions common.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,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
11 changes: 11 additions & 0 deletions content.js
Original file line number Diff line number Diff line change
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);
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@
"webNavigation"
],

"version": "1.6.8"
"version": "1.6.8.2"

}
6 changes: 5 additions & 1 deletion options.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
</p>
<p>
<strong>Tip:</strong>
Use <code>*</code> as <a href="https://www.proginosko.com/leechblock/faq/wildcards/" target="_blank">wildcard</a>,
Use <code>*</code> or <code>**</code> as <a href="https://www.proginosko.com/leechblock/faq/wildcards/" target="_blank">wildcard</a>,
<code>+</code> to prefix <a href="https://www.proginosko.com/leechblock/faq/exceptions/" target="_blank">exceptions</a>,
<code>&gt;</code> to prefix <a href="https://www.proginosko.com/leechblock/faq/referrers/" target="_blank">referrers</a>,
and <code>~</code> to prefix <a href="https://www.proginosko.com/leechblock/faq/keywords/" target="_blank">keywords</a>.
Expand Down Expand Up @@ -518,6 +518,10 @@
<input id="allFocused" type="checkbox">
<label for="allFocused">Treat browser windows as always focused</label>
</p>
<p class="simplifiable">
<input id="useDocFocus" type="checkbox">
<label for="useDocFocus">Use document focus for counting time on active tab (Android only)</label>
</p>
<p class="simplifiable">
<input id="accessCodeImage" type="checkbox">
<label for="accessCodeImage">Display access code as image</label>
Expand Down
11 changes: 7 additions & 4 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ function getElement(id) { return document.getElementById(id); }

function isTrue(str) { return /^true$/i.test(str); }

function escape(str) { return str.replace(/\n/g, "\\n"); }
function unescape(str) { return str.replace(/\\n/g, "\n"); }

var gIsAndroid = false;
var gAccessConfirmed = false;
var gAccessRequiredInput;
Expand Down Expand Up @@ -765,7 +768,7 @@ function compileExportOptions(passwords) {
} else if (type == "boolean") {
options[`${name}${set}`] = getElement(`${id}${set}`).checked;
} else if (type == "string") {
options[`${name}${set}`] = getElement(`${id}${set}`).value;
options[`${name}${set}`] = escape(getElement(`${id}${set}`).value);
} else if (type == "array") {
let val = PER_SET_OPTIONS[name].def.slice();
for (let i = 0; i < val.length; i++) {
Expand All @@ -785,7 +788,7 @@ function compileExportOptions(passwords) {
if (type == "boolean") {
options[name] = getElement(id).checked;
} else if (type == "string") {
options[name] = getElement(id).value;
options[name] = escape(getElement(id).value);
}
}
}
Expand Down Expand Up @@ -815,7 +818,7 @@ function applyImportOptions(options) {
} else if (type == "boolean") {
getElement(`${id}${set}`).checked = val;
} else if (type == "string") {
getElement(`${id}${set}`).value = val;
getElement(`${id}${set}`).value = unescape(val);;
} else if (type == "array") {
for (let i = 0; i < val.length; i++) {
getElement(`${id}${i}${set}`).checked = val[i];
Expand Down Expand Up @@ -845,7 +848,7 @@ function applyImportOptions(options) {
if (type == "boolean") {
getElement(id).checked = options[name];
} else if (type == "string") {
getElement(id).value = options[name];
getElement(id).value = unescape(options[name]);
}
}
}
Expand Down

0 comments on commit e518f38

Please sign in to comment.