-
-
Notifications
You must be signed in to change notification settings - Fork 183
Expand file tree
/
Copy pathgithub-allow-repo-transfer.user.js
More file actions
59 lines (50 loc) · 2.04 KB
/
github-allow-repo-transfer.user.js
File metadata and controls
59 lines (50 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// ==UserScript==
// @name GitHub Allow Repo Transfer
// @version 1.0.0
// @description Automatically fills repo name on transfer form on GitHub
// @license MIT
// @author Rob Garrison, Bluscream
// @namespace https://github.com/Mottie
// @match https://github.com/*/*/transfer
// @run-at document-idle
// @grant GM_registerMenuCommand
// @grant GM.registerMenuCommand
// @grant GM.addStyle
// @grant GM_addStyle
// @grant GM.getValue
// @grant GM_getValue
// @grant GM.setValue
// @grant GM_setValue
// @icon https://github.githubassets.com/pinned-octocat.svg
// @updateURL https://raw.githubusercontent.com/Mottie/Github-userscripts/master/github-allow-repo-transfer.user.js
// @downloadURL https://raw.githubusercontent.com/Mottie/Github-userscripts/master/github-allow-repo-transfer.user.js
// @supportURL https://github.com/Mottie/GitHub-userscripts/issues
// ==/UserScript==
(function() {
'use strict';
// console.warn(`start`);
function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
function fillTransferForm() {
// Find the input field
const inputField = document.querySelector('input[data-testid=transfer-repo-confirmation]');
if (!inputField) return;
// Find the label span
const labelSpan = getElementByXpath('/html/body/div[1]/div[5]/main/react-app/div/form/div[3]/div[3]/div/label/span/div/b');
if (!labelSpan) return;
// Get the text content of the label span
const labelText = labelSpan.textContent.trim();
console.warn(`labelText: ${labelText}`);
// Fill the input field
inputField.value = labelText;
// console.warn(`finished`);
}
// Wait for the DOM to load
if (document.readyState === 'loading') {
window.addEventListener('DOMContentLoaded', fillTransferForm);
} else {
fillTransferForm();
}
// console.warn(`end`);
})();