parent
921da08317
commit
b115e1c2d4
|
@ -360,9 +360,12 @@ const styleMan = (() => {
|
||||||
}
|
}
|
||||||
switch (reason) {
|
switch (reason) {
|
||||||
case 'link':
|
case 'link':
|
||||||
|
style._linking = true;
|
||||||
|
saveStyle(style);
|
||||||
style._usw = {
|
style._usw = {
|
||||||
token: await tokenMan.getToken('userstylesworld', true, style),
|
token: await tokenMan.getToken('userstylesworld', true, style),
|
||||||
};
|
};
|
||||||
|
delete style._linking;
|
||||||
for (const [k, v] of Object.entries(await retrieveStyleInformation(style._usw.token))) {
|
for (const [k, v] of Object.entries(await retrieveStyleInformation(style._usw.token))) {
|
||||||
style._usw[k] = v;
|
style._usw[k] = v;
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,11 +92,8 @@ const tokenMan = (() => {
|
||||||
if (!interactive) {
|
if (!interactive) {
|
||||||
throw new Error(`Invalid token: ${name}`);
|
throw new Error(`Invalid token: ${name}`);
|
||||||
}
|
}
|
||||||
const styleInformation = name === 'userstylesworld' ? JSON.stringify({
|
const accessToken = authUser(name, k, interactive);
|
||||||
'code': style.sourceCode,
|
return accessToken;
|
||||||
'name': style.name,
|
|
||||||
}) : null;
|
|
||||||
return authUser(name, k, interactive, styleInformation);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async revokeToken(name, styleId) {
|
async revokeToken(name, styleId) {
|
||||||
|
@ -136,7 +133,7 @@ const tokenMan = (() => {
|
||||||
return handleTokenResult(result, k);
|
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']);
|
await require(['/vendor/webext-launch-web-auth-flow/webext-launch-web-auth-flow.min']);
|
||||||
/* global webextLaunchWebAuthFlow */
|
/* global webextLaunchWebAuthFlow */
|
||||||
const provider = AUTH[name];
|
const provider = AUTH[name];
|
||||||
|
@ -147,9 +144,6 @@ const tokenMan = (() => {
|
||||||
redirect_uri: provider.redirect_uri || chrome.identity.getRedirectURL(),
|
redirect_uri: provider.redirect_uri || chrome.identity.getRedirectURL(),
|
||||||
state,
|
state,
|
||||||
};
|
};
|
||||||
if (styleInformation) {
|
|
||||||
query['styleInfo'] = styleInformation;
|
|
||||||
}
|
|
||||||
if (provider.scopes) {
|
if (provider.scopes) {
|
||||||
query.scope = provider.scopes.join(' ');
|
query.scope = provider.scopes.join(' ');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* global API */// msg.js
|
||||||
'use strict';
|
'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);
|
window.addEventListener('message', onPageLoaded);
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user