import styles from Stylish extension

This commit is contained in:
Jeremy Schomery 2017-01-11 15:25:38 +03:30
parent 458daf0836
commit 9582c65a84
5 changed files with 193 additions and 129 deletions

View File

@ -187,6 +187,31 @@
<div><input id="popup.stylesFirst" type="checkbox"><label id="stylesFirst-label" for="popup.stylesFirst" i18n-text="popupStylesFirst"></label></div>
<div><input id="analyticsEnabled" type="checkbox"><label id="analyticsEnabled-label" for="analyticsEnabled" i18n-text="analyticsEnabled"></label></div>
</div>
<div>
<h2>Export Styles from Stylish extension</h2>
<ul>
<li>Open chrome://extensions in a browser tab</li>
<li>Turn developer mode on</li>
<li>Find Stylish extension and press "background page"</li>
<li>Copy this script in the console tab and press Enter key</li>
<pre style='color:#000000;background:#eee; overflow: auto;'>getStyles({}, e => {
<span style='color:#7f0055; font-weight:bold; '>let</span> styles = JSON.stringify(e);
<span style='color:#7f0055; font-weight:bold; '>let</span> <span style='color:#7f0055; font-weight:bold; '>link</span> = document.createElement(<span style='color:#2a00ff; '>'</span><span style='color:#2a00ff; '>a</span><span style='color:#2a00ff; '>'</span>);
<span style='color:#7f0055; font-weight:bold; '>let</span> data = <span style='color:#7f0055; font-weight:bold; '>new</span> Blob([styles], {type: <span style='color:#2a00ff; '>'</span><span style='color:#2a00ff; '>text/plain;charset=utf-8;</span><span style='color:#2a00ff; '>'</span>});
<span style='color:#7f0055; font-weight:bold; '>link</span>.href = window.URL.createObjectURL(data);
<span style='color:#7f0055; font-weight:bold; '>link</span>.setAttribute(<span style='color:#2a00ff; '>'</span><span style='color:#2a00ff; '>download</span><span style='color:#2a00ff; '>'</span>, <span style='color:#2a00ff; '>'</span><span style='color:#2a00ff; '>styles.json</span><span style='color:#2a00ff; '>'</span>);
document.body.appendChild(<span style='color:#7f0055; font-weight:bold; '>link</span>);
<span style='color:#7f0055; font-weight:bold; '>link</span>.click();
document.body.removeChild(<span style='color:#7f0055; font-weight:bold; '>link</span>);
});
</pre>
<li>Use the import button to import "styles.json" file</li>
</ul>
</div>
<div>
<h2>Import Styles</h2>
<input id="import" type="file">
</div>
<p id="manage-text" i18n-html="manageText"></p>
</div>
<div id="installed"></div>

View File

@ -461,6 +461,37 @@ function initFilter(className, node) {
onFilterChange(className, {target: node});
}
function importStyles (e) {
var file = e.target.files[0];
var reader = new FileReader();
var styles = [];
function save () {
var style = styles.shift();
if (style) {
delete style.id;
saveStyle(style, save);
}
else {
window.location.reload()
}
}
reader.onloadend = function (evt) {
try {
styles = JSON.parse(evt.target.result);
save();
}
catch (e) {
window.alert(e.message);
}
};
reader.onerror = function (e) {
window.alert(e.message);
}
reader.readAsText(file)
}
document.addEventListener("DOMContentLoaded", function() {
installed = document.getElementById("installed");
if (document.stylishStyles) {
@ -473,6 +504,8 @@ document.addEventListener("DOMContentLoaded", function() {
document.getElementById("search").addEventListener("input", searchStyles);
searchStyles(true); // re-apply filtering on history Back
document.getElementById('import').addEventListener('change', importStyles);
setupLivePrefs([
"manage.onlyEnabled",
"manage.onlyEdited",
@ -482,4 +515,5 @@ document.addEventListener("DOMContentLoaded", function() {
]);
initFilter("enabled-only", document.getElementById("manage.onlyEnabled"));
initFilter("edited-only", document.getElementById("manage.onlyEdited"));
});

132
popup.css Normal file
View File

@ -0,0 +1,132 @@
body {
width: 300px;
font-size: 13px;
font-family: Arial,"Helvetica Neue",Helvetica,sans-serif;
}
input[type=checkbox] {
outline: none;
}
#no-styles {
font-style: italic;
}
.checker {
display: inline;
}
.style-name {
cursor: default;
font-weight: bold;
margin-bottom: 2px;
display: block;
}
.actions {
font-size: x-small;
}
a, a:visited {
color: black;
}
.left-gutter {
display: table-cell;
width: 16px;
vertical-align: top;
}
.left-gutter input {
margin-top: 0;
margin-left: 0;
}
.main-controls {
display: table-cell;
}
.entry {
padding: 0.5em 0;
border-bottom: 1px solid black;
}
.entry:first-child {
padding-top: 0;
}
.entry:last-child {
border-bottom: none;
}
body > DIV {
border-bottom: 1px solid black;
padding-bottom: 2px;
}
body > DIV:last-of-type,
body.blocked > DIV {
border-bottom: none;
}
#installed {
margin-top: 0.5em;
}
#installed.disabled .style-name {
text-decoration: line-through;
}
#installed .actions a {
margin-right: 0.2em;
}
body > .actions {
margin-top: 0.5em;
}
.actions > div:not(:last-child):not(#disable-all-wrapper), .actions > .main-controls > div:not(:last-child), #unavailable:not(:last-child), #unavailable + .actions {
margin-bottom: 0.75em;
}
.actions input, .actions label {
vertical-align: middle;
}
#unavailable {
border: none;
display: none;
}
body.blocked #installed,
body.blocked #find-styles,
body.blocked #write-style,
body:not(.blocked) #unavailable {
display: none;
}
/* Never shown, but can be enabled with a style */
.enable, .disable {
display: none;
}
/* 'New style' links */
#write-style-for {margin-right: .6ex}
.write-style-link {margin-left: .6ex}
.write-style-link::before, .write-style-link::after {font-size: x-small}
.write-style-link::before {content: "\00ad"} /* "soft" hyphen */
#match {overflow-wrap: break-word;}
/* "breadcrumbs" 'new style' links */
.breadcrumbs > .write-style-link {margin-left: 0}
.breadcrumbs:hover a {color: #bbb; text-decoration: none}
/* use just the subdomain name instead of the full domain name */
.breadcrumbs > .write-style-link[subdomain]:not(:nth-last-child(2)) {font-size: 0}
.breadcrumbs > .write-style-link[subdomain]:not(:nth-last-child(2))::before {
content: attr(subdomain);
}
/* "dot" after each subdomain name */
.breadcrumbs > .write-style-link[subdomain]::after {content: "."}
/* no "dot" after top-level domain */
.breadcrumbs > .write-style-link:nth-last-child(2)::after {content: none}
/* "forward slash" before path ("this URL") */
.breadcrumbs > .write-style-link:last-child::before {content: "\200b/"}
.breadcrumbs > .write-style-link:last-child:first-child::before,
.breadcrumbs > .write-style-link[subdomain=""] + .write-style-link::before {content: none}
/* suppress TLD-only link */
.breadcrumbs > .write-style-link[subdomain=""] {display: none}
/* :hover style */
.breadcrumbs.url\(\) > .write-style-link, /* :hover or :focus on "this URL" sets class="url()" */
.breadcrumbs > .write-style-link:hover,
.breadcrumbs > .write-style-link:focus,
.breadcrumbs > .write-style-link:hover ~ .write-style-link[subdomain],
.breadcrumbs > .write-style-link:focus ~ .write-style-link[subdomain] {
color: inherit;
text-decoration: underline;
}

View File

@ -1,135 +1,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<style>
body {
width: 200px;
}
#no-styles {
font-style: italic;
}
.checker {
display: inline;
}
.style-name {
cursor: default;
font-weight: bold;
margin-bottom: 2px;
display: block;
}
.actions {
font-size: x-small;
}
a, a:visited {
color: black;
}
.left-gutter {
display: table-cell;
width: 16px;
vertical-align: top;
}
.left-gutter input {
margin-top: 0;
margin-left: 0;
}
.main-controls {
display: table-cell;
}
.entry {
padding: 0.5em 0;
border-bottom: 1px solid black;
}
.entry:first-child {
padding-top: 0;
}
.entry:last-child {
border-bottom: none;
}
body > DIV {
border-bottom: 1px solid black;
padding-bottom: 2px;
}
body > DIV:last-of-type,
body.blocked > DIV {
border-bottom: none;
}
#installed {
margin-top: 0.5em;
}
#installed.disabled .style-name {
text-decoration: line-through;
}
#installed .actions a {
margin-right: 0.2em;
}
body > .actions {
margin-top: 0.5em;
}
.actions > div:not(:last-child):not(#disable-all-wrapper), .actions > .main-controls > div:not(:last-child), #unavailable:not(:last-child), #unavailable + .actions {
margin-bottom: 0.75em;
}
.actions input, .actions label {
vertical-align: middle;
}
#unavailable {
border: none;
display: none;
}
body.blocked #installed,
body.blocked #find-styles,
body.blocked #write-style,
body:not(.blocked) #unavailable {
display: none;
}
/* Never shown, but can be enabled with a style */
.enable, .disable {
display: none;
}
/* 'New style' links */
#write-style-for {margin-right: .6ex}
.write-style-link {margin-left: .6ex}
.write-style-link::before, .write-style-link::after {font-size: x-small}
.write-style-link::before {content: "\00ad"} /* "soft" hyphen */
#match {overflow-wrap: break-word;}
/* "breadcrumbs" 'new style' links */
.breadcrumbs > .write-style-link {margin-left: 0}
.breadcrumbs:hover a {color: #bbb; text-decoration: none}
/* use just the subdomain name instead of the full domain name */
.breadcrumbs > .write-style-link[subdomain]:not(:nth-last-child(2)) {font-size: 0}
.breadcrumbs > .write-style-link[subdomain]:not(:nth-last-child(2))::before {
content: attr(subdomain);
}
/* "dot" after each subdomain name */
.breadcrumbs > .write-style-link[subdomain]::after {content: "."}
/* no "dot" after top-level domain */
.breadcrumbs > .write-style-link:nth-last-child(2)::after {content: none}
/* "forward slash" before path ("this URL") */
.breadcrumbs > .write-style-link:last-child::before {content: "\200b/"}
.breadcrumbs > .write-style-link:last-child:first-child::before,
.breadcrumbs > .write-style-link[subdomain=""] + .write-style-link::before {content: none}
/* suppress TLD-only link */
.breadcrumbs > .write-style-link[subdomain=""] {display: none}
/* :hover style */
.breadcrumbs.url\(\) > .write-style-link, /* :hover or :focus on "this URL" sets class="url()" */
.breadcrumbs > .write-style-link:hover,
.breadcrumbs > .write-style-link:focus,
.breadcrumbs > .write-style-link:hover ~ .write-style-link[subdomain],
.breadcrumbs > .write-style-link:focus ~ .write-style-link[subdomain] {
color: inherit;
text-decoration: underline;
}
</style>
<link rel="stylesheet" href="popup.css">
<template data-id="style">
<div>

View File

@ -97,6 +97,7 @@ function saveStyle(o, callback) {
var os = tx.objectStore("styles");
// Update
console.error(o)
if (o.id) {
var request = os.get(Number(o.id));
request.onsuccess = function(event) {