mirror of
https://github.com/Maks1mS/userscripts.git
synced 2024-12-23 16:22:59 +03:00
[GithubLinkExternalResources] update to 0.2
fix some bugs
This commit is contained in:
parent
b6ff558469
commit
5326567242
@ -1,7 +1,7 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Github Link External Resources
|
// @name Github Link External Resources
|
||||||
// @namespace https://github.com/Maks1mS/userscripts
|
// @namespace https://github.com/Maks1mS/userscripts
|
||||||
// @version 0.1
|
// @version 0.2
|
||||||
// @description Github Link External Resources
|
// @description Github Link External Resources
|
||||||
// @author Maxim Slipenko
|
// @author Maxim Slipenko
|
||||||
// @match https://github.com/*
|
// @match https://github.com/*
|
||||||
@ -30,28 +30,29 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function t(key) {
|
function t(key) {
|
||||||
const currentLang = navigator.language;
|
const currentLang = navigator.language || 'en-US';
|
||||||
return translations?.[currentLang]?.[key] ?? translations?.['en-US'] ?? key;
|
const shortLang = currentLang.split('-')[0];
|
||||||
|
return translations?.[currentLang]?.[key] ?? translations?.[shortLang]?.[key] ?? translations?.['en-US']?.[key] ?? key;
|
||||||
}
|
}
|
||||||
|
|
||||||
const settingsId = 'GithubLinkExternalResources';
|
const settingsId = 'GithubLinkExternalResources';
|
||||||
|
|
||||||
const gmc = new GM_config({
|
const gmc = new GM_config({
|
||||||
events: {
|
events: {
|
||||||
save () {
|
save () {
|
||||||
this.close();
|
this.close();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
fields: {
|
fields: {
|
||||||
data: {
|
data: {
|
||||||
label: t('config'),
|
label: t('config'),
|
||||||
type: 'textarea',
|
type: 'textarea',
|
||||||
// github prefix org or org/repo | prefix | url ($1 - numeric identifier)
|
// github prefix org or org/repo | prefix | url ($2 - numeric identifier)
|
||||||
default: 'pyside | PYSIDE- | https://bugreports.qt.io/browse/$1'
|
default: 'pyside | PYSIDE- | https://bugreports.qt.io/browse/$1'
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
id: settingsId,
|
id: settingsId,
|
||||||
title: 'Github Link External Resources',
|
title: 'Github Link External Resources',
|
||||||
css: `
|
css: `
|
||||||
#${settingsId} .field_label {
|
#${settingsId} .field_label {
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
@ -62,36 +63,37 @@
|
|||||||
}`
|
}`
|
||||||
});
|
});
|
||||||
|
|
||||||
GM_registerMenuCommand(t('settings'), () => gmc.open());
|
GM_registerMenuCommand(t('settings'), () => gmc.open());
|
||||||
|
|
||||||
const selector = '.js-issue-title.markdown-title,' +
|
const selector = '.js-issue-title.markdown-title,' +
|
||||||
'.js-navigation-open.markdown-title,' +
|
'.js-navigation-open.markdown-title,' +
|
||||||
|
'.commit-title.markdown-title,' +
|
||||||
'#partial-actions-workflow-runs .Link--primary,' + // actions
|
'#partial-actions-workflow-runs .Link--primary,' + // actions
|
||||||
'.repository-content h3.PageHeader-title > span > span,' + // actions
|
'.repository-content h3.PageHeader-title > span > span,' + // actions
|
||||||
'div.my-2.Details-content--hidden,' + // commit message
|
'div.my-2.Details-content--hidden,' + // commit message
|
||||||
'.wb-break-word.width-fit > .color-fg-default.lh-0.mb-2.markdown-title'; // sidebar
|
'.wb-break-word.width-fit > .color-fg-default.lh-0.mb-2.markdown-title'; // sidebar
|
||||||
|
|
||||||
const replace = (node, row) => {
|
const replace = (node, row) => {
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
const re = new RegExp(`\\b(${row[1]}\\d+)\\b(?!<\\/a>|")`, 'g');
|
const re = new RegExp(`\\b(${row[1]}(\\d+))\\b(?!<\\/a>|")`, 'g');
|
||||||
node.innerHTML = node.innerHTML.replace(re, `<a href="${row[2]}">$1</a>`);
|
console.log(re);
|
||||||
|
node.innerHTML = node.innerHTML.replace(re, `<a href="${row[2]}">$1</a>`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let data = '';
|
let data = '';
|
||||||
|
|
||||||
const run = (url) => {
|
const run = (url) => {
|
||||||
const row = data.find(row => url.startsWith(`https://github.com/${row[0]}`));
|
const row = data.find(row => url.startsWith(`https://github.com/${row[0]}`));
|
||||||
|
console.log(data);
|
||||||
console.log(row)
|
if (!row) return;
|
||||||
|
console.log(row);
|
||||||
const matches = document.querySelectorAll(selector)
|
const matches = document.querySelectorAll(selector)
|
||||||
matches.forEach(n => replace(n, row));
|
matches.forEach(n => replace(n, row));
|
||||||
}
|
}
|
||||||
|
|
||||||
const onInit = gmc => new Promise(resolve => {
|
const onInit = gmc => new Promise(resolve => {
|
||||||
let isInit = () => setTimeout(() =>
|
let isInit = () => setTimeout(() => gmc.isInit ? resolve() : isInit(), 0);
|
||||||
gmc.isInit ? resolve() : isInit(), 0);
|
isInit();
|
||||||
isInit();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
onInit(gmc).then(() => {
|
onInit(gmc).then(() => {
|
||||||
@ -102,4 +104,5 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
Loading…
Reference in New Issue
Block a user