2023-08-01 18:25:12 +03:00
|
|
|
// ==UserScript==
|
|
|
|
// @name Github Link External Resources
|
2023-08-03 19:52:37 +03:00
|
|
|
// @namespace https://github.com/Maks1mS/userscripts
|
2024-05-28 13:20:55 +03:00
|
|
|
// @version 0.2
|
2023-08-01 18:25:12 +03:00
|
|
|
// @description Github Link External Resources
|
|
|
|
// @author Maxim Slipenko
|
|
|
|
// @match https://github.com/*
|
|
|
|
// @icon https://github.com/favicon.ico
|
|
|
|
// @require https://openuserjs.org/src/libs/sizzle/GM_config.js
|
|
|
|
// @grant GM_getValue
|
|
|
|
// @grant GM_setValue
|
|
|
|
// @grant GM.getValue
|
|
|
|
// @grant GM.setValue
|
|
|
|
// @grant GM_registerMenuCommand
|
|
|
|
// @grant window.onurlchange
|
|
|
|
// ==/UserScript==
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const translations = {
|
|
|
|
'ru-RU': {
|
|
|
|
settings: 'Настройки',
|
|
|
|
config: 'Параметры'
|
|
|
|
},
|
|
|
|
'en-US': {
|
|
|
|
settings: 'Settings',
|
|
|
|
config: 'Config'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function t(key) {
|
2024-05-28 13:20:55 +03:00
|
|
|
const currentLang = navigator.language || 'en-US';
|
|
|
|
const shortLang = currentLang.split('-')[0];
|
|
|
|
return translations?.[currentLang]?.[key] ?? translations?.[shortLang]?.[key] ?? translations?.['en-US']?.[key] ?? key;
|
2023-08-01 18:25:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const settingsId = 'GithubLinkExternalResources';
|
|
|
|
|
|
|
|
const gmc = new GM_config({
|
2024-05-28 13:20:55 +03:00
|
|
|
events: {
|
|
|
|
save () {
|
|
|
|
this.close();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
fields: {
|
|
|
|
data: {
|
|
|
|
label: t('config'),
|
|
|
|
type: 'textarea',
|
|
|
|
// github prefix org or org/repo | prefix | url ($2 - numeric identifier)
|
2023-08-01 18:25:12 +03:00
|
|
|
default: 'pyside | PYSIDE- | https://bugreports.qt.io/browse/$1'
|
2024-05-28 13:20:55 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
id: settingsId,
|
|
|
|
title: 'Github Link External Resources',
|
2023-08-01 18:25:12 +03:00
|
|
|
css: `
|
|
|
|
#${settingsId} .field_label {
|
|
|
|
font-size: 20px;
|
|
|
|
}
|
|
|
|
textarea {
|
|
|
|
width: 60%;
|
|
|
|
font-size: 16px;
|
|
|
|
}`
|
|
|
|
});
|
|
|
|
|
2024-05-28 13:20:55 +03:00
|
|
|
GM_registerMenuCommand(t('settings'), () => gmc.open());
|
2023-08-01 18:25:12 +03:00
|
|
|
|
|
|
|
const selector = '.js-issue-title.markdown-title,' +
|
|
|
|
'.js-navigation-open.markdown-title,' +
|
2024-05-28 13:20:55 +03:00
|
|
|
'.commit-title.markdown-title,' +
|
2023-08-01 18:25:12 +03:00
|
|
|
'#partial-actions-workflow-runs .Link--primary,' + // actions
|
|
|
|
'.repository-content h3.PageHeader-title > span > span,' + // actions
|
|
|
|
'div.my-2.Details-content--hidden,' + // commit message
|
|
|
|
'.wb-break-word.width-fit > .color-fg-default.lh-0.mb-2.markdown-title'; // sidebar
|
|
|
|
|
|
|
|
const replace = (node, row) => {
|
2024-05-28 13:20:55 +03:00
|
|
|
if (!node) return;
|
|
|
|
const re = new RegExp(`\\b(${row[1]}(\\d+))\\b(?!<\\/a>|")`, 'g');
|
|
|
|
console.log(re);
|
|
|
|
node.innerHTML = node.innerHTML.replace(re, `<a href="${row[2]}">$1</a>`);
|
2023-08-01 18:25:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
let data = '';
|
|
|
|
|
|
|
|
const run = (url) => {
|
|
|
|
const row = data.find(row => url.startsWith(`https://github.com/${row[0]}`));
|
2024-05-28 13:20:55 +03:00
|
|
|
console.log(data);
|
|
|
|
if (!row) return;
|
|
|
|
console.log(row);
|
2023-08-01 18:25:12 +03:00
|
|
|
const matches = document.querySelectorAll(selector)
|
|
|
|
matches.forEach(n => replace(n, row));
|
|
|
|
}
|
|
|
|
|
|
|
|
const onInit = gmc => new Promise(resolve => {
|
2024-05-28 13:20:55 +03:00
|
|
|
let isInit = () => setTimeout(() => gmc.isInit ? resolve() : isInit(), 0);
|
|
|
|
isInit();
|
2023-08-01 18:25:12 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
onInit(gmc).then(() => {
|
|
|
|
data = gmc.get('data').split('\n').map(l => l.split('|').map(w => w.trim()))
|
|
|
|
if (window.onurlchange === null) {
|
|
|
|
window.addEventListener('urlchange', (info) => {
|
|
|
|
run(info?.url);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2024-05-28 13:20:55 +03:00
|
|
|
|
2023-08-01 18:25:12 +03:00
|
|
|
})();
|