Replies: 1 comment
-
Bonus: Here's my code for fetching my external IP address, and sanitizing the page before posting screenshots. /************************************
** common **
************************************/
// based on: https://stackoverflow.com/a/34559316
function replaceAllText(node, pattern, replacement) {
if (node.nodeType == 3) {
node.data = node.data.replaceAll(pattern, replacement);
}
if (node.nodeType == 1 && node.nodeName != "SCRIPT") {
for (var i = 0; i < node.childNodes.length; i++) {
replaceAllText(node.childNodes[i], pattern, replacement);
}
}
}
/************************************
** External IP Address **
************************************/
function fetchExternalIP() {
fetch('https://api.ipify.org?format=json') // responds with json
.then((response) => response.json())
.then((data) => {
const targets = document.querySelectorAll('.information-widget-greeting span');
for (const target of targets) {
replaceAllText(target, '{MY_IP}', data.ip);
}
})
.catch((error) => {
console.error('Error fetching IP address:', error);
});
}
/************************************
** Sanitize **
************************************/
function sanitizeIdentifiers(options) {
for (const opts of options) {
const targets = !!opts.selector
? document.querySelectorAll(opts.selector)
: [document.body];
for (const target of targets) {
replaceAllText(target, opts.pattern, opts.replacement);
}
}
}
function initSanitizeButton(options) {
// Adds a button to the bottom right pf the page
const button = document.createElement('button');
button.innerHTML = 'sanitize';
button.className = 'w-24 rounded-md m-1 bg-theme-300/20 dark:bg-white/10 text-theme-700 dark:text-theme-200 cursor-pointer';
button.onclick = function(){
sanitizeIdentifiers(options);
return false;
};
document.querySelector('#revalidate').after(button);
}
/************************************
** MAIN **
************************************/
fetchExternalIP();
initSanitizeButton([
{pattern: /your-domain-name\.net/mgi, replacement: 'redacted.domain'},
{pattern: /https:\/\/.*?\.myunraid.net/mgi, replacement: 'http://redacted.myunraid.net'},
{pattern: /\b((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}/mg, replacement: '111.111.111.111' },
// Calendar entries
{selector: '.service[data-name="agenda"] .flex-row .flex-row div', pattern: /[a-z]/mgi, replacement: '*'}
]); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Sharing my code to add markdown support. This is currently works in Service Descriptions and Greeting Widgets. You can add other sections by editing the parameters of
initMarkdown()
.custom.js
custom.css
Sample usage: widgets.yaml
Sample usage: services.yaml
Beta Was this translation helpful? Give feedback.
All reactions