diff --git a/_locales/en/messages.json b/_locales/en/messages.json
index 8cb8f725..f8699dcc 100644
--- a/_locales/en/messages.json
+++ b/_locales/en/messages.json
@@ -1365,17 +1365,13 @@
"message": "Sections",
"description": "Header for the table of contents block listing style section names in the left panel of the classic editor"
},
- "linking": {
+ "integration": {
"message": "UserStyles.world integration",
"description": "Header for the section to link the style with userStyles.world"
},
- "linkStyle": {
- "message": "Link Style",
- "description": "Link the current style with userstyles.world"
- },
"uploadStyle": {
- "message": "Upload Style",
- "description": "Upload the current style to userstyles.world"
+ "message": "Publish Style",
+ "description": "Publish the current style to userstyles.world"
},
"revokeLink": {
"message": "Revoke Link",
diff --git a/background/style-manager.js b/background/style-manager.js
index eb814945..53d22a1f 100644
--- a/background/style-manager.js
+++ b/background/style-manager.js
@@ -56,7 +56,7 @@ const styleMan = (() => {
let ready = init();
chrome.runtime.onConnect.addListener(handleLivePreview);
- chrome.runtime.onConnect.addListener(handleLinkingUSW);
+ chrome.runtime.onConnect.addListener(handlePublishingUSW);
//#endregion
//#region Exports
@@ -349,7 +349,7 @@ const styleMan = (() => {
});
}
- function handleLinkingUSW(port) {
+ function handlePublishingUSW(port) {
if (port.name !== 'link-style-usw') {
return;
}
@@ -359,28 +359,32 @@ const styleMan = (() => {
return;
}
switch (reason) {
- case 'link':
- style._linking = true;
- saveStyle(style);
- style._usw = {
- token: await tokenMan.getToken('userstylesworld', true, style),
- };
- delete style._linking;
- for (const [k, v] of Object.entries(await retrieveStyleInformation(style._usw.token))) {
- style._usw[k] = v;
- }
- handleSave(await saveStyle(style), 'success-linking', true);
- break;
-
case 'revoke':
await tokenMan.revokeToken('userstylesworld', style.id);
style._usw = {};
handleSave(await saveStyle(style), 'success-revoke', true);
break;
- case 'upload':
- if (!style._usw.token) {
- return;
+ case 'publish':
+ if (!style._usw || !style._usw.token) {
+ style._linking = true;
+ await saveStyle(style);
+ const data = id2data(style.id);
+ if (!data) {
+ storeInMap(style);
+ } else {
+ data.style = style;
+ }
+
+ style._usw = {
+ token: await tokenMan.getToken('userstylesworld', true, style),
+ };
+
+ delete style._linking;
+ for (const [k, v] of Object.entries(await retrieveStyleInformation(style._usw.token))) {
+ style._usw[k] = v;
+ }
+ handleSave(await saveStyle(style), 'success-publishing', true);
}
uploadStyle(style);
break;
diff --git a/edit.html b/edit.html
index c4aad8ca..a48f96f9 100644
--- a/edit.html
+++ b/edit.html
@@ -59,7 +59,7 @@
-
+
@@ -392,16 +392,11 @@
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
diff --git a/edit/edit.js b/edit/edit.js
index df531ae9..8fccc7ef 100644
--- a/edit/edit.js
+++ b/edit/edit.js
@@ -11,7 +11,7 @@
/* global linterMan */
/* global prefs */
/* global t */// localization.js
-/* global updateUI linkToUSW revokeLinking uploadStyle */// usw-linking.js
+/* global updateUI revokeLinking publishStyle */// usw-integration.js
'use strict';
//#region init
@@ -44,9 +44,8 @@ baseInit.ready.then(async () => {
require(['/edit/linter-dialogs'], () => linterMan.showLintConfig());
$('#lint-help').onclick = () =>
require(['/edit/linter-dialogs'], () => linterMan.showLintHelp());
- $('#link-style').onclick = () => linkToUSW();
$('#revoke-link').onclick = () => revokeLinking();
- $('#upload-style').onclick = () => uploadStyle();
+ $('#publish-style').onclick = () => publishStyle();
require([
'/edit/autocomplete',
'/edit/global-search',
@@ -63,7 +62,7 @@ msg.onExtension(request => {
.then(newStyle => {
editor.replaceStyle(newStyle, request.codeIsUpdated);
- if (['success-linking', 'success-revoke'].includes(request.reason)) {
+ if (['success-publishing', 'success-revoke'].includes(request.reason)) {
updateUI(newStyle);
}
});
diff --git a/edit/usw-linking.js b/edit/usw-integration.js
similarity index 60%
rename from edit/usw-linking.js
rename to edit/usw-integration.js
index 54d58e4d..6e2dd072 100644
--- a/edit/usw-linking.js
+++ b/edit/usw-integration.js
@@ -14,13 +14,6 @@ function connectToPort() {
}
}
-/* exported linkToUSW */
-function linkToUSW() {
- connectToPort();
-
- const data = Object.assign(editor.style, {sourceCode: editor.getEditors()[0].getValue()});
- uswPort.postMessage({reason: 'link', data});
-}
/* exported revokeLinking */
function revokeLinking() {
@@ -29,11 +22,11 @@ function revokeLinking() {
uswPort.postMessage({reason: 'revoke', data: editor.style});
}
-/* exported uploadStyle */
-function uploadStyle() {
+/* exported publishStyle */
+function publishStyle() {
connectToPort();
const data = Object.assign(editor.style, {sourceCode: editor.getEditors()[0].getValue()});
- uswPort.postMessage({reason: 'upload', data});
+ uswPort.postMessage({reason: 'publish', data});
}
@@ -41,18 +34,16 @@ function uploadStyle() {
function updateUI(useStyle) {
const style = useStyle || editor.style;
if (style._usw && style._usw.token) {
- const afterLinking = $('#after-linking');
- afterLinking.style = '';
- $('#pre-linking').style = 'display: none;';
+ $('#revoke-link').style = '';
const linkInformation = $create('div', {id: 'link-info'}, [
$create('p', `Style name: ${style._usw.name}`),
$create('p', `Description: ${style._usw.description}`),
]);
$remove('#link-info');
- afterLinking.insertBefore(linkInformation, afterLinking.firstChild);
+ $('#integration').insertBefore(linkInformation, $('#integration').firstChild);
} else {
- $('#after-linking').style = 'display: none;';
- $('#pre-linking').style = '';
+ $('#revoke-link').style = 'display: none;';
+ $remove('#link-info');
}
}