-
-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathnpm-trusted-publisher.user.js
More file actions
104 lines (86 loc) · 3.6 KB
/
Copy pathnpm-trusted-publisher.user.js
File metadata and controls
104 lines (86 loc) · 3.6 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// ==UserScript==
// @name NPM Trusted Publisher Auto-fill for @arborium
// @namespace http://tampermonkey.net/
// @version 2.0
// @description Auto-fill trusted publisher settings for @arborium packages
// @author You
// @match https://www.npmjs.com/package/@arborium/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Configuration - edit these values
const CONFIG = {
repositoryOwner: 'bearcove',
repositoryName: 'arborium',
workflowFilename: 'ci.yml',
environmentName: '' // leave empty
};
function setInputValue(input, value) {
// React inputs need special handling
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;
nativeInputValueSetter.call(input, value);
input.dispatchEvent(new Event('input', { bubbles: true }));
input.dispatchEvent(new Event('change', { bubbles: true }));
}
function clickIfExists(selector) {
const el = document.querySelector(selector);
if (el) {
console.log(`[NPM Trusted Publisher] Clicking: ${selector}`);
el.click();
return true;
}
return false;
}
function fillFormIfReady() {
const ownerInput = document.querySelector('#oidc_repositoryOwner');
if (!ownerInput) return false;
const repoInput = document.querySelector('#oidc_repositoryName');
const workflowInput = document.querySelector('#oidc_workflowName');
const envInput = document.querySelector('#oidc_githubEnvironmentName');
if (ownerInput) setInputValue(ownerInput, CONFIG.repositoryOwner);
if (repoInput) setInputValue(repoInput, CONFIG.repositoryName);
if (workflowInput) setInputValue(workflowInput, CONFIG.workflowFilename);
if (envInput) setInputValue(envInput, CONFIG.environmentName);
console.log('[NPM Trusted Publisher] Form filled!');
return true;
}
let formFilled = false;
let navigated = false;
function tick() {
// Only run on visible/active tab
if (document.hidden) return;
// If not on /access page, navigate there (only once)
if (!window.location.pathname.endsWith('/access')) {
if (!navigated) {
navigated = true;
const currentPath = window.location.pathname;
const accessPath = currentPath.replace(/\/?$/, '/access');
console.log(`[NPM Trusted Publisher] Navigating to ${accessPath}`);
window.location.href = accessPath;
}
return;
}
// Click "Use security key" button if present
clickIfExists('button.e64d5a00');
// Click "GitHub Actions" button to reveal the form
clickIfExists('button[aria-label="Add Trusted Publisher connection for GitHub Actions"]');
// Try to fill the form
if (!formFilled && fillFormIfReady()) {
formFilled = true;
}
// Click submit button (keep trying even after formFilled)
if (formFilled) {
const submitBtn = document.querySelector('button[aria-label="Set up new trusted publisher connection"]');
if (submitBtn && !submitBtn.disabled) {
console.log('[NPM Trusted Publisher] Clicking submit...');
submitBtn.click();
}
}
}
console.log('[NPM Trusted Publisher] Script loaded, starting...');
// Run tick every 500ms forever
setInterval(tick, 500);
// Also run immediately
setTimeout(tick, 1000);
})();