Patch up several things

This commit is contained in:
Gusted 2021-05-30 23:57:51 +02:00
parent 621e4ce6fd
commit cc928d6e5a
No known key found for this signature in database
GPG Key ID: FD821B732837125F
5 changed files with 22 additions and 11 deletions

View File

@ -1366,8 +1366,20 @@
"description": "Header for the table of contents block listing style section names in the left panel of the classic editor" "description": "Header for the table of contents block listing style section names in the left panel of the classic editor"
}, },
"linking": { "linking": {
"message": "Linking", "message": "UserStyles.world integration",
"description": "Header for the section to link the style with other services." "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"
},
"revokeLink": {
"message": "Revoke Link",
"description": "Revoke current link of style with userstyles.world"
}, },
"shortcuts": { "shortcuts": {
"message": "Shortcuts", "message": "Shortcuts",

View File

@ -56,10 +56,8 @@ const styleMan = (() => {
let ready = init(); let ready = init();
chrome.runtime.onConnect.addListener(handleLivePreview); chrome.runtime.onConnect.addListener(handleLivePreview);
chrome.runtime.onConnect.addListener(handleLinkingUSW); chrome.runtime.onConnect.addListener(handleLinkingUSW);
//#endregion //#endregion
//#region Exports //#region Exports
@ -381,7 +379,8 @@ const styleMan = (() => {
if (!style._usw.token) { if (!style._usw.token) {
return; return;
} }
uploadStyle(style._usw.token, style); uploadStyle(style);
break;
} }
}); });
} }

View File

@ -14,11 +14,11 @@ async function retrieveStyleInformation(token) {
} }
/* exported uploadStyle */ /* exported uploadStyle */
async function uploadStyle(token, style) { async function uploadStyle(style) {
return (await (await fetch(`${URLS.usw}api/style/${style._usw.id}`, { return (await (await fetch(`${URLS.usw}api/style/${style._usw.id}`, {
method: 'POST', method: 'POST',
headers: new Headers({ headers: new Headers({
'Authorization': `Bearer ${token}`, 'Authorization': `Bearer ${style._usw.token}`,
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}), }),
body: JSON.stringify({ body: JSON.stringify({

View File

@ -395,12 +395,12 @@
<details id="linking" data-pref="editor.toc.expanded" class="ignore-pref-if-compact"> <details id="linking" data-pref="editor.toc.expanded" class="ignore-pref-if-compact">
<summary><h2 i18n-text="linking"></h2></summary> <summary><h2 i18n-text="linking"></h2></summary>
<div id="pre-linking"> <div id="pre-linking">
<button id="link-style">Link style</button> <button id="link-style" i18n-text="linkStyle"></button>
</div> </div>
<div id="after-linking"> <div id="after-linking">
<div> <div>
<button id="upload-style">Upload style</button> <button id="upload-style" i18n-text="uploadStyle"></button>
<button id="revoke-style">Revoke linking</button> <button id="revoke-link" i18n-text="revokeLink"></button>
</div> </div>
</div> </div>
</details> </details>

View File

@ -45,7 +45,7 @@ baseInit.ready.then(async () => {
$('#lint-help').onclick = () => $('#lint-help').onclick = () =>
require(['/edit/linter-dialogs'], () => linterMan.showLintHelp()); require(['/edit/linter-dialogs'], () => linterMan.showLintHelp());
$('#link-style').onclick = () => linkToUSW(); $('#link-style').onclick = () => linkToUSW();
$('#revoke-style').onclick = () => revokeLinking(); $('#revoke-link').onclick = () => revokeLinking();
$('#upload-style').onclick = () => uploadStyle(); $('#upload-style').onclick = () => uploadStyle();
require([ require([
'/edit/autocomplete', '/edit/autocomplete',