diff --git a/background/style-manager.js b/background/style-manager.js index d8867387..6df2e9cf 100644 --- a/background/style-manager.js +++ b/background/style-manager.js @@ -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)); diff --git a/background/token-manager.js b/background/token-manager.js index 67cefe51..f1e4f550 100644 --- a/background/token-manager.js +++ b/background/token-manager.js @@ -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; diff --git a/edit.html b/edit.html index cd6bac6d..377db734 100644 --- a/edit.html +++ b/edit.html @@ -395,6 +395,9 @@

    +
    + +

    : diff --git a/edit/edit.js b/edit/edit.js index 95439259..6d20a3b8 100644 --- a/edit/edit.js +++ b/edit/edit.js @@ -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', diff --git a/edit/usw-debug.js b/edit/usw-debug.js new file mode 100644 index 00000000..5164d033 --- /dev/null +++ b/edit/usw-debug.js @@ -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); +}