Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ var API_URL = 'http://crackbook.info/api/';
var NOTIFICATION_THRESHOLD = 5;
var NOTIFICATION_HIT_INTERVAL = 5;

function getAppearance()
{
return {transparent: false,custDimmerText:getLocal('custDimmerText'),custSwitchText:getLocal('custDimmerText')};
}

function drawIcon(img_name) {
img_path = "images/" + img_name;
chrome.browserAction.setIcon({ path: img_path });
Expand Down Expand Up @@ -164,7 +169,7 @@ function handleNewPage(newTab, selectedTab, sendResponse) {
var tabIsActive = (newTab.id == selectedTab.id);
sendResponse({dimmerAction: tabIsActive ? "create" : "create_suspended",
delay: getLocal('dimmerDelay'),
appearance: {transparent: false}});
appearance: getAppearance()});
if (tabIsActive) {
lastDimmedTabId = newTab.id;
}
Expand Down Expand Up @@ -235,7 +240,7 @@ function newPageHandler(request, sender, sendResponse) {
function showNotification() {
var notification_obj = webkitNotifications.createNotification(
'images/hamburger-128px.png',
NOTIFICATION_TEXT,
getLocal('custNotificationText'),
"");
notification_obj.show();
window.setTimeout(function() { notification_obj.cancel() }, 3000);
Expand Down
11 changes: 8 additions & 3 deletions dimmer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var BODY_POLL_MS = 30;
var DIMMER_DIV_ID = '_crackbook_dimmer_';
var DIMMER_TEXT = "Wait %d seconds for the content to appear.";
//var DIMMER_TEXT = "Wait %d seconds for the content to appear.";
var DIMMER_SWITCH_TEXT = "The timer restarts if you switch away from this tab.";

var timeoutFn = function() {
Expand Down Expand Up @@ -40,6 +40,11 @@ function setTimer(dimmer, delay) {
timerIdInput.value = timerId;
}

function getCustomText(appearance,name)
{
return (name in appearance)?appearance[name]:getLocal(name)||'';
}

function addDimmer(delay, appearance) {
var dimmer = document.createElement('div');
dimmer.id = DIMMER_DIV_ID;
Expand All @@ -54,14 +59,14 @@ function addDimmer(delay, appearance) {
dimmer.style.fontVariant = 'normal';

var text = document.createElement("div");
text.innerHTML = DIMMER_TEXT.replace('%d', Math.round(delay));
console.log(text.innerHTML = getCustomText(appearance,'custDimmerText').replace('%d', Math.round(delay)));
text.style.textAlign = "center";
text.style.paddingTop = "50px";
text.style.fontSize = "20px";
dimmer.appendChild(text);

var switch_text = document.createElement("div");
switch_text.innerHTML = DIMMER_SWITCH_TEXT;
switch_text.innerHTML = getCustomText(appearance,'custSwitchText');
switch_text.id = DIMMER_DIV_ID + 'stayput';
switch_text.style.display = "none";
switch_text.style.textAlign = "center";
Expand Down
5 changes: 4 additions & 1 deletion lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ var_defaults = {
weekdays: '"12345"',
day: '""',
dayHits: '0',
hitLogKeys: '[]'
hitLogKeys: '[]',
custDimmerText: '"Wait %d seconds for the content to appear!"',
custSwitchText: '"The timer restarts if you switch away from this tab."',
custNotificationText: '"Time to get back to work!"'
};

function getLocal(varname) {
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Crackbook",
"version": "0.2.7",
"version": "0.2.8",
"manifest_version": 2,
"description": "Limit junk sites in your daily infodiet.",
"icons": {
Expand All @@ -18,7 +18,7 @@
"content_scripts": [
{
"matches": ["*://*/*"],
"js": ["dimmer.js"],
"js": ["lib.js","dimmer.js"],
"run_at": "document_start"
}
],
Expand Down
14 changes: 14 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,27 @@
<div>
<label>Increase the delay by <input id="dimmerDelayIncrement" class="rightAlign" name="dimmerDelayIncrement" type="text" /> seconds after every block</label>
</div>
<div>
<label>Probability of redirect is <input id="redirectProbability" class="rightAlign" name="redirectProbability" type="text" /> %.</label>
</div>
<div style="padding-top: 0.3em">
<label>
<label><input id="checkActiveTab" name="checkActiveTab" type="checkbox" value="1" />Block new background tabs opened from a junk page</label>
</label>
</div>
</div>

<div class="subheading" style="padding-bottom: 0.4EM">Customization</div>
<div>
<label>Text to show while blocked: <input id="custDimmerText" name="custDimmerText" type="text">.</label>
</div>
<div>
<label>Text to show when switch tabs: <input id="custSwitchText" name="custSwitchText" type="text">.</label>
</div>
<div>
<label>Text to show while mouse is over the icon: <input id="custNotificationText" name="custNotificationText" type="text">.</label>
</div>

<div class="subheading" style="padding-bottom: 0.4em">Usage data</div>
<div>
<label>
Expand Down
11 changes: 11 additions & 0 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ function showSettings() {
document.getElementById("dimmerDelay").value = getLocal('dimmerDelay').toFixed(2);
document.getElementById("dimmerDelayIncrement").value = getLocal('dimmerDelayIncrement').toFixed(2);
document.getElementById("checkActiveTab").checked = getLocal('checkActiveTab');
document.getElementById("custDimmerText").value = getLocal('custDimmerText');
document.getElementById("custSwitchText").value = getLocal('custSwitchText');
document.getElementById("custNotificationText").value = getLocal('custNotificationText');


// Junk domains.
clearDomainsFromPage('siteBlacklist');
Expand Down Expand Up @@ -197,6 +201,10 @@ function saveSettings() {

var reporting = document.getElementById("upload_stats").checked;

var custDimmerText = document.getElementById('custDimmerText').value||getLocal('custDimmerText');
var custSwitchText = document.getElementById('custSwitchText').value||getLocal('custDimmerText');
var custNotificationText = document.getElementById('custNotificationText').value||getLocal('custNotificationText');

// Write settings to storage.
setLocal('reporting', reporting);
setLocal('dimmerThreshold', dimmerThreshold);
Expand All @@ -208,6 +216,9 @@ function saveSettings() {
setLocal('startTime', startTime);
setLocal('endTime', endTime);
setLocal('weekdays', weekdays);
setLocal('custDimmerText', custDimmerText);
setLocal('custSwitchText', custSwitchText);
setLocal('custNotificationText', custNotificationText);

bgPage().submitConfigChange();
bgPage().updateIcon(null, true);
Expand Down