Commit dd47eda7 authored by Marco Kellershoff's avatar Marco Kellershoff

Adds config import/export and Custom HTML field

parent ac385550
......@@ -4,7 +4,7 @@
"name": "Super Evil New Tab",
"short_name": "SENT",
"author":"Marco Kellershoff",
"version": "6.0.2",
"version": "6.0.3",
"description": "Fixes the super evil new tab page.",
"options_page": "options.html",
"permissions": [
......
......@@ -6,6 +6,15 @@
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
}
h1 {
color: #fc9867;
border-bottom: 2px solid #ab9dfd;
max-width: 50%;
}
h1 span {
color: #a9dc76;
}
kbd {
-moz-border-radius:3px;
-moz-box-shadow:0 1px 0 rgba(0,0,0,0.2),0 0 0 2px #fff inset;
......@@ -44,7 +53,7 @@ a:link,a:active,a:visited {
color: #666;
}
#javascriptEditor, #cssEditor {
#htmlEditor, #javascriptEditor, #cssEditor {
max-width: 95%;
width: 900px;
height: 550px;
......@@ -68,6 +77,44 @@ a:link,a:active,a:visited {
color: #333;
}
button {
font-family: 'Source Code Pro';
position: relative;
padding: 10px 40px;
margin: 0px 10px 10px 10px;
border-radius: 10px;
font-size: 18px;
color: #FFF;
text-decoration: none;
border: 1px solid #333;
}
#exportBtn {
background-color: #3498DB;
border-bottom: 5px solid #2980B9;
text-shadow: 0px -2px #2980B9;
}
#importBtn {
background-color: #E74C3C;
border-bottom: 5px solid #BD3E31;
text-shadow: 0px -2px #BD3E31;
}
#file {
display: none;
}
button:active {
transform: translate(0px,5px);
-webkit-transform: translate(0px,5px);
border-bottom: 1px solid;
}
nav {
margin-top: 20px;
}
footer {
color: #666;
position: fixed;
......
......@@ -8,7 +8,7 @@
</head>
<body>
<div id="contentwrapper">
<h1>Options for Hide Most Visited Pages Reloaded</h1>
<h1>Options for <span>Super Evil New Tab</span></h1>
<p>Press <kbd>CTRL</kbd> / <kbd></kbd> + <kbd>S</kbd> to save the configuration.</p>
<p>
To reset the configuration back to the default values,<br/>
......@@ -17,6 +17,13 @@
and press <kbd>CTRL</kbd> / <kbd></kbd> + <kbd>S</kbd>.
</p>
<p>This can mess up your newtab page pretty badly, so be cautious.</p>
<nav>
<button id="exportBtn">Export Configuration</button>
<button id="importBtn">Import Configuration</button>
<input id="file" name="file" type="file" accept=".json" />
</nav>
<h3>Custom HTML (inside <code>&lt;body&gt;</code> tag)</h3>
<div id="htmlEditor"></div>
<h3>Custom CSS</h3>
<div id="cssEditor"></div>
<h3>Custom JavaScript</h3>
......
(function(window, document) {
var saveAll;
function downloadDatastring(filename, datastr, mimetype) {
mimetype = mimetype || "text/plain"
var el = document.createElement('a');
el.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(datastr));
el.setAttribute('download', filename);
el.style.display = 'none';
document.body.appendChild(el);
el.click();
document.body.removeChild(el);
}
var EDITORS = [
["html", ace.edit('htmlEditor')],
["css", ace.edit('cssEditor')],
["javascript", ace.edit('javascriptEditor')]
];
......@@ -25,7 +38,21 @@
sender: 'editor|cli'
},
exec: function(env, args, request) {
saveAll();
saveAll("Configuration saved.");
}
});
var session = ed.getSession();
session.on("changeAnnotation", function () {
var annotations = session.getAnnotations() || [], i = len = annotations.length;
while (i--) {
if (/doctype first\. Expected/.test(annotations[i].text)) {
annotations.splice(i, 1);
} else if (/Unexpected End of file\. Expected/.test(annotations[i].text)) {
annotations.splice(i, 1);
}
}
if (len > annotations.length) {
session.setAnnotations(annotations);
}
});
});
......@@ -55,14 +82,18 @@
});
};
saveAll = function() {
saveAll = function(msg) {
var ed;
// CSS Edtior
// HTML Edtior
ed = EDITORS[0][1];
setOption("html", ed.getValue());
// CSS Edtior
ed = EDITORS[1][1];
setOption("css", ed.getValue());
// JavaScript Edtior
ed = EDITORS[1][1];
ed = EDITORS[2][1];
setOption("javascript", ed.getValue());
alert(msg);
};
getById = function(id) {
......@@ -71,23 +102,86 @@
// load editor contents
if (chrome && chrome.storage && chrome.storage.sync) {
chrome.storage.sync.get(["javascript", "css"], function(results) {
chrome.storage.sync.get(["html", "css", "javascript"], function(results) {
if (!results)
return;
if (results.html && results.html.length)
EDITORS[0][1].setValue(results.html, 1);
if (results.css && results.css.length)
EDITORS[0][1].setValue(results.css, 1);
EDITORS[1][1].setValue(results.css, 1);
if (results.javascript && results.javascript.length)
EDITORS[1][1].setValue(results.javascript, 1);
EDITORS[2][1].setValue(results.javascript, 1);
});
}
var onCtrlSCallback = function(evt) {
if (evt.ctrlKey === true && evt.key === 's') {
evt.preventDefault();
saveAll();
saveAll("Configuration saved.");
return false;
}
};
document.querySelector("#exportBtn").addEventListener("click", (evt) =>{
evt.preventDefault();
var ed, data;
data = {name: "Super Evil New Tab Configuration", data:{}};
// HTML Edtior
ed = EDITORS[0][1];
data.data.html = ed.getValue();
// CSS Edtior
ed = EDITORS[1][1];
data.data.css = ed.getValue();
// JavaScript Edtior
ed = EDITORS[2][1];
data.data.javascript = ed.getValue();
downloadDatastring("SuperEvilNewTab.conf.json", JSON.stringify(data), "application/json");
});
var loadFromFile = function(evt) {
var files = evt.target.files; // FileList object
var fr = new FileReader();
fr.onload = function(e) {
var json = JSON.parse(e.target.result);
try {
if (json.data) {
var keys = Object.keys(json.data);
keys.forEach((key) => {
switch(key) {
case "html":
EDITORS[0][1].setValue(json.data[key]);
break;
case "css":
EDITORS[1][1].setValue(json.data[key]);
break;
case "javascript":
EDITORS[2][1].setValue(json.data[key]);
break;
default:
break;
}
});
saveAll("Configuration imported and saved.");
}
} catch (ex) {
alert(ex.toString());
}
};
if (files && files.length) {
fr.readAsText(files[0]);
}
};
var fileInput = document.getElementById("file");
fileInput.addEventListener('change', loadFromFile, false);
document.getElementById("importBtn").addEventListener("click", (evt) => {
evt.preventDefault();
fileInput.click();
});
window.addEventListener('keydown', onCtrlSCallback);
})(window, document);
......@@ -14,12 +14,16 @@
let css = document.createElement("style");
let js = document.createElement("script");
getOption("css", (result) => {
css.innerHTML = result.css;
document.body.appendChild(css);
css.innerHTML = result.css;
document.querySelector("head").appendChild(css);
});
getOption("javascript", (result) => {
js.innerHTML = result.javascript;
document.body.appendChild(js);
getOption("html", (result) => {
if (result.html && result.html.length)
document.body.innerHTML = result.html;
getOption("javascript", (result) => {
js.innerHTML = result.javascript;
document.querySelector("head").appendChild(js);
});
});
};
boot();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment