Change: drop prefChanged, use prefs service
This commit is contained in:
		
							parent
							
								
									10f9449144
								
							
						
					
					
						commit
						8a6e8ac03a
					
				|  | @ -34,6 +34,9 @@ | ||||||
|     window.addEventListener(chrome.runtime.id, orphanCheck, true); |     window.addEventListener(chrome.runtime.id, orphanCheck, true); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   prefs.subscribe(['disableAll'], (key, value) => doDisableAll(value)); | ||||||
|  |   prefs.subscribe(['exposeIframes'], (key, value) => doExposeIframes(value)); | ||||||
|  | 
 | ||||||
|   function requestStyles(options, callback = applyStyles) { |   function requestStyles(options, callback = applyStyles) { | ||||||
|     if (!chrome.app && document instanceof XMLDocument) { |     if (!chrome.app && document instanceof XMLDocument) { | ||||||
|       chrome.runtime.sendMessage({method: 'styleViaAPI', action: 'styleApply'}); |       chrome.runtime.sendMessage({method: 'styleViaAPI', action: 'styleApply'}); | ||||||
|  | @ -140,15 +143,6 @@ | ||||||
|         replaceAll(request.styles); |         replaceAll(request.styles); | ||||||
|         break; |         break; | ||||||
| 
 | 
 | ||||||
|       case 'prefChanged': |  | ||||||
|         if ('disableAll' in request.prefs) { |  | ||||||
|           doDisableAll(request.prefs.disableAll); |  | ||||||
|         } |  | ||||||
|         if ('exposeIframes' in request.prefs) { |  | ||||||
|           doExposeIframes(request.prefs.exposeIframes); |  | ||||||
|         } |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|       case 'ping': |       case 'ping': | ||||||
|         sendResponse(true); |         sendResponse(true); | ||||||
|         break; |         break; | ||||||
|  |  | ||||||
|  | @ -55,6 +55,9 @@ Promise.all([ | ||||||
|   } |   } | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
|  | prefs.subscribe(['editor.smartIndent'], (key, value) => | ||||||
|  |   CodeMirror.setOption('smartIndent', value)); | ||||||
|  | 
 | ||||||
| function preinit() { | function preinit() { | ||||||
|   // make querySelectorAll enumeration code readable
 |   // make querySelectorAll enumeration code readable
 | ||||||
|   ['forEach', 'some', 'indexOf', 'map'].forEach(method => { |   ['forEach', 'some', 'indexOf', 'map'].forEach(method => { | ||||||
|  | @ -183,11 +186,6 @@ function onRuntimeMessage(request) { | ||||||
|         break; |         break; | ||||||
|       } |       } | ||||||
|       break; |       break; | ||||||
|     case 'prefChanged': |  | ||||||
|       if ('editor.smartIndent' in request.prefs) { |  | ||||||
|         CodeMirror.setOption('smartIndent', request.prefs['editor.smartIndent']); |  | ||||||
|       } |  | ||||||
|       break; |  | ||||||
|     case 'editDeleteText': |     case 'editDeleteText': | ||||||
|       document.execCommand('delete'); |       document.execCommand('delete'); | ||||||
|       break; |       break; | ||||||
|  |  | ||||||
|  | @ -58,7 +58,7 @@ | ||||||
|       "run_at": "document_start", |       "run_at": "document_start", | ||||||
|       "all_frames": true, |       "all_frames": true, | ||||||
|       "match_about_blank": true, |       "match_about_blank": true, | ||||||
|       "js": ["content/apply.js"] |       "js": ["js/prefs.js", "content/apply.js"] | ||||||
|     }, |     }, | ||||||
|     { |     { | ||||||
|       "matches": ["http://userstyles.org/*", "https://userstyles.org/*"], |       "matches": ["http://userstyles.org/*", "https://userstyles.org/*"], | ||||||
|  |  | ||||||
|  | @ -28,6 +28,14 @@ getActiveTab().then(tab => | ||||||
| 
 | 
 | ||||||
| chrome.runtime.onMessage.addListener(onRuntimeMessage); | chrome.runtime.onMessage.addListener(onRuntimeMessage); | ||||||
| 
 | 
 | ||||||
|  | prefs.subscribe(['popup.stylesFirst'], (key, stylesFirst) => { | ||||||
|  |   const actions = $('body > .actions'); | ||||||
|  |   const before = stylesFirst ? actions : actions.nextSibling; | ||||||
|  |   document.body.insertBefore(installed, before); | ||||||
|  | }); | ||||||
|  | prefs.subscribe(['popupWidth'], (key, value) => setPopupWidth(value)); | ||||||
|  | prefs.subscribe(['popup.borders'], (key, value) => toggleSideBorders(value)); | ||||||
|  | 
 | ||||||
| function onRuntimeMessage(msg) { | function onRuntimeMessage(msg) { | ||||||
|   switch (msg.method) { |   switch (msg.method) { | ||||||
|     case 'styleAdded': |     case 'styleAdded': | ||||||
|  | @ -38,18 +46,6 @@ function onRuntimeMessage(msg) { | ||||||
|     case 'styleDeleted': |     case 'styleDeleted': | ||||||
|       handleDelete(msg.id); |       handleDelete(msg.id); | ||||||
|       break; |       break; | ||||||
|     case 'prefChanged': |  | ||||||
|       if ('popup.stylesFirst' in msg.prefs) { |  | ||||||
|         const stylesFirst = msg.prefs['popup.stylesFirst']; |  | ||||||
|         const actions = $('body > .actions'); |  | ||||||
|         const before = stylesFirst ? actions : actions.nextSibling; |  | ||||||
|         document.body.insertBefore(installed, before); |  | ||||||
|       } else if ('popupWidth' in msg.prefs) { |  | ||||||
|         setPopupWidth(msg.prefs.popupWidth); |  | ||||||
|       } else if ('popup.borders' in msg.prefs) { |  | ||||||
|         toggleSideBorders(msg.prefs['popup.borders']); |  | ||||||
|       } |  | ||||||
|       break; |  | ||||||
|   } |   } | ||||||
|   dispatchEvent(new CustomEvent(msg.method, {detail: msg})); |   dispatchEvent(new CustomEvent(msg.method, {detail: msg})); | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user