Skip to content

Commit 946c51f

Browse files
committed
v0.46.53.1
1 parent 20e2577 commit 946c51f

File tree

6 files changed

+79
-49
lines changed

6 files changed

+79
-49
lines changed

changelog.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
v0.46.53 - Thursday, May 5, 2016
1+
v0.46.53.1 - Thursday, May 5, 2016
2+
- v0.46.53.1 = tweaked Paranoid Mode to Cloak behaviour, fixed page favicon and page titles toggling, and hotkey changes now take effect immediately
23
- updated core DP cloaking functions so that DP Option setting changes and the Paranoid Hotkey toggle take effect immediately (without temporarily uncloaking and recloaking open tabs)
34
- optimized number of calls when cloaking a page (from 3 to 1)
45
- tweaked page favicon cloaking to be instant

js/background.js

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,20 @@ function setDefaultOptions() {
129129
chrome.contextMenus.create({"title": chrome.i18n.getMessage("whitelistdomain"), "contexts": ['browser_action','page_action'], "onclick": function(info, tab){
130130
if (tab.url.substring(0, 4) != 'http') return;
131131
domainHandler(extractDomainFromURL(tab.url), 0);
132-
if (localStorage["enable"] == "true") magician('false', localStorage["showIcon"], localStorage["disableFavicons"], localStorage["hidePageTitles"], localStorage["pageTitleText"], tab.id);
132+
if (localStorage["enable"] == "true") magician('false', tab.id);
133133
}});
134134
chrome.contextMenus.create({"title": chrome.i18n.getMessage("blacklistdomain"), "contexts": ['browser_action','page_action'], "onclick": function(info, tab){
135135
if (tab.url.substring(0, 4) != 'http') return;
136136
domainHandler(extractDomainFromURL(tab.url), 1);
137-
if (localStorage["enable"] == "true") magician('true', localStorage["showIcon"], localStorage["disableFavicons"], localStorage["hidePageTitles"], localStorage["pageTitleText"], tab.id);
137+
if (localStorage["enable"] == "true") magician('true', tab.id);
138138
}});
139139
chrome.contextMenus.create({"title": chrome.i18n.getMessage("removelist"), "contexts": ['browser_action','page_action'], "onclick": function(info, tab){
140140
if (tab.url.substring(0, 4) != 'http') return;
141141
domainHandler(extractDomainFromURL(tab.url), 2);
142142
if (localStorage["enable"] == "true") {
143143
if (localStorage['newPages'] == 'Cloak' || localStorage['global'] == 'true') flag = 'true';
144144
else flag = 'false';
145-
magician(flag, localStorage["showIcon"], localStorage["disableFavicons"], localStorage["hidePageTitles"], localStorage["pageTitleText"], tab.id);
145+
magician(flag, tab.id);
146146
}
147147
}});
148148

@@ -152,9 +152,9 @@ function newCloak(info, tab) {
152152
localStorage["enable"] = "true";
153153
localStorage["sfwmode"] = "SFW";
154154
// If it's an image, load the "src" attribute
155-
if (info.mediaType) chrome.tabs.create({'url': info.srcUrl}, function(tab){cloakedTabs.push(tab.id);recursiveCloak('true', localStorage["global"], localStorage["showIcon"], localStorage["disableFavicons"], localStorage["hidePageTitles"], localStorage["pageTitleText"], tab.id);});
155+
if (info.mediaType) chrome.tabs.create({'url': info.srcUrl}, function(tab){cloakedTabs.push(tab.id);recursiveCloak('true', localStorage["global"], tab.id);});
156156
// Else, it's a normal link, so load the linkUrl.
157-
else chrome.tabs.create({'url': info.linkUrl}, function(tab){cloakedTabs.push(tab.id);recursiveCloak('true', localStorage["global"], localStorage["showIcon"], localStorage["disableFavicons"], localStorage["hidePageTitles"], localStorage["pageTitleText"], tab.id);});
157+
else chrome.tabs.create({'url': info.linkUrl}, function(tab){cloakedTabs.push(tab.id);recursiveCloak('true', localStorage["global"], tab.id);});
158158
}
159159
// Add context menu item that shows only if you right-click on links/images.
160160
function dpContext(boo) {
@@ -169,7 +169,16 @@ function uncloakAll(){
169169
cloakedTabs=[];
170170
uncloakedTabs=[];
171171
}
172-
function recursiveCloak(enable, global, showIcon, hideFavicon, hidePageTitle, titleText, tabId) {
172+
function hotkeyChange() {
173+
chrome.windows.getAll({"populate":true}, function(windows) {
174+
for (var i=0; i<windows.length; i++) {
175+
for (var x=0; x<windows[i].tabs.length; x++) {
176+
chrome.tabs.executeScript(windows[i].tabs[x].id, {code: 'hotkeySet("'+localStorage["enableToggle"]+'","'+localStorage["hotkey"]+'","'+localStorage["paranoidhotkey"]+'");', allFrames: true});
177+
}
178+
}
179+
});
180+
}
181+
function recursiveCloak(enable, global, tabId) {
173182
if (global == 'true') {
174183
chrome.windows.getAll({"populate":true}, function(windows) {
175184
for (var i=0; i<windows.length; i++) {
@@ -179,17 +188,17 @@ function recursiveCloak(enable, global, showIcon, hideFavicon, hidePageTitle, ti
179188
var dpcloakindex = cloakedTabs.indexOf(windows[i].tabs[x].id);
180189
if (dpcloakindex != -1) cloakedTabs.splice(dpcloakindex, 1);
181190
else cloakedTabs.push(windows[i].tabs[x].id);
182-
magician(enable, showIcon, hideFavicon, hidePageTitle, titleText, windows[i].tabs[x].id);
191+
magician(enable, windows[i].tabs[x].id);
183192
}
184193
}
185194
}
186195
});
187196
} else {
188-
if (tabId) magician(enable, showIcon, hideFavicon, hidePageTitle, titleText, tabId);
197+
if (tabId) magician(enable, tabId);
189198
else {
190199
// If no tabId is passed, it means the user changed an option on the Options page and we must go through all of the individual tabs that have cloaking enabled (we're in this section because global is false)
191200
for (var i=cloakedTabs.length-1; i>=0; --i) {
192-
magician(enable, showIcon, hideFavicon, hidePageTitle, titleText, cloakedTabs[i]);
201+
magician(enable, cloakedTabs[i]);
193202
}
194203
}
195204
}
@@ -206,16 +215,20 @@ function setDPIcon() {
206215
}
207216
});
208217
}
209-
function magician(enable, showIcon, hideFavicon, hidePageTitle, titleText, tabId) {
218+
function magician(enable, tabId) {
210219
if (enable == 'true') {
211-
if (hideFavicon == 'true' && hidePageTitle == 'true') chrome.tabs.executeScript(tabId, {code: 'init();faviconblank();replaceTitle("'+titleText+'");titleBind("'+titleText+'");', allFrames: true});
212-
else if (hideFavicon == 'true' && hidePageTitle != 'true') chrome.tabs.executeScript(tabId, {code: "init();faviconblank();titleRestore();", allFrames: true});
213-
else if (hideFavicon != 'true' && hidePageTitle == 'true') chrome.tabs.executeScript(tabId, {code: 'init();faviconrestore();replaceTitle("'+titleText+'");titleBind("'+titleText+'");', allFrames: true});
214-
else if (hideFavicon != 'true' && hidePageTitle != 'true') chrome.tabs.executeScript(tabId, {code: 'init();faviconrestore();titleRestore();', allFrames: true});
220+
if (localStorage["disableFavicons"] == 'true' && localStorage["hidePageTitles"] == 'true')
221+
chrome.tabs.executeScript(tabId, {code: 'init();faviconblank();replaceTitle("'+localStorage["pageTitleText"]+'");titleBind("'+localStorage["pageTitleText"]+'");', allFrames: true});
222+
else if (localStorage["disableFavicons"] == 'true' && localStorage["hidePageTitles"] != 'true')
223+
chrome.tabs.executeScript(tabId, {code: 'init();faviconblank();titleRestore();', allFrames: true});
224+
else if (localStorage["disableFavicons"] != 'true' && localStorage["hidePageTitles"] == 'true')
225+
chrome.tabs.executeScript(tabId, {code: 'init();faviconrestore();replaceTitle("'+localStorage["pageTitleText"]+'");localStorage["pageTitleText"]("'+titleText+'");', allFrames: true});
226+
else if (localStorage["disableFavicons"] != 'true' && localStorage["hidePageTitles"] != 'true')
227+
chrome.tabs.executeScript(tabId, {code: 'init();faviconrestore();titleRestore();', allFrames: true});
215228
} else {
216229
chrome.tabs.executeScript(tabId, {code: "removeCss()", allFrames: true});
217230
}
218-
if (showIcon == 'true') {
231+
if (localStorage["showIcon"] == 'true') {
219232
if (enable == 'true') {
220233
chrome.pageAction.setIcon({path: "img/addressicon/"+dpicon+".png", tabId: tabId});
221234
} else {
@@ -230,11 +243,11 @@ function dpHandle(tab) {
230243
if (localStorage["enable"] == "true") {
231244
localStorage["enable"] = "false";
232245
// Remove cloak in all windows and tabs.
233-
recursiveCloak('false', 'true', localStorage["showIcon"], localStorage["disableFavicons"], localStorage["hidePageTitles"], localStorage["pageTitleText"]);
246+
recursiveCloak('false', 'true');
234247
} else {
235248
localStorage["enable"] = "true";
236249
// Activate cloak in all windows and tabs.
237-
recursiveCloak('true', 'true', localStorage["showIcon"], localStorage["disableFavicons"], localStorage["hidePageTitles"], localStorage["pageTitleText"]);
250+
recursiveCloak('true', 'true');
238251
}
239252
} else {
240253
var dpcloakindex = cloakedTabs.indexOf(tab.id);
@@ -243,11 +256,11 @@ function dpHandle(tab) {
243256
if (dpcloakindex != -1) {
244257
if (dpuncloakindex == -1) uncloakedTabs.push(tab.id);
245258
cloakedTabs.splice(dpcloakindex, 1);
246-
magician('false', localStorage["showIcon"], localStorage["disableFavicons"], localStorage["hidePageTitles"], localStorage["pageTitleText"], tab.id);
259+
magician('false', tab.id);
247260
} else {
248261
if (dpcloakindex == -1) cloakedTabs.push(tab.id);
249262
uncloakedTabs.splice(dpuncloakindex, 1);
250-
magician('true', localStorage["showIcon"], localStorage["disableFavicons"], localStorage["hidePageTitles"], localStorage["pageTitleText"], tab.id);
263+
magician('true', tab.id);
251264
}
252265
}
253266
}
@@ -265,7 +278,7 @@ chrome.tabs.onUpdated.addListener(function(tabid, changeinfo, tab) {
265278
if (dpcloakindex == -1) cloakedTabs.push(tabid);
266279
// Cloak page if it meets the criteria
267280
if (dpcheck) {
268-
magician(enabled(tab.url), localStorage["showIcon"], localStorage["disableFavicons"], localStorage["hidePageTitles"], localStorage["pageTitleText"], tabid);
281+
magician(enabled(tab.url), tabid);
269282
if (dpdomaincheck != 1 && localStorage["global"] == "false") localStorage["enable"] = "true";
270283
}
271284
if (localStorage["showIcon"] == "true") {
@@ -282,7 +295,7 @@ chrome.tabs.onUpdated.addListener(function(tabid, changeinfo, tab) {
282295
if (tab.openerTabId) {
283296
if (cloakedTabs.indexOf(tab.openerTabId) != -1 && dpuncloakindex == -1) {
284297
if (dpcloakindex == -1) cloakedTabs.push(tabid);
285-
magician('true', localStorage["showIcon"], localStorage["disableFavicons"], localStorage["hidePageTitles"], localStorage["pageTitleText"], tabid);
298+
magician('true', tabid);
286299
}
287300
}
288301
}
@@ -308,23 +321,32 @@ var requestDispatchTable = {
308321
if (localStorage["savedsfwmode"] != "") {
309322
localStorage["sfwmode"] = localStorage["savedsfwmode"];
310323
localStorage["savedsfwmode"] = "";
324+
if (localStorage["global"] == "true") {
325+
recursiveCloak('true', 'true');
326+
} else {
327+
var dpuncloakindex = uncloakedTabs.indexOf(sender.tab.id);
328+
if (dpuncloakindex != -1) uncloakedTabs.splice(dpuncloakindex, 1);
329+
if (cloakedTabs.indexOf(sender.tab.id) == -1) cloakedTabs.push(sender.tab.id);
330+
magician('true', sender.tab.id);
331+
}
332+
localStorage["enable"] = "true";
333+
} else {
334+
dpHandle(sender.tab);
311335
}
312-
dpHandle(sender.tab);
313336
},
314337
"toggleparanoid": function(request, sender, sendResponse) {
315338
if (localStorage["savedsfwmode"] == "") {
316339
localStorage["savedsfwmode"] = localStorage["sfwmode"];
317340
localStorage["sfwmode"] = "Paranoid";
318341
if (localStorage["global"] == "true") {
319-
recursiveCloak('true', 'true', localStorage["showIcon"], localStorage["disableFavicons"], localStorage["hidePageTitles"], localStorage["pageTitleText"]);
320-
localStorage["enable"] = "true";
342+
recursiveCloak('true', 'true');
321343
} else {
322344
var dpuncloakindex = uncloakedTabs.indexOf(sender.tab.id);
323345
if (dpuncloakindex != -1) uncloakedTabs.splice(dpuncloakindex, 1);
324346
if (cloakedTabs.indexOf(sender.tab.id) == -1) cloakedTabs.push(sender.tab.id);
325-
magician('true', localStorage["showIcon"], localStorage["disableFavicons"], localStorage["hidePageTitles"], localStorage["pageTitleText"], sender.tab.id);
326-
localStorage["enable"] = "true";
347+
magician('true', sender.tab.id);
327348
}
349+
localStorage["enable"] = "true";
328350
} else {
329351
localStorage["sfwmode"] = localStorage["savedsfwmode"];
330352
localStorage["savedsfwmode"] = "";

js/dp.js

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Supporting functions by AdThwart - T. Joseph
44
var origtitle;
55
var postloaddelay;
6+
var dphotkeylistener;
67
var timestamp = Math.round(new Date().getTime()/1000.0);
78
function addCloak(sfw, f, fsize, u, bg, text, table, link, bold, o1, o2, collapseimage) {
89
// Inject CSS into page
@@ -124,8 +125,8 @@ function dpPostLoad(dpheight, dpwidth, sfwmode, bold) {
124125
}
125126
}
126127
function removeCss(name) {
127-
if (typeof(name) === 'undefined') name = "productivity"+timestamp;
128-
jQuery("style[__decreased__='"+name+"']").remove();
128+
if (typeof(name) === 'undefined') jQuery("style[__decreased__='productivity"+timestamp+"']").remove();
129+
else jQuery("style[__decreased__='"+name+"']").remove();
129130
if (typeof(name) === 'undefined') {
130131
faviconrestore();
131132
titleRestore();
@@ -171,7 +172,7 @@ function faviconclear() {
171172
}
172173
function faviconrestore() {
173174
jQuery("link#decreasedproductivity"+timestamp).remove();
174-
jQuery("link:not(.intro)[data-rel='shortcut icon'], link[data-rel='icon']").each(function() {
175+
jQuery("link[data-rel='shortcut icon'], link[data-rel='icon']").each(function() {
175176
jQuery(this).attr('rel', jQuery(this).attr('data-rel')).removeAttr('data-rel');
176177
});
177178
}
@@ -192,23 +193,27 @@ function titleRestore() {
192193
jQuery('title').unbind('DOMSubtreeModified.decreasedproductivity'+timestamp);
193194
if (origtitle) document.title = origtitle;
194195
}
196+
function hotkeySet(hotkeyenabled, hotkey, paranoidhotkey) {
197+
if (dphotkeylistener) dphotkeylistener.reset();
198+
if (hotkeyenabled == 'true') {
199+
dphotkeylistener = new window.keypress.Listener();
200+
if (hotkey) {
201+
dphotkeylistener.simple_combo(hotkey.toLowerCase(), function() {
202+
chrome.extension.sendRequest({reqtype: "toggle"});
203+
});
204+
}
205+
if (paranoidhotkey) {
206+
dphotkeylistener.simple_combo(paranoidhotkey.toLowerCase(), function() {
207+
chrome.extension.sendRequest({reqtype: "toggleparanoid"});
208+
});
209+
}
210+
}
211+
}
195212
// Initially hide all elements on page (injected code is removed when page is loaded)
196213
chrome.extension.sendRequest({reqtype: "get-enabled"}, function(response) {
197-
if (response.enableToggle == 'true') {
198-
jQuery(document).ready(function() {
199-
var listener = new window.keypress.Listener();
200-
if (response.hotkey) {
201-
listener.simple_combo(response.hotkey.toLowerCase(), function() {
202-
chrome.extension.sendRequest({reqtype: "toggle"});
203-
});
204-
}
205-
if (response.paranoidhotkey) {
206-
listener.simple_combo(response.paranoidhotkey.toLowerCase(), function() {
207-
chrome.extension.sendRequest({reqtype: "toggleparanoid"});
208-
});
209-
}
210-
});
211-
}
214+
jQuery(document).ready(function() {
215+
hotkeySet(response.enableToggle, response.hotkey, response.paranoidhotkey);
216+
});
212217
if (response.enable == "true") {
213218
if (response.favicon == 'true') faviconblank();
214219
if (response.hidePageTitles == 'true') {

js/options.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ function saveOptions() {
325325
error = true;
326326
}
327327
// Apply new settings
328-
bkg.recursiveCloak(localStorage["enable"], localStorage["global"], localStorage["showIcon"], localStorage["disableFavicons"], localStorage["hidePageTitles"], localStorage["pageTitleText"]);
328+
bkg.recursiveCloak(localStorage["enable"], localStorage["global"]);
329+
bkg.hotkeyChange();
329330
// Remove any existing styling
330331
if (!error) notification(chrome.i18n.getMessage("saved"));
331332
else notification(chrome.i18n.getMessage("invalidcolour"));

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
},
2828
"permissions": [ "http://*/*", "https://*/*", "contextMenus", "tabs" ],
2929
"update_url": "http://clients2.google.com/service/update2/crx",
30-
"version": "0.46.53"
30+
"version": "0.46.53.1"
3131
}

updated.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
<body id="updatepage">
88
<span id="title">Decreased Productivity</span> by Andrew Y.<br /><br />
99
<div id="main">
10-
<h1>Updated to v0.46.53! (Thursday, May 5, 2016)</h1>
10+
<h1>Updated to v0.46.53.1! (Thursday, May 5, 2016)</h1>
1111
<ul>
12-
<li>v0.46.53:<ul>
12+
<li>v0.46.53.1:<ul>
13+
<li>v0.46.53.1 = tweaked Paranoid Mode to Cloak behaviour, fixed page favicon and page titles toggling, and hotkey changes now take effect immediately</li>
1314
<li>updated core DP cloaking functions so that DP Option setting changes and the Paranoid Hotkey toggle take effect immediately (without temporarily uncloaking and recloaking open tabs)</li>
1415
<li>optimized number of calls when cloaking a page (from potentially up to 3 down to just 1)</li>
1516
<li>tweaked page favicon cloaking so it is now instant</li>

0 commit comments

Comments
 (0)