420733b93a
* add Patch CSP option * show style version, size, and update age in manager * add scope selector to style search in manager * keep scroll position and selections in tab's session * directly install usercss from raw github links * ditch localStorage, use on-demand SessionStore proxy * simplify localization * allow <code> tag in i18n-html * keep nodes in HTML templates * API.getAllStyles is actually faster with code untouched * fix fitToContent when applies-to is taller than window * dedupe linter.enableForEditor calls * prioritize visible CMs in refreshOnViewListener * don't scroll to last style on editing a new one * delay colorview for invisible CMs * eslint comma-dangle error + autofix files * styleViaXhr: also toggle for disableAll pref * styleViaXhr: allow cookies for sandbox CSP * simplify notes in options * simplify getStylesViaXhr * oldUI fixups: * remove separator before 1st applies-to * center name bubbles * fix updateToc focus on a newly added section * fix fitToContent when cloning section * remove CSS `contain` as it makes no difference * replace overrides with declarative CSS + code cosmetics * simplify adjustWidth and make it work in FF
103 lines
2.5 KiB
JavaScript
103 lines
2.5 KiB
JavaScript
'use strict';
|
|
|
|
(() => {
|
|
// begin:nanographql - Tiny graphQL client library
|
|
// Author: yoshuawuyts (https://github.com/yoshuawuyts)
|
|
// License: MIT
|
|
// Modified by DecentM to fit project standards
|
|
|
|
const getOpname = /(query|mutation) ?([\w\d-_]+)? ?\(.*?\)? \{/;
|
|
const gql = str => {
|
|
str = Array.isArray(str) ? str.join('') : str;
|
|
const name = getOpname.exec(str);
|
|
|
|
return variables => {
|
|
const data = {query: str};
|
|
if (variables) data.variables = JSON.stringify(variables);
|
|
if (name && name.length) {
|
|
const operationName = name[2];
|
|
if (operationName) data.operationName = name[2];
|
|
}
|
|
return JSON.stringify(data);
|
|
};
|
|
};
|
|
|
|
// end:nanographql
|
|
|
|
const api = 'https://api.openusercss.org';
|
|
const doQuery = ({id}, queryString) => {
|
|
const query = gql(queryString);
|
|
|
|
return fetch(api, {
|
|
method: 'POST',
|
|
headers: new Headers({
|
|
'Content-Type': 'application/json',
|
|
}),
|
|
body: query({
|
|
id,
|
|
}),
|
|
})
|
|
.then(res => res.json());
|
|
};
|
|
|
|
window.API_METHODS = Object.assign(window.API_METHODS || {}, {
|
|
/**
|
|
* This function can be used to retrieve a theme object from the
|
|
* GraphQL API, set above
|
|
*
|
|
* Example:
|
|
* chrome.runtime.sendMessage({
|
|
* 'method': 'oucThemeById',
|
|
* 'id': '5a2f819f7c57c751001b49df'
|
|
* }, console.log);
|
|
*
|
|
* @param {ID} $0.id MongoDB style ID
|
|
* @returns {Promise.<{data: object}>} The GraphQL result with the `theme` object
|
|
*/
|
|
|
|
oucThemeById: params => doQuery(params, `
|
|
query($id: ID!) {
|
|
theme(id: $id) {
|
|
_id
|
|
title
|
|
description
|
|
createdAt
|
|
lastUpdate
|
|
version
|
|
screenshots
|
|
user {
|
|
_id
|
|
displayname
|
|
}
|
|
}
|
|
}
|
|
`),
|
|
|
|
/**
|
|
* This function can be used to retrieve a user object from the
|
|
* GraphQL API, set above
|
|
*
|
|
* Example:
|
|
* chrome.runtime.sendMessage({
|
|
* 'method': 'oucUserById',
|
|
* 'id': '5a2f0361ba666f0b00b9c827'
|
|
* }, console.log);
|
|
*
|
|
* @param {ID} $0.id MongoDB style ID
|
|
* @returns {Promise.<{data: object}>} The GraphQL result with the `user` object
|
|
*/
|
|
|
|
oucUserById: params => doQuery(params, `
|
|
query($id: ID!) {
|
|
user(id: $id) {
|
|
_id
|
|
displayname
|
|
avatarUrl
|
|
smallAvatarUrl
|
|
bio
|
|
}
|
|
}
|
|
`),
|
|
});
|
|
})();
|