fe45781545
* Prototype Just able to log the token for the requested style. * Store USw Token * Fix linting * Add revoke capabilities * Add upload capabilities + UI? * Add credentials for production server * Patch up several things * Send styleInfo We will be adding the feature to add style based of the currentStyle, see paring commit31813da300
* Fix clientSecret * Pass styleInfo trough usw's hook Related commit on USW:461ddb03c7
* Adjusted behavior Applied suggestions from Narco. * Wait for `usw-ready`before sending style * don't use `window.` * Ensure correct style is pre-filled * Send over metadata Related USW commit:7d8c4c1248
* Title Case => Title case * _linking => _isUswLinked
50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
/* global $ $create $remove */// dom.js
|
|
/* global editor */
|
|
|
|
'use strict';
|
|
|
|
let uswPort;
|
|
|
|
function connectToPort() {
|
|
if (!uswPort) {
|
|
uswPort = chrome.runtime.connect({name: 'link-style-usw'});
|
|
uswPort.onDisconnect.addListener(err => {
|
|
throw err;
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
/* exported revokeLinking */
|
|
function revokeLinking() {
|
|
connectToPort();
|
|
|
|
uswPort.postMessage({reason: 'revoke', data: editor.style});
|
|
}
|
|
|
|
/* exported publishStyle */
|
|
function publishStyle() {
|
|
connectToPort();
|
|
const data = Object.assign(editor.style, {sourceCode: editor.getEditors()[0].getValue()});
|
|
uswPort.postMessage({reason: 'publish', data});
|
|
}
|
|
|
|
|
|
/* exported updateUI */
|
|
function updateUI(useStyle) {
|
|
const style = useStyle || editor.style;
|
|
if (style._usw && style._usw.token) {
|
|
$('#revoke-link').style = '';
|
|
|
|
const linkInformation = $create('div', {id: 'link-info'}, [
|
|
$create('p', `Style name: ${style._usw.name}`),
|
|
$create('p', `Description: ${style._usw.description}`),
|
|
]);
|
|
$remove('#link-info');
|
|
$('#integration').insertBefore(linkInformation, $('#integration').firstChild);
|
|
} else {
|
|
$('#revoke-link').style = 'display: none;';
|
|
$remove('#link-info');
|
|
}
|
|
}
|