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() { | ||||
|   initCodeMirror(); | ||||
|   const params = getParams(); | ||||
|   getStyle().then(style => { | ||||
|     styleId = style.id; | ||||
|     sessionStorage.justEditedStyleId = styleId; | ||||
|  | @ -1310,7 +1309,8 @@ function init() { | |||
|   }); | ||||
| 
 | ||||
|   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
 | ||||
|       // This is an add
 | ||||
|       $('#heading').textContent = t('addStyleTitle'); | ||||
|  | @ -1318,7 +1318,7 @@ function init() { | |||
|     } | ||||
|     $('#heading').textContent = t('editStyleHeading'); | ||||
|     // This is an edit
 | ||||
|     return getStylesSafe({id: params.id}).then(styles => { | ||||
|     return getStylesSafe({id}).then(styles => { | ||||
|       let style = styles[0]; | ||||
|       if (!style) { | ||||
|         style = createEmptyStyle(); | ||||
|  | @ -1329,7 +1329,7 @@ function init() { | |||
|   } | ||||
| 
 | ||||
|   function createEmptyStyle() { | ||||
|     const params = getParams(); | ||||
|     const params = new URLSearchParams(location.search); | ||||
|     const style = { | ||||
|       id: null, | ||||
|       name: '', | ||||
|  | @ -1337,8 +1337,8 @@ function init() { | |||
|       sections: [{code: ''}] | ||||
|     }; | ||||
|     for (const i in CssToProperty) { | ||||
|       if (params[i]) { | ||||
|         style.sections[0][CssToProperty[i]] = [params[i]]; | ||||
|       if (params.get(i)) { | ||||
|         style.sections[0][CssToProperty[i]] = [params.get(i)]; | ||||
|       } | ||||
|     } | ||||
|     return style; | ||||
|  | @ -1893,19 +1893,6 @@ function showCodeMirrorPopup(title, html, options) { | |||
|   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); | ||||
| 
 | ||||
| function replaceStyle(request) { | ||||
|  |  | |||
|  | @ -2,12 +2,12 @@ | |||
| 'use strict'; | ||||
| 
 | ||||
| (() => { | ||||
|   const params = getParams(); | ||||
|   const params = new URLSearchParams(location.search); | ||||
|   let liveReload = false; | ||||
|   let installed = false; | ||||
| 
 | ||||
|   const port = chrome.tabs.connect( | ||||
|     Number(params.tabId), | ||||
|     Number(params.get('tabId')), | ||||
|     {name: 'usercss-install', frameId: 0} | ||||
|   ); | ||||
|   port.postMessage({method: 'getSourceCode'}); | ||||
|  | @ -234,7 +234,7 @@ | |||
| 
 | ||||
|     // set updateUrl
 | ||||
|     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); | ||||
|     if (dup && dup.updateUrl === updateUrl.href) { | ||||
|       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 *_gen() { | ||||
|       for (const section of style.sections) { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user