Skip to content

Commit

Permalink
v0.46.56.7
Browse files Browse the repository at this point in the history
  • Loading branch information
andryou committed Jul 25, 2016
1 parent 4a5e192 commit ba23e9f
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 21 deletions.
16 changes: 16 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
"description": "Text",
"message": "Text"
},
"customcss": {
"description": "Enter custom CSS code to be applied to all websites (advanced users)",
"message": "Enter custom CSS code to be applied to all websites (advanced users)"
},
"darkbrown": {
"description": "Dark Brown",
"message": "Dark Brown"
Expand Down Expand Up @@ -147,6 +151,14 @@
"description": "Hovered",
"message": "Hovered"
},
"importsuccessoptions": {
"description": "Settings imported successfully",
"message": "Settings imported successfully"
},
"importsuccesscond": {
"description": "Settings imported successfully, except the following (unrecognized name): ",
"message": "Settings imported successfully, except the following (unrecognized name): "
},
"invalidcolour": {
"description": "Your colors weren't saved as one or more were invalid. Please revert your colors or re-enter a correct color.",
"message": "Your colors weren't saved as one or more were invalid. Please revert your colors or re-enter a correct color."
Expand Down Expand Up @@ -195,6 +207,10 @@
"description": "Paranoid (hide everything)",
"message": "Paranoid (hide everything)"
},
"pastesettings": {
"description": "Paste in settings and try again",
"message": "Paste in settings and try again"
},
"people": {
"description": "People who bought Andrew coffee",
"message": "People who bought Andrew coffee"
Expand Down
16 changes: 16 additions & 0 deletions _locales/en_GB/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
"description": "Text",
"message": "Text"
},
"customcss": {
"description": "Enter custom CSS code to be applied to all websites (advanced users)",
"message": "Enter custom CSS code to be applied to all websites (advanced users)"
},
"darkbrown": {
"description": "Dark Brown",
"message": "Dark Brown"
Expand Down Expand Up @@ -147,6 +151,14 @@
"description": "Hovered",
"message": "Hovered"
},
"importsuccessoptions": {
"description": "Settings imported successfully",
"message": "Settings imported successfully"
},
"importsuccesscond": {
"description": "Settings imported successfully, except the following (unrecognized name): ",
"message": "Settings imported successfully, except the following (unrecognized name): "
},
"invalidcolour": {
"description": "Your colors weren't saved as one or more were invalid. Please revert your colors or re-enter a correct color.",
"message": "Your colours weren't saved as one or more were invalid. Please revert your colours or re-enter a correct colour."
Expand Down Expand Up @@ -195,6 +207,10 @@
"description": "Paranoid (hide everything)",
"message": "Paranoid (hide everything)"
},
"pastesettings": {
"description": "Paste in settings and try again",
"message": "Paste in settings and try again"
},
"people": {
"description": "People who bought Andrew coffee",
"message": "People who bought Andrew coffee"
Expand Down
16 changes: 16 additions & 0 deletions _locales/en_US/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
"description": "Text",
"message": "Text"
},
"customcss": {
"description": "Enter custom CSS code to be applied to all websites (advanced users)",
"message": "Enter custom CSS code to be applied to all websites (advanced users)"
},
"darkbrown": {
"description": "Dark Brown",
"message": "Dark Brown"
Expand Down Expand Up @@ -147,6 +151,14 @@
"description": "Hovered",
"message": "Hovered"
},
"importsuccessoptions": {
"description": "Settings imported successfully",
"message": "Settings imported successfully"
},
"importsuccesscond": {
"description": "Settings imported successfully, except the following (unrecognized name): ",
"message": "Settings imported successfully, except the following (unrecognized name): "
},
"invalidcolour": {
"description": "Your colors weren't saved as one or more were invalid. Please revert your colors or re-enter a correct color.",
"message": "Your colors weren't saved as one or more were invalid. Please revert your colors or re-enter a correct color."
Expand Down Expand Up @@ -195,6 +207,10 @@
"description": "Paranoid (hide everything)",
"message": "Paranoid (hide everything)"
},
"pastesettings": {
"description": "Paste in settings and try again",
"message": "Paste in settings and try again"
},
"people": {
"description": "People who bought Andrew coffee",
"message": "People who bought Andrew coffee"
Expand Down
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v0.46.56.7 - Monday, July 25, 2016
- Added capability to Import/Export Settings (and even save your settings to a text file)
- Added option to add custom CSS
- Added support for cloaking of <canvas> elements

v0.46.56.6 - Tuesday, June 21, 2016
- minor fixes and improved YouTube cloaking

Expand Down
8 changes: 5 additions & 3 deletions css/options.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ div#newPagesRow { font-size: 12px; }
div#pageTitle { font-size: 12px; }
a { color: blue; }
input[type=image] { opacity: 0.5; }
#message { z-index: 999; color: #000; margin: 5px; position: fixed; top: 0; left: 0; padding: 5px; font-weight: bold; border: 1px solid #ffcc66; background-color: #ffffcc; }
#main:hover, input[type=image]:hover { opacity: 1; }
#test { width: 411px; height: 188px; background-image: url('../img/option/demo/background.png'); }
.list { width: 250px; max-height: 300px; overflow-y: auto; border: 1px solid #ccc; background-color: #eee; padding: 5px; }
.listentry:hover { background-color: #fff; }
.list, textarea { width: 250px; max-height: 300px; overflow-y: auto; border: 1px solid #ccc; background-color: #eee; padding: 5px; }
textarea { min-height: 100px; font-family: Arial, Sans-Serif; }
#customcss { width: 100%; height: 200px; }
.listentry:hover, #customcss, #settingsimport { background-color: #fff; }
.clear { clear: both; }
.right, #sampleimage { float: right; }
.message { display: none; color: #000; margin-top: 5px; }
.hide { display: none; }
#listMsg { display: none; color: #000; margin-left: 5px; }
#demo_favicon {
Expand Down
10 changes: 7 additions & 3 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ function setDefaultOptions() {
defaultOptionValue("s_link", "000099");
defaultOptionValue("s_table", "cccccc");
defaultOptionValue("s_text", "000000");
defaultOptionValue("customcss", "");
// fix hotkey shortcut if in old format (if using + as separator instead of space)
if (localStorage["hotkey"].indexOf('+') != -1) {
localStorage["hotkey"] = localStorage["hotkey"].replace(/\+$/, "APLUSA").replace(/\+/g, " ").replace(/APLUSA/, "+");
Expand Down Expand Up @@ -319,6 +320,10 @@ function setDPIcon() {
});
});
}
function initLists() {
blackList = JSON.parse(localStorage['blackList']).sort();
whiteList = JSON.parse(localStorage['whiteList']).sort();
}
// ----- Request library to support content script communication
chrome.tabs.onUpdated.addListener(function(tabid, changeinfo, tab) {
if (changeinfo.status == "loading") {
Expand Down Expand Up @@ -426,7 +431,7 @@ var requestDispatchTable = {
} else fontface = localStorage["font"];
if (localStorage["global"] == "false") enable = 'true';
else enable = enabled(sender.tab);
sendResponse({enable: enable, sfwmode: localStorage["sfwmode"], font: fontface, fontsize: localStorage["fontsize"], underline: localStorage["showUnderline"], background: localStorage["s_bg"], text: localStorage["s_text"], table: localStorage["s_table"], link: localStorage["s_link"], bold: localStorage["removeBold"], opacity1: localStorage["opacity1"], opacity2: localStorage["opacity2"], collapseimage: localStorage["collapseimage"], maxheight: localStorage["maxheight"], maxwidth: localStorage["maxwidth"]});
sendResponse({enable: enable, sfwmode: localStorage["sfwmode"], font: fontface, fontsize: localStorage["fontsize"], underline: localStorage["showUnderline"], background: localStorage["s_bg"], text: localStorage["s_text"], table: localStorage["s_table"], link: localStorage["s_link"], bold: localStorage["removeBold"], opacity1: localStorage["opacity1"], opacity2: localStorage["opacity2"], collapseimage: localStorage["collapseimage"], maxheight: localStorage["maxheight"], maxwidth: localStorage["maxwidth"], customcss: localStorage["customcss"]});
}
}
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
Expand All @@ -440,8 +445,7 @@ chrome.pageAction.onClicked.addListener(function(tab) {
// Execute
setDefaultOptions();
// save blacklist and whitelist in global variable for faster lookups
blackList = JSON.parse(localStorage['blackList']).sort();
whiteList = JSON.parse(localStorage['whiteList']).sort();
initLists();
setDPIcon();
dpContext();
if ((!optionExists("version") || localStorage["version"] != version) && localStorage["showUpdateNotifications"] == 'true') {
Expand Down
11 changes: 6 additions & 5 deletions js/dp.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var origtitle;
var postloaddelay;
var dphotkeylistener;
var timestamp = Math.round(new Date().getTime()/1000.0);
function addCloak(sfw, f, fsize, u, bg, text, table, link, bold, o1, o2, collapseimage) {
function addCloak(sfw, f, fsize, u, bg, text, table, link, bold, o1, o2, collapseimage, customcss) {
// Inject CSS into page
var cssinject = document.createElement("style");
cssinject.setAttribute("__decreased__", "productivity"+timestamp);
Expand Down Expand Up @@ -41,15 +41,15 @@ function addCloak(sfw, f, fsize, u, bg, text, table, link, bold, o1, o2, collaps
else magic += 'none !important; }';

if (sfw == 'SFW' || sfw == 'SFW1' || sfw == 'SFW2') {
if (o1 == 0 && collapseimage == 'true') magic += ' iframe, img, input[type=image], path, polygon, picture { display: none !important; }';
else magic += ' iframe, img, input[type=image], path, polygon, picture { opacity: '+o1+' !important; } iframe:hover, img:hover, input[type=image]:hover, path:hover, polygon:hover { opacity: '+o2+' !important; }';
if (o1 == 0 && collapseimage == 'true') magic += ' iframe, img, canvas, input[type=image], path, polygon, picture { display: none !important; }';
else magic += ' iframe, img, canvas, input[type=image], path, polygon, picture { opacity: '+o1+' !important; } iframe:hover, img:hover, input[type=image]:hover, path:hover, polygon:hover { opacity: '+o2+' !important; }';
}
if (sfw == 'SFW') {
if (o1 == 0 && collapseimage == 'true') magic += ' object, embed, param, video, audio { display: none !important; }';
else magic += ' object, embed, param, video, audio { opacity: '+o1+' !important; } object:hover, embed:hover, param:hover, video:hover, audio:hover { opacity: '+o2+' !important; }';
}
if (sfw == 'SFW1') magic += ' object, embed, param, video, audio { display: none !important; opacity: 0 !important; }';
if (sfw == 'Paranoid') magic += ' iframe, img, input[type=image], path, polygon, object, embed, param, video, audio, picture { display: none !important; opacity: 0 !important; }';
if (sfw == 'Paranoid') magic += ' iframe, img, canvas, input[type=image], path, polygon, object, embed, param, video, audio, picture { display: none !important; opacity: 0 !important; }';

magic += ' .dp'+timestamp+'_visible { visibility: visible !important; opacity: 1 !important; }';
magic += ' .dp'+timestamp+'_unbold { font-weight: normal !important }';
Expand Down Expand Up @@ -96,6 +96,7 @@ function addCloak(sfw, f, fsize, u, bg, text, table, link, bold, o1, o2, collaps
magic += ' .res-nightmode #header-bottom-right a, .res-nightmode a.title, .res-nightmode a.title:visited, .res-nightmode .RES-keyNav-activeElement > .tagline, .res-nightmode .RES-keyNav-activeElement .md-container > .md, .res-nightmode .RES-keyNav-activeElement .md-container > .md p, .res-nightmode #search input[type="text"] { color: #' + text + ' !important; } ';
magic += ' .usertext-edit textarea { border: 1px dotted #' + table + ' !important; } ';
}
if (customcss) magic += customcss.replace(/(?:\r\n|\r|\n)/g, ' ');
removeCss('initialstealth'+timestamp);
if (jQuery("style[__decreased__='productivity"+timestamp+"']").length) {
jQuery("style[__decreased__='productivity"+timestamp+"']").remove();
Expand Down Expand Up @@ -139,7 +140,7 @@ function removeCss(name) {
function init() {
chrome.extension.sendRequest({reqtype: "get-settings"}, function(response) {
if (response.enable == "true") {
addCloak(response.sfwmode, response.font, response.fontsize, response.underline, response.background, response.text, response.table, response.link, response.bold, response.opacity1, response.opacity2, response.collapseimage);
addCloak(response.sfwmode, response.font, response.fontsize, response.underline, response.background, response.text, response.table, response.link, response.bold, response.opacity1, response.opacity2, response.collapseimage, response.customcss);
dpPostLoad(response.maxheight, response.maxwidth, response.sfwmode, response.bold);
jQuery('body').unbind('DOMSubtreeModified.decreasedproductivity'+timestamp);
jQuery('body').bind('DOMSubtreeModified.decreasedproductivity'+timestamp, function() {
Expand Down
77 changes: 75 additions & 2 deletions js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var version = (function () {
var bkg = chrome.extension.getBackgroundPage();
var error = false;
var oldglobalstate = false;
var settingnames = [];
document.addEventListener('DOMContentLoaded', function () {
$("#tabs").tabs();
$("#o1").slider({min: 0, max: 1, step: 0.05, slide: function(event, ui) { $("#opacity1").val(ui.value); opacitytest(); }, stop: function(event, ui) {
Expand All @@ -36,7 +37,7 @@ document.addEventListener('DOMContentLoaded', function () {
}
});
$("#enable, #enableToggle, #enableStickiness, #disableFavicons, #hidePageTitles, #showUnderline, #collapseimage, #removeBold, #showContext, #showIcon, #showUpdateNotifications").click(saveOptions);
$("#iconTitle").blur(saveOptions);
$("#iconTitle, #customcss").blur(saveOptions);
$("#s_bg, #s_text, #s_link, #s_table").keyup(updateDemo);
$("#global").click(function() {
saveOptions();
Expand Down Expand Up @@ -92,6 +93,9 @@ document.addEventListener('DOMContentLoaded', function () {
$("#s_preset").change(function() {
stylePreset($(this).val());
});
$("#settingsall").click(settingsall);
$("#importsettings").click(settingsImport);
$("#savetxt").click(downloadtxt);
$(".i18_close").click(closeOptions);
});
function keyhandle(keypressed) {
Expand Down Expand Up @@ -128,6 +132,12 @@ function saveElement(id) {
function closeOptions() {
window.open('', '_self', '');window.close();
}
function settingsall() {
selectAll('settingsexport');
}
function selectAll(id) {
$("#"+id).select();
}
function i18load() {
$("#title").html("Decreased Productivity v"+version);
$(".i18_default").html(chrome.i18n.getMessage("default"));
Expand Down Expand Up @@ -209,6 +219,7 @@ function i18load() {
$(".i18_translators").html(chrome.i18n.getMessage("translators"));
$(".i18_help").html(chrome.i18n.getMessage("help"));
$(".i18_support").html(chrome.i18n.getMessage("support"));
$("#customcssdesc").html(chrome.i18n.getMessage("customcss"));
$(".i18_supportimg").attr({alt: chrome.i18n.getMessage("support"), title: chrome.i18n.getMessage("support")});
}
function loadOptions() {
Expand Down Expand Up @@ -261,6 +272,7 @@ function loadOptions() {
$("#customfontrow").hide();
}
}
loadElement("customcss");
listUpdate();
opacitytest();
updateDemo();
Expand Down Expand Up @@ -325,6 +337,9 @@ function saveOptions() {
} else {
error = true;
}
$("#customcss").val($("#customcss").val().replace(/\s*<([^>]+)>\s*/ig, ""));
saveElement("customcss");
updateExport();
// Apply new settings
bkg.optionsSaveTrigger(oldglobalstate, localStorage["global"]);
bkg.hotkeyChange();
Expand Down Expand Up @@ -372,7 +387,7 @@ function fontsizeValidation() {
}

function notification(msg) {
$('.message').html(msg).stop().fadeIn("slow").delay(2000).fadeOut("slow")
$('#message').html(msg).stop().fadeIn("slow").delay(2000).fadeOut("slow")
}
function truncText(str) {
if (str.length > 16) return str.substr(0, 16)+'...';
Expand Down Expand Up @@ -509,6 +524,8 @@ function listUpdate() {
$('#blacklist').html(blacklistCompiled);
$(".domainRemover").unbind('click');
$(".domainRemover").click(function() { domainRemover($(this).attr('rel'));});
bkg.initLists();
updateExport();
}
function listclear(type) {
if (confirm([chrome.i18n.getMessage("removefromwhitelist"),chrome.i18n.getMessage("removefromblacklist")][type]+'?')) {
Expand Down Expand Up @@ -537,4 +554,60 @@ function colorPickLoad(id) {
updateDemo();
}
});
}

function downloadtxt() {
var textToWrite = $("#settingsexport").val();
var textFileAsBlob = new Blob([textToWrite], {type:'text/plain'});
var fileNameToSaveAs = "dp-settings-"+new Date().toJSON()+".txt";
var downloadLink = document.createElement("a");
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = "Download File";
downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
downloadLink.click();
downloadLink.remove();
}
function updateExport() {
$("#settingsexport").val("");
settingnames = [];
for (var i in localStorage) {
if (i != "version") {
settingnames.push(i);
$("#settingsexport").val($("#settingsexport").val()+i+"|"+localStorage[i].replace(/(?:\r\n|\r|\n)/g, ' ')+"\n");
}
}
$("#settingsexport").val($("#settingsexport").val().slice(0,-1));
}
function settingsImport() {
var error = "";
var settings = $("#settingsimport").val().split("\n");
if ($.trim($("#settingsimport").val()) == "") {
notification(chrome.i18n.getMessage("pastesettings"));
return false;
}
if (settings.length > 0) {
$.each(settings, function(i, v) {
if ($.trim(v) != "") {
var settingentry = $.trim(v).split("|");
if (settingnames.indexOf($.trim(settingentry[0])) != -1) {
if ($.trim(settingentry[0]) == 'whiteList' || $.trim(settingentry[0]) == 'blackList') {
var listarray = $.trim(settingentry[1]).replace(/(\[|\]|")/g,"").split(",");
if ($.trim(settingentry[0]) == 'whiteList' && listarray.toString() != '') localStorage['whiteList'] = JSON.stringify(listarray);
else if ($.trim(settingentry[0]) == 'blackList' && listarray.toString() != '') localStorage['blackList'] = JSON.stringify(listarray);
} else
localStorage[$.trim(settingentry[0])] = $.trim(settingentry[1]);
} else {
error += $.trim(settingentry[0])+", ";
}
}
});
}
loadOptions();
listUpdate();
if (!error) {
notification(chrome.i18n.getMessage("importsuccessoptions"));
$("#settingsimport").val("");
} else {
notification(chrome.i18n.getMessage("importsuccesscond")+error.slice(0, -2));
}
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
},
"permissions": [ "http://*/*", "https://*/*", "contextMenus", "tabs" ],
"update_url": "http://clients2.google.com/service/update2/crx",
"version": "0.46.56.6"
"version": "0.46.56.7"
}
Loading

0 comments on commit ba23e9f

Please sign in to comment.