Lines button in Splunk

try to take over the world!

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Lines button in Splunk
// @namespace    http://enco.io/
// @version      0.7
// @description  try to take over the world!
// @author       Brent
// @include      http://10.1.50.50:8000/*/app/search/search*
// @include      https://splunk.dev.enco.io/*/app/search/search*
// @grant        none
// ==/UserScript==

(function() {
    var splunkNewLinesText = ' | rex mode=sed "s/\\\\\\\\\\\\\\n/\\n/g" | rex mode=sed "s/\\\\\\\\n/\\n/g" | rex mode=sed "s/\\\\\\\\u003c/</g" | rex mode=sed "s/\\\\\\\\u003e/>/g" | rex mode=sed "s/\\\\\\\\\\\\\\x22/\\"/g" | rex mode=sed "s/\\\\\\\\\\\\\\x0D\\\\\\\\\\\\\\x0A//g"';
    var searchInput;

    'use strict';
    var intervalHandle = setInterval(addButton, 100);
    var tryCount = 0;
    function addButton() {
        if(tryCount >= 100) {
               console.log("Failed inserting new button");
             clearInterval(intervalHandle);
        }
        tryCount++;
        var searchAppsTd = document.querySelector('.search-apps');
        if(searchAppsTd == null) {
           //console.log("Search apps is null");
            return;
        }

        clearInterval(intervalHandle);
        searchInput = document.querySelector('.ace_text-input');

        if(searchInput == null) {
           console.log("Unable to find search input.");
        }

        window.addLineFormat = addLineFormat;

        console.log(searchAppsTd);
        var newButton = document.createElement('td');
        newButton.classList.add("search-apps");
        newButton.innerHTML = '<div class="shared-searchbar-submit"><a class="btn" href="#" onclick="window.addLineFormat()"><span>Add newline format</span></div>';
        insertAfter(newButton, searchAppsTd);
    }

    function addLineFormat() {
        //searchInput.value = searchInput.value + " | wow";
        var aceEditorObj = document.querySelector('.ace_editor');
        console.log("Editing ace with ID " + aceEditorObj);
        var editor = ace.edit(aceEditorObj);
        var currentValue = editor.getSession().getValue();
        if(currentValue.indexOf(splunkNewLinesText) >= 0) {
            console.log("Line is already present.");
            return;
        }
        editor.getSession().setValue(currentValue + splunkNewLinesText);
        editor.renderer.updateFull();
    }

    function insertAfter(el, referenceNode) {
        referenceNode.parentNode.insertBefore(el, referenceNode.nextSibling);
    }

    //document.addEventListener('DOMContentLoaded', addButton, false);
})();