From b115e1c2d4f8203dc33311eb7ebef288ce3d3ae7 Mon Sep 17 00:00:00 2001 From: Gusted Date: Sat, 5 Jun 2021 17:11:18 +0200 Subject: [PATCH] Pass styleInfo trough usw's hook Related commit on USW: https://github.com/userstyles-world/userstyles.world/commit/461ddb03c703867d356235c90659a7f89f47df05 --- background/style-manager.js | 3 +++ background/token-manager.js | 12 +++--------- content/install-hook-userstylesworld.js | 7 +++++++ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/background/style-manager.js b/background/style-manager.js index d9279ff3..eb814945 100644 --- a/background/style-manager.js +++ b/background/style-manager.js @@ -360,9 +360,12 @@ const styleMan = (() => { } 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; } diff --git a/background/token-manager.js b/background/token-manager.js index b4088973..272f431e 100644 --- a/background/token-manager.js +++ b/background/token-manager.js @@ -92,11 +92,8 @@ const tokenMan = (() => { if (!interactive) { throw new Error(`Invalid token: ${name}`); } - const styleInformation = name === 'userstylesworld' ? JSON.stringify({ - 'code': style.sourceCode, - 'name': style.name, - }) : null; - return authUser(name, k, interactive, styleInformation); + const accessToken = authUser(name, k, interactive); + return accessToken; }, async revokeToken(name, styleId) { @@ -136,7 +133,7 @@ const tokenMan = (() => { return handleTokenResult(result, k); } - async function authUser(name, k, interactive = false, styleInformation = null) { + async function authUser(name, k, interactive = false) { await require(['/vendor/webext-launch-web-auth-flow/webext-launch-web-auth-flow.min']); /* global webextLaunchWebAuthFlow */ const provider = AUTH[name]; @@ -147,9 +144,6 @@ const tokenMan = (() => { redirect_uri: provider.redirect_uri || chrome.identity.getRedirectURL(), state, }; - if (styleInformation) { - query['styleInfo'] = styleInformation; - } if (provider.scopes) { query.scope = provider.scopes.join(' '); } diff --git a/content/install-hook-userstylesworld.js b/content/install-hook-userstylesworld.js index 23f7c0d8..7a4bb19a 100644 --- a/content/install-hook-userstylesworld.js +++ b/content/install-hook-userstylesworld.js @@ -1,3 +1,4 @@ +/* global API */// msg.js 'use strict'; (() => { @@ -18,5 +19,11 @@ } }; + if (window.location.pathname === '/api/oauth/authorize_style/new') { + API.styles.find({_linking: true}).then(style => { + sendPostMessage({type: 'usw-fill-new-style', data: style}); + }); + } + window.addEventListener('message', onPageLoaded); })();