Quellcode durchsuchen

Clicking the extension icon scrolls the page to the first visible found element.

Mr.doob vor 6 Monaten
Ursprung
Commit
860be6cced
2 geänderte Dateien mit 25 neuen und 4 gelöschten Zeilen
  1. 14 0
      devtools/background.js
  2. 11 4
      devtools/bridge.js

+ 14 - 0
devtools/background.js

@@ -3,6 +3,20 @@
 // Map tab IDs to connections
 // Map tab IDs to connections
 const connections = new Map();
 const connections = new Map();
 
 
+// Handle extension icon clicks in the toolbar
+chrome.action.onClicked.addListener( ( tab ) => {
+
+	// Send scroll-to-canvas message to the content script (no UUID = scroll to first canvas)
+	chrome.tabs.sendMessage( tab.id, {
+		name: 'scroll-to-canvas',
+		tabId: tab.id
+	} ).catch( () => {
+		// Tab might not have the content script injected
+		console.log( 'Could not send scroll-to-canvas message to tab', tab.id );
+	} );
+
+} );
+
 // Listen for connections from the devtools panel
 // Listen for connections from the devtools panel
 chrome.runtime.onConnect.addListener( port => {
 chrome.runtime.onConnect.addListener( port => {
 
 

+ 11 - 4
devtools/bridge.js

@@ -455,12 +455,19 @@
 
 
 		}
 		}
 
 
-		function scrollToCanvas( rendererUuid ) {
+		function scrollToCanvas( uuid ) {
 
 
-			// Find the renderer with the given UUID
-			const renderer = observedRenderers.find( r => r.uuid === rendererUuid );
+			let renderer = null;
 			
 			
-			if ( renderer && renderer.domElement ) {
+			if ( uuid ) {
+				// Find the renderer with the given UUID
+				renderer = observedRenderers.find( r => r.uuid === uuid );
+			} else {
+				// If no UUID provided, find the first available renderer whose canvas is in the DOM
+				renderer = observedRenderers.find( r => r.domElement && document.body.contains( r.domElement ) );
+			}
+			
+			if ( renderer ) {
 
 
 				// Scroll the canvas element into view
 				// Scroll the canvas element into view
 				renderer.domElement.scrollIntoView( {
 				renderer.domElement.scrollIntoView( {

粤ICP备19079148号