Fix: drop getParams
This commit is contained in:
parent
6a53ea423c
commit
d981660983
25
edit/edit.js
25
edit/edit.js
|
@ -1297,7 +1297,6 @@ onDOMready().then(init);
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
initCodeMirror();
|
initCodeMirror();
|
||||||
const params = getParams();
|
|
||||||
getStyle().then(style => {
|
getStyle().then(style => {
|
||||||
styleId = style.id;
|
styleId = style.id;
|
||||||
sessionStorage.justEditedStyleId = styleId;
|
sessionStorage.justEditedStyleId = styleId;
|
||||||
|
@ -1310,7 +1309,8 @@ function init() {
|
||||||
});
|
});
|
||||||
|
|
||||||
function getStyle() {
|
function getStyle() {
|
||||||
if (!params.id) {
|
const id = new URLSearchParams(location.search).get('id');
|
||||||
|
if (!id) {
|
||||||
// match should be 2 - one for the whole thing, one for the parentheses
|
// match should be 2 - one for the whole thing, one for the parentheses
|
||||||
// This is an add
|
// This is an add
|
||||||
$('#heading').textContent = t('addStyleTitle');
|
$('#heading').textContent = t('addStyleTitle');
|
||||||
|
@ -1318,7 +1318,7 @@ function init() {
|
||||||
}
|
}
|
||||||
$('#heading').textContent = t('editStyleHeading');
|
$('#heading').textContent = t('editStyleHeading');
|
||||||
// This is an edit
|
// This is an edit
|
||||||
return getStylesSafe({id: params.id}).then(styles => {
|
return getStylesSafe({id}).then(styles => {
|
||||||
let style = styles[0];
|
let style = styles[0];
|
||||||
if (!style) {
|
if (!style) {
|
||||||
style = createEmptyStyle();
|
style = createEmptyStyle();
|
||||||
|
@ -1329,7 +1329,7 @@ function init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function createEmptyStyle() {
|
function createEmptyStyle() {
|
||||||
const params = getParams();
|
const params = new URLSearchParams(location.search);
|
||||||
const style = {
|
const style = {
|
||||||
id: null,
|
id: null,
|
||||||
name: '',
|
name: '',
|
||||||
|
@ -1337,8 +1337,8 @@ function init() {
|
||||||
sections: [{code: ''}]
|
sections: [{code: ''}]
|
||||||
};
|
};
|
||||||
for (const i in CssToProperty) {
|
for (const i in CssToProperty) {
|
||||||
if (params[i]) {
|
if (params.get(i)) {
|
||||||
style.sections[0][CssToProperty[i]] = [params[i]];
|
style.sections[0][CssToProperty[i]] = [params.get(i)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return style;
|
return style;
|
||||||
|
@ -1893,19 +1893,6 @@ function showCodeMirrorPopup(title, html, options) {
|
||||||
return popup;
|
return popup;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getParams() {
|
|
||||||
const params = {};
|
|
||||||
const urlParts = location.href.split('?', 2);
|
|
||||||
if (urlParts.length === 1) {
|
|
||||||
return params;
|
|
||||||
}
|
|
||||||
urlParts[1].split('&').forEach(keyValue => {
|
|
||||||
const splitKeyValue = keyValue.split('=', 2);
|
|
||||||
params[decodeURIComponent(splitKeyValue[0])] = decodeURIComponent(splitKeyValue[1]);
|
|
||||||
});
|
|
||||||
return params;
|
|
||||||
}
|
|
||||||
|
|
||||||
chrome.runtime.onMessage.addListener(onRuntimeMessage);
|
chrome.runtime.onMessage.addListener(onRuntimeMessage);
|
||||||
|
|
||||||
function replaceStyle(request) {
|
function replaceStyle(request) {
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
const params = getParams();
|
const params = new URLSearchParams(location.search);
|
||||||
let liveReload = false;
|
let liveReload = false;
|
||||||
let installed = false;
|
let installed = false;
|
||||||
|
|
||||||
const port = chrome.tabs.connect(
|
const port = chrome.tabs.connect(
|
||||||
Number(params.tabId),
|
Number(params.get('tabId')),
|
||||||
{name: 'usercss-install', frameId: 0}
|
{name: 'usercss-install', frameId: 0}
|
||||||
);
|
);
|
||||||
port.postMessage({method: 'getSourceCode'});
|
port.postMessage({method: 'getSourceCode'});
|
||||||
|
@ -234,7 +234,7 @@
|
||||||
|
|
||||||
// set updateUrl
|
// set updateUrl
|
||||||
const setUpdate = $('.set-update-url input[type=checkbox]');
|
const setUpdate = $('.set-update-url input[type=checkbox]');
|
||||||
const updateUrl = new URL(params.updateUrl);
|
const updateUrl = new URL(params.get('updateUrl'));
|
||||||
$('.set-update-url > span').textContent = t('installUpdateFromLabel', updateUrl.href);
|
$('.set-update-url > span').textContent = t('installUpdateFromLabel', updateUrl.href);
|
||||||
if (dup && dup.updateUrl === updateUrl.href) {
|
if (dup && dup.updateUrl === updateUrl.href) {
|
||||||
setUpdate.checked = true;
|
setUpdate.checked = true;
|
||||||
|
@ -272,23 +272,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getParams() {
|
|
||||||
// URL.searchParams needs chrome 51+
|
|
||||||
const {search} = location;
|
|
||||||
const result = {};
|
|
||||||
for (const param of search.slice(1).split('&')) {
|
|
||||||
let key, value;
|
|
||||||
if (param.includes('=')) {
|
|
||||||
[key, value] = param.split('=').map(decodeURIComponent);
|
|
||||||
} else {
|
|
||||||
key = decodeURIComponent(param);
|
|
||||||
value = true;
|
|
||||||
}
|
|
||||||
result[key] = value;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getAppliesTo(style) {
|
function getAppliesTo(style) {
|
||||||
function *_gen() {
|
function *_gen() {
|
||||||
for (const section of style.sections) {
|
for (const section of style.sections) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user