Skip to content

Instantly share code, notes, and snippets.

@mohemohe
Created April 22, 2024 06:40
Show Gist options
  • Save mohemohe/0c35ec92185b1e91954602f49569106e to your computer and use it in GitHub Desktop.
Save mohemohe/0c35ec92185b1e91954602f49569106e to your computer and use it in GitHub Desktop.
GitHubのPullReqのタイトルにあるBacklogの課題キーをいい感じにリンクにするやつ
// ==UserScript==
// @name github.com Backlog linkify
// @namespace Violentmonkey Scripts
// @match https://github.com/*
// @grant none
// @version 1.0
// @author -
// @description 2024/4/22 14:40:04
// @require https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js
// ==/UserScript==
const config = {
LSCM: "common-c.backlog.com",
SUMIYOKU: "common-c.backlog.com",
MEDWELL: "common-c.backlog.com",
};
const stopPropagation = (e) => e.stopPropagation();
const linkify = () => {
const titleContainers = document.querySelectorAll(".js-issue-title");
for (const titleContainer of titleContainers) {
if (!titleContainer || titleContainer.classList.contains("replaced")) {
continue;
}
let title = titleContainer.innerText;
for (const key of Object.keys(config)) {
const regex = new RegExp(`(${key}-[0-9]+)`);
const match = title.match(regex);
if (match) {
titleContainer.innerHTML = title.replace(regex,`<a href="https://${config[key]}/view/${match[1]}" target="_blank" class="backlog-linkify">${match[1]}</a>`);
const links = titleContainer.querySelectorAll(".backlog-linkify");
for (const link of links) {
link.addEventListener("click", stopPropagation);
}
titleContainer.classList.add("replaced");
}
}
}
};
const mo = new MutationObserver(_.debounce(changes => {
linkify();
}), 1000);
mo.observe(document.body, {
childList: true,
subtree: true,
});
linkify();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment