diff --git a/src/plugins/gitea-add-swagger-button.user.js b/src/plugins/gitea-add-swagger-button.user.js new file mode 100644 index 0000000..e57049c --- /dev/null +++ b/src/plugins/gitea-add-swagger-button.user.js @@ -0,0 +1,47 @@ +// ==UserScript== +// @name gitea-add-swagger-button +// @namespace https://integratielaag.nl/ +// @version 0.1 +// @description Creates a button in Gitea to view Swagger +// @author bboterm +// @match https://git.integratielaag.nl/*.yaml +// @icon https://www.google.com/s2/favicons?sz=64&domain=gitea.com +// @grant none +// ==/UserScript== + +(function() { + 'use strict'; + + // Set the base URL for the Swagger instance + const swaggerBaseURL = 'https://swagger.integratielaag.nl/?url='; + // Get the base URL from the current webpage + const gitBaseURL = window.location.origin; + + // Replace 'parent-class-name' with the class name of the parent div + const parentClassName = 'file-actions'; + // Replace 'child-class-name' with the class name of the child div + const childClassName = 'buttons'; + + const parentDiv = document.querySelector('div.file-actions'); + if (parentDiv) { + const childDiv = parentDiv.querySelector('div.buttons'); + if (childDiv) { + const firstATag = childDiv.querySelector('a'); + if (firstATag) { + // Get the URL of the raw file + const hrefValue = firstATag.getAttribute('href'); + // Create a string literal for the new Swagger button + const swaggerButton = `Swagger`; + // Add the Swagger button to the HTML + childDiv.innerHTML = swaggerButton + childDiv.innerHTML; + } else { + console.log('No tag found inside the child div.'); + } + } else { + console.log(`Child div with class '${childClassName}' not found.`); + } + } else { + console.log(`Parent div with class '${parentClassName}' not found.`); + } +})(); +