需要修改的文件:
splunk/share/splunk/search_mrsparkle/exposed/js/i18n.js
在文件最下面添加代码:
// waiting for the element
function wait_for_element(selector, callback) {
element = document.querySelector(selector);
if (element) {
callback();
} else {
setTimeout(() => {
wait_for_element(selector, callback);
}, 100);
}
}
// change splunk logo
wait_for_element("span[data-role='logo']", () => {
// delete the splunk logo
del_splunk = document.querySelector("i[data-icon='splunk']");
del_gt = document.querySelector("span[data-role='gt']");
del_logo = document.querySelector("span[data-role='logo']");
del_logo.parentNode.removeChild(del_logo);
del_gt.parentNode.removeChild(del_gt);
del_splunk.parentNode.removeChild(del_splunk);
// add new logo img element
new_img= document.createElement("img");
new_img.src = "your img path";
// new_img.width="140";
// new_img.height="30"; // 图片高度为30px能够最佳显示
document.querySelectorAll("a[title='splunk > listen to your data']")[0].appendChild(new_img);
});
曾经使用过如下代码:
// change splunk logo
window.addEventListener('load', function() {
del_splunk = document.querySelector("i[data-icon='splunk']");
del_gt = document.querySelector("span[data-role='gt']");
del_logo = document.querySelector("span[data-role='logo']");
del_logo.parentNode.removeChild(del_logo);
del_gt.parentNode.removeChild(del_gt);
del_splunk.parentNode.removeChild(del_splunk);
new_img= document.createElement("img");
new_img.src = "your img path";
// new_img.width="200";
// new_img.height="30";
document.querySelectorAll("a[title='splunk > listen to your data']")[0].appendChild(new_img);
// });
测试中发现,当Splunk进入某些app后,失效。(无法找到element而出现undefined)
虽不使用,但留作记录。
文章讲述了如何在Splunk的i18n.js文件中添加一个等待元素存在的函数,以便在页面加载后替换Splunk的logo。然而,这个脚本在Splunk进入某些应用时失效,因为找不到元素。提供了两种实现方式,一种使用`window.addEventListener`,另一种是`wait_for_element`函数。
1916

被折叠的 条评论
为什么被折叠?



