Update Elements with ID lister to 1.0.4
- Hide SVGs and their children from the elements list
This commit is contained in:
		
							parent
							
								
									8dd050b576
								
							
						
					
					
						commit
						73724ff549
					
				| 
						 | 
					@ -6,7 +6,7 @@
 | 
				
			||||||
// @grant       GM_getResourceURL
 | 
					// @grant       GM_getResourceURL
 | 
				
			||||||
// @require     https://cdn.jsdelivr.net/npm/dialog-polyfill@0.5.6/dist/dialog-polyfill.min.js#sha256-cec1a2e320aab77e28bad4ad6bc5e532a6ef5757345c19bb5158aa880b7162a6
 | 
					// @require     https://cdn.jsdelivr.net/npm/dialog-polyfill@0.5.6/dist/dialog-polyfill.min.js#sha256-cec1a2e320aab77e28bad4ad6bc5e532a6ef5757345c19bb5158aa880b7162a6
 | 
				
			||||||
// @resource    dialogPolyfillCSS https://cdn.jsdelivr.net/npm/dialog-polyfill@0.5.6/dist/dialog-polyfill.min.css#sha256-4dcb3ab62e545f30bf06a4824c253641ee889ca85ca28d5447590557922496ab
 | 
					// @resource    dialogPolyfillCSS https://cdn.jsdelivr.net/npm/dialog-polyfill@0.5.6/dist/dialog-polyfill.min.css#sha256-4dcb3ab62e545f30bf06a4824c253641ee889ca85ca28d5447590557922496ab
 | 
				
			||||||
// @version     1.0.3
 | 
					// @version     1.0.4
 | 
				
			||||||
// @author      blankie
 | 
					// @author      blankie
 | 
				
			||||||
// @description A userscript that adds a "Show elements popup" option to the Monkey Menu which lists all elements with an ID
 | 
					// @description A userscript that adds a "Show elements popup" option to the Monkey Menu which lists all elements with an ID
 | 
				
			||||||
// @inject-into content
 | 
					// @inject-into content
 | 
				
			||||||
| 
						 | 
					@ -123,8 +123,7 @@ function getElementList() {
 | 
				
			||||||
    let elements = [];
 | 
					    let elements = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (let element of document.body.querySelectorAll("[id]")) {
 | 
					    for (let element of document.body.querySelectorAll("[id]")) {
 | 
				
			||||||
        let rect = element.getBoundingClientRect();
 | 
					        if (shouldIgnoreElement(element)) {
 | 
				
			||||||
        if (rect.height === 0 || rect.width === 0) {
 | 
					 | 
				
			||||||
            continue;
 | 
					            continue;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        elements.push(getElementListItem(element));
 | 
					        elements.push(getElementListItem(element));
 | 
				
			||||||
| 
						 | 
					@ -133,6 +132,25 @@ function getElementList() {
 | 
				
			||||||
    return elements;
 | 
					    return elements;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function shouldIgnoreElement(element) {
 | 
				
			||||||
 | 
					    // Check if the element is not visible
 | 
				
			||||||
 | 
					    let rect = element.getBoundingClientRect();
 | 
				
			||||||
 | 
					    if (rect.height === 0 || rect.width === 0) {
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Check if the element is a svg or a part of one
 | 
				
			||||||
 | 
					    // https://arstechnica.com/information-technology/2023/05/critics-say-googles-new-zip-and-mov-domains-will-be-a-boon-to-scammers/
 | 
				
			||||||
 | 
					    while (element) {
 | 
				
			||||||
 | 
					        if (element.localName === "svg") {
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        element = element.parentElement;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getElementListItem(element) {
 | 
					function getElementListItem(element) {
 | 
				
			||||||
    let li = document.createElement("li");
 | 
					    let li = document.createElement("li");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue