diff --git a/background/style-manager.js b/background/style-manager.js index f0a7bd24..31eba73b 100644 --- a/background/style-manager.js +++ b/background/style-manager.js @@ -374,10 +374,8 @@ const styleMan = (() => { case 'publish': { if (!style._usw || !style._usw.token) { - // Ensures just the style does have the _isUswLinked property as `true`. for (const {style: someStyle} of dataMap.values()) { if (someStyle._id === style._id) { - someStyle._isUswLinked = true; someStyle.tmpSourceCode = style.sourceCode; let metadata = {}; try { @@ -388,7 +386,6 @@ const styleMan = (() => { } someStyle.metadata = metadata; } else { - delete someStyle._isUswLinked; delete someStyle.tmpSourceCode; delete someStyle.metadata; } @@ -398,7 +395,6 @@ const styleMan = (() => { token: await tokenMan.getToken('userstylesworld', true, style.id), }; - delete style._isUswLinked; delete style.tmpSourceCode; delete style.metadata; for (const [k, v] of Object.entries(await retrieveStyleInformation(style._usw.token))) { diff --git a/background/token-manager.js b/background/token-manager.js index 04100a3d..2508f2b6 100644 --- a/background/token-manager.js +++ b/background/token-manager.js @@ -92,7 +92,7 @@ const tokenMan = (() => { if (!interactive) { throw new Error(`Invalid token: ${name}`); } - const accessToken = authUser(name, k, interactive); + const accessToken = authUser(name, k, interactive, styleId ? {vendor_data: styleId} : {}); return accessToken; }, @@ -133,17 +133,17 @@ const tokenMan = (() => { return handleTokenResult(result, k); } - async function authUser(name, k, interactive = false) { + async function authUser(name, k, interactive = false, extraQuery = {}) { await require(['/vendor/webext-launch-web-auth-flow/webext-launch-web-auth-flow.min']); /* global webextLaunchWebAuthFlow */ const provider = AUTH[name]; const state = Math.random().toFixed(8).slice(2); - const query = { + const query = Object.assign(extraQuery, { response_type: provider.flow, client_id: provider.clientId, redirect_uri: provider.redirect_uri || chrome.identity.getRedirectURL(), state, - }; + }); if (provider.scopes) { query.scope = provider.scopes.join(' '); } diff --git a/content/install-hook-userstylesworld.js b/content/install-hook-userstylesworld.js index 05bdc591..6644eb37 100644 --- a/content/install-hook-userstylesworld.js +++ b/content/install-hook-userstylesworld.js @@ -18,7 +18,8 @@ sendPostMessage({type: 'usw-remove-stylus-button'}); if (location.pathname === '/api/oauth/style/new') { - API.styles.find({_isUswLinked: true}).then(style => { + const styleId = Number(new URLSearchParams(location.search).get('vendor_data')); + API.styles.get(styleId).then(style => { style.sourceCode = style.tmpSourceCode; sendPostMessage({type: 'usw-fill-new-style', data: style}); });