Skip to content

Commit 53cf76a

Browse files
committed
add custom events
1 parent 5b41425 commit 53cf76a

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="UTF-8">
55
<title>E621 OpenAPI Documentation</title>
6-
<script defer data-domain="e621.wiki" src="https://plausible.furry.computer/js/script.js"></script>
6+
<script defer data-domain="e621.wiki" src="https://plausible.furry.computer/js/script.tagged-events.js"></script>
77
</head>
88

99
<body>

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"clean-webpack-plugin": "^4.0.0",
2323
"favicons-webpack-plugin": "^6.0.1",
2424
"html-webpack-plugin": "^5.6.0",
25+
"jquery": "^3.7.1",
2526
"swagger-themes": "^1.4.3",
2627
"swagger-ui": "^5.17.14"
2728
},

pnpm-lock.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
import SwaggerUI from "swagger-ui";
22
import "swagger-ui/dist/swagger-ui.css";
33
import "swagger-themes/themes/dark.css";
4+
import "jquery";
5+
6+
function addEvent(selector: string, event: string, properties: (element: Element) => Record<string, string>): void {
7+
const items = Array.from(document.querySelectorAll(selector));
8+
for (const item of items) {
9+
const props = properties(item);
10+
item.classList.add(`plausible-event-name=${event.replaceAll(" ", "+")}`);
11+
for (const [key, value] of Object.entries(props)) {
12+
item.classList.add(`plausible-event-${key}=${value.replaceAll(" ", "+")}`);
13+
}
14+
}
15+
}
416

517
SwaggerUI({
618
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, unicorn/prefer-module
719
spec: require("../openapi.yaml"),
8-
dom_id: "#swagger-ui"
20+
dom_id: "#swagger-ui",
21+
onComplete() {
22+
addEvent("button.opblock-summary-control", "Open Endpoint", element => ({ endpoint: element.querySelector(".opblock-summary-description")!.textContent! }));
23+
addEvent(".btn.authorize ", "Open Authorize", () => ({}));
24+
addEvent(".json-schema-2020-12-accordion", "Toggle Schema", element => ({ schema: element.querySelector(".json-schema-2020-12__title")!.textContent! }));
25+
addEvent(".json-schema-2020-12-expand-deep-button", "Toggle Schema", element => ({ schema: element.parentNode!.querySelector(".json-schema-2020-12__title")!.textContent! }));
26+
}
927
});

0 commit comments

Comments
 (0)