-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReplace Potainer localhost URLs.user.js
40 lines (37 loc) · 1.41 KB
/
Replace Potainer localhost URLs.user.js
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
// ==UserScript==
// @name Replace Potainer localhost URLs
// @namespace tampermonkey-replace-localhost-urls
// @version 1.3
// @description Replaces localhost URLs on specific Potainer pages with the full server address, preserving the original port from the URL
// @author SimonTheCoder
// @match https://192.168.1.66:9443/*
// @match https://192.168.1.67:9443/*
// ==/UserScript==
(function() {
'use strict';
// Get the current server address
var serverAddress = window.location.hostname;
// Replace localhost URLs with the full server address, preserving the original port from the URL
const replaceURLs = () => {
const elements = document.querySelectorAll('a[href*="0.0.0.0:"]');
if(elements.length == 0) return;
console.log("find elemnt:", elements);
if(document.title.match(/_67/)!=null){
serverAddress = "192.168.1.67";
}
for (const element of elements) {
const url = element.href;
const replacedURL = url.replace('0.0.0.0:', `${serverAddress}:`);
console.log("replacedURL:",url," -> ", replacedURL);
element.href = replacedURL;
}
};
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.type === "childList" && document.readyState === "complete") {
replaceURLs();
}
});
});
observer.observe(document, { childList: true, subtree: true });
})();