add events properly
This commit is contained in:
		
							parent
							
								
									42c310828b
								
							
						
					
					
						commit
						d33e5f0a2d
					
				
					 1 changed files with 8 additions and 7 deletions
				
			
		|  | @ -3,7 +3,7 @@ | |||
| export default class Menu { | ||||
| 	#options; | ||||
| 
 | ||||
| 	constructor (ID, title, contexts, event, type, icon) { | ||||
| 	constructor (ID, title, contexts, events, type, icon) { | ||||
| 		if ((typeof ID).includes(`obj`) && !Array.isArray(ID)) { | ||||
| 			// Create the ID if it doesn't exist. 
 | ||||
| 			ID.ID = ((ID.hasOwnProperty(`ID`)) ? ID.ID : false) ? ID.ID : String(Math.random() / Math.random() * 100); | ||||
|  | @ -43,12 +43,13 @@ export default class Menu { | |||
| 			this.hidden = false; | ||||
| 			this.ID = chrome.contextMenus.create(this.#options);		 | ||||
| 
 | ||||
| 			if (((this.events && (typeof this.events).includes(`obj`) && !Array.isArray(this.events))) ? Object.keys(this.events) > 0 : false) { | ||||
| 			console.log(Object.keys(this.events)); | ||||
| 			if (((this.events && (typeof this.events).includes(`obj`) && !Array.isArray(this.events))) ? Object.keys(this.events).length > 0 : false) { | ||||
| 				(Object.keys(this.events)).forEach((EVENT) => { | ||||
| 					chrome.contextMenus[EVENT].addListener((info, tab) => { | ||||
| 						((info.menuItemId) ? info.menuItemId == this.ID : false) | ||||
| 							? this.events[EVENT](info, tab) | ||||
| 							: false; | ||||
| 						if (info.menuItemId == this.ID) { | ||||
| 							this.events[EVENT](info, tab) | ||||
| 						} | ||||
| 					}) | ||||
| 				}); | ||||
| 			}; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue