diff --git a/_locales/en/messages.json b/_locales/en/messages.json
index 580ef244..76952976 100644
--- a/_locales/en/messages.json
+++ b/_locales/en/messages.json
@@ -165,6 +165,10 @@
"message": "Enable",
"description": "Label for the button to enable a style"
},
+ "exportLabel": {
+ "message": "Export",
+ "description": "Label for the button to export a style ('edit' page) or all styles ('manage' page)"
+ },
"findStylesForSite": {
"message": "Find more styles for this site.",
"description": "Text for a link that gets a list of styles for the current site"
@@ -181,6 +185,26 @@
"message": "Type a command name",
"description": "Placeholder text of inputbox in keymap help popup on the edit style page. Must be very short"
},
+ "importLabel": {
+ "message": "Import",
+ "description": "Label for the button to import a style ('edit' page) or all styles ('manage' page)"
+ },
+ "importAppendLabel": {
+ "message": "Append to style",
+ "description": "Label for the button to import a style and append to the existing sections"
+ },
+ "importAppendTooltip": {
+ "message": "Append the imported style to current style",
+ "description": "Tooltip for the button to import a style and append to the existing sections"
+ },
+ "importReplaceLabel": {
+ "message": "Overwrite style",
+ "description": "Label for the button to import and overwrite current style"
+ },
+ "importReplaceTooltip": {
+ "message": "Discard contents of current style and overwrite it with the imported style",
+ "description": "Label for the button to import and overwrite current style"
+ },
"installUpdate": {
"message": "Install update",
"description": "Label for the button to install an update for a single style"
@@ -322,13 +346,21 @@
"message": "Sections",
"description": "Title for the style sections section"
},
- "styleToMozillaFormat": {
- "message": "To Mozilla format",
- "description": "Label for the button that converts the code to Mozilla format"
+ "styleMozillaFormatHeading": {
+ "message": "Mozilla Format",
+ "description": "Heading for the section with buttons to import/export Mozilla format of the style"
+ },
+ "styleFromMozillaFormatPrompt": {
+ "message": "Paste the Mozilla-format code",
+ "description": "Prompt in the dialog displayed after clicking 'Import from Mozilla format' button"
+ },
+ "styleToMozillaFormatTitle": {
+ "message": "Style in Mozilla format",
+ "description": "Title of the popup with the style code in Mozilla format, shown after pressing the Export button on Edit style page"
},
"styleToMozillaFormatHelp": {
"message": "The Mozilla format of the code can be used with Stylish for Firefox and can be submitted to userstyles.org.",
- "description": "Help info for the button that converts the code to Mozilla format"
+ "description": "Help info for the Mozilla format header section that converts the code to/from Mozilla format"
},
"styleUpdate": {
"message": "Are you sure you want to update '$stylename$'?",
diff --git a/edit.html b/edit.html
index 8542773c..32c037b1 100644
--- a/edit.html
+++ b/edit.html
@@ -241,7 +241,7 @@
background-color: white;
box-shadow: 3px 3px 30px rgba(0, 0, 0, 0.5);
padding: 0.5rem;
- z-index: 9999;
+ z-index: 99;
}
#help-popup .title {
font-weight: bold;
@@ -282,6 +282,19 @@
padding-right: 0.5rem;
}
+ #help-popup button[name^="import"] {
+ line-height: 1.5rem;
+ padding: 0 0.5rem;
+ margin: 0.5rem 0 0 0.5rem;
+ pointer-events: none;
+ opacity: 0.5;
+ float: right;
+ }
+ #help-popup.ready button[name^="import"] {
+ pointer-events: all;
+ opacity: 1.0;
+ }
+
/************ lint ************/
#lint {
display: none;
@@ -528,9 +541,16 @@
-
-
-
+
+
+
+
+
+
+
+
+
+
diff --git a/edit.js b/edit.js
index 6f6dc026..9e0e0b10 100644
--- a/edit.js
+++ b/edit.js
@@ -24,6 +24,8 @@ Array.prototype.rotate = function(amount) { // negative amount == rotate left
return r;
}
+Object.defineProperty(Array.prototype, "last", {get: function() { return this[this.length - 1]; }});
+
// reroute handling to nearest editor when keypress resolves to one of these commands
var hotkeyRerouter = {
commands: {
@@ -134,13 +136,8 @@ function initCodeMirror() {
"Alt-PageUp": "prevEditor"
}
}
- mergeOptions(stylishOptions, CM.defaults);
- mergeOptions(userOptions, CM.defaults);
-
- function mergeOptions(source, target) {
- for (var key in source) target[key] = source[key];
- return target;
- }
+ shallowMerge(stylishOptions, CM.defaults);
+ shallowMerge(userOptions, CM.defaults);
// additional commands
CM.commands.jumpToLine = jumpToLine;
@@ -353,7 +350,7 @@ function indicateCodeChange(cm) {
}
function getSectionForCodeMirror(cm) {
- return cm.getTextArea().parentNode;
+ return cm.display.wrapper.parentNode;
}
function getCodeMirrorForSection(section) {
@@ -1086,6 +1083,7 @@ function initHooks() {
});
document.getElementById("to-mozilla").addEventListener("click", showMozillaFormat, false);
document.getElementById("to-mozilla-help").addEventListener("click", showToMozillaHelp, false);
+ document.getElementById("from-mozilla").addEventListener("click", fromMozillaFormat);
document.getElementById("beautify").addEventListener("click", beautify);
document.getElementById("save-button").addEventListener("click", save, false);
document.getElementById("sections-help").addEventListener("click", showSectionHelp, false);
@@ -1253,7 +1251,9 @@ function saveComplete(style) {
}
function showMozillaFormat() {
- window.open("data:text/plain;charset=UTF-8," + encodeURIComponent(toMozillaFormat()));
+ var popup = showCodeMirrorPopup(t("styleToMozillaFormatTitle"), "", {readOnly: true});
+ popup.codebox.setValue(toMozillaFormat());
+ popup.codebox.execCommand("selectAll");
}
function toMozillaFormat() {
@@ -1270,6 +1270,147 @@ function toMozillaFormat() {
}).join("\n\n");
}
+function fromMozillaFormat() {
+ var popup = showCodeMirrorPopup(t("styleFromMozillaFormatPrompt"), tHTML("