Prototype

Just able to log the token for the requested style.
This commit is contained in:
Gusted 2021-05-27 22:35:37 +02:00
parent 83a6808c67
commit 4a7c2445c8
No known key found for this signature in database
GPG Key ID: FD821B732837125F
5 changed files with 48 additions and 1 deletions

View File

@ -6,6 +6,7 @@
/* global prefs */
/* global tabMan */
/* global usercssMan */
/* global tokenMan */
'use strict';
/*
@ -54,6 +55,9 @@ const styleMan = (() => {
chrome.runtime.onConnect.addListener(handleLivePreview);
chrome.runtime.onConnect.addListener(handleLinkingUSW);
//#endregion
//#region Exports
@ -345,6 +349,19 @@ const styleMan = (() => {
});
}
function handleLinkingUSW(port) {
if (port.name !== 'link-style-usw') {
return;
}
port.onMessage.addListener(async style => {
if (!style.id) {
return;
}
const result = await tokenMan.getToken('userstylesworld', true);
console.log(result);
});
}
async function addIncludeExclude(type, id, rule) {
if (ready.then) await ready;
const style = Object.assign({}, id2style(id));

View File

@ -1,4 +1,4 @@
/* global FIREFOX getActiveTab waitForTabUrl */// toolbox.js
/* global FIREFOX getActiveTab waitForTabUrl URLS */// toolbox.js
/* global chromeLocal */// storage-util.js
'use strict';
@ -48,6 +48,14 @@ const tokenMan = (() => {
'https://' + location.hostname + '.chromiumapp.org/',
scopes: ['Files.ReadWrite.AppFolder', 'offline_access'],
},
userstylesworld: {
flow: 'code',
clientId: 'publicccc_client',
clientSecret: 'secreettUwU', // Don't judege.
authURL: URLS.usw + 'api/oauth/authorize_style',
tokenURL: URLS.usw + 'api/oauth/access_token',
redirect_uri: 'https://gusted.xyz/callback_helper/',
},
};
const NETWORK_LATENCY = 30; // seconds
@ -177,6 +185,7 @@ const tokenMan = (() => {
grant_type: 'authorization_code',
client_id: provider.clientId,
redirect_uri: query.redirect_uri,
state,
};
if (provider.clientSecret) {
body.client_secret = provider.clientSecret;

View File

@ -395,6 +395,9 @@
<summary><h2 i18n-text="sections"></h2></summary>
<ol id="toc"></ol>
</details>
<details id="debug">
<button id="debug-button">Link style</button>
</details>
<details id="lint" data-pref="editor.lint.expanded" class="hidden-unless-compact ignore-pref-if-compact">
<summary>
<h2 i18n-text="linterIssues">: <span id="issue-count"></span>

View File

@ -42,6 +42,8 @@ baseInit.ready.then(async () => {
require(['/edit/linter-dialogs'], () => linterMan.showLintConfig());
$('#lint-help').onclick = () =>
require(['/edit/linter-dialogs'], () => linterMan.showLintHelp());
$('#debug-button').onclick = () =>
require(['/edit/usw-debug'], () => linkToUSW()); /* global linkToUSW */
require([
'/edit/autocomplete',
'/edit/global-search',

16
edit/usw-debug.js Normal file
View File

@ -0,0 +1,16 @@
/* global editor */
'use strict';
let uswPort;
/* exported linkToUSW */
function linkToUSW() {
if (!uswPort) {
uswPort = chrome.runtime.connect({name: 'link-style-usw'});
uswPort.onDisconnect.addListener(err => {
throw err;
});
}
uswPort.postMessage(editor.style);
}