Update Elements with ID lister to 1.0.13

- Ignore elements with an empty ID
This commit is contained in:
blankie 2023-08-01 19:24:03 +10:00
parent 03debb468a
commit 7e87996b41
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 10 additions and 7 deletions

View File

@ -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.12 // @version 1.0.13
// @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
@ -145,10 +145,17 @@ function getElementList() {
let elements = []; let elements = [];
for (let element of document.body.querySelectorAll("[id], a[name]")) { for (let element of document.body.querySelectorAll("[id], a[name]")) {
let id = element.id;
if (!id && element.localName === "a") {
id = element.name;
}
if (!id) {
continue;
}
if (shouldIgnoreElement(element)) { if (shouldIgnoreElement(element)) {
continue; continue;
} }
elements.push(getElementListItem(element)); elements.push(getElementListItem(element, id));
} }
return elements; return elements;
@ -176,12 +183,8 @@ function shouldIgnoreElement(element) {
return false; return false;
} }
function getElementListItem(element) { function getElementListItem(element, id) {
let newLocation = new URL(location.href); let newLocation = new URL(location.href);
let id = element.id;
if (!id && element.localName === "a") {
id = element.name;
}
let li = document.createElement("li"); let li = document.createElement("li");