From 72033ae19196865ee6d8e9327e37591df74a8eef Mon Sep 17 00:00:00 2001 From: Sebastian Schulze Date: Fri, 23 Sep 2022 19:37:58 +0200 Subject: [PATCH] [qutebrowser] Add greasemonkey script to load related merge requests --- .../greasemonkey/gitlab-issue-board.js | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 dot_config/private_qutebrowser/greasemonkey/gitlab-issue-board.js diff --git a/dot_config/private_qutebrowser/greasemonkey/gitlab-issue-board.js b/dot_config/private_qutebrowser/greasemonkey/gitlab-issue-board.js new file mode 100644 index 0000000..0892d39 --- /dev/null +++ b/dot_config/private_qutebrowser/greasemonkey/gitlab-issue-board.js @@ -0,0 +1,46 @@ +// ==UserScript== +// @name GitLabBoardEnhancements +// @namespace https://github.com/bascht +// @description Adjust a few non-mono pages that I like to read +// @include /^https://git.* +// @version 1 +// @author Bascht +// ==/UserScript== + +(async function IIFE() { + 'use strict'; + + var enhanceGitLabCard = async function(card) { + const full_issue = $(card).find("h4 a").first().attr("href"); + var project_path = full_issue.split("/-/issues/")[0].replace("https://git.alfa.sx/", "") + var issue_id = full_issue.split("/-/issues/")[1] + var full_api_path = "https://git.alfa.sx/api/v4/projects/" + encodeURIComponent(project_path) + "/issues/" + issue_id + "/related_merge_requests?per_page=100"; + + const board_info_items = $(card).find("span.board-info-items").first() + GM.xmlHttpRequest({ + method: "GET", + url: full_api_path, + onload: function(response) { + $(board_info_items).find("div.related-merge-requests").each(function(){ $(this).remove()}); + $(JSON.parse(response.responseText)).each(function(){ + var div = $("
", { class: "related-merge-requests gl-display-flex align-items-start" }) + var a = $("", { href: this.web_url, title: this.title }) + a.html("[" + this.state + "]" + this.references.full) + $(div).append(a) + $(board_info_items).append(div) + + }) + } + }); + }; + + document.addEventListener('readystatechange', async function onReadyStateChange() { + $("body").on("click", function(e){ + + var card = $(e.target).parents("li[data-qa-selector='board_card']").first(); + if(card) { + enhanceGitLabCard(card) + } + }); + }); +})();