Last active
October 9, 2018 18:07
-
-
Save jettero/40c0bbe05b4f39d7e6819ae4086ae7a0 to your computer and use it in GitHub Desktop.
Splunk insists on using the locale based time in the _time column of search results; even though my LC_TIME locale is en_DK.utf8; this gives me a nice short big-to-small time format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Splunk-time to Rational-time | |
| // @namespace org.voltar.splunktime2rational | |
| // @version 0.31 | |
| // @downloadURL https://goo.gl/7qizYC | |
| // @description Splunk insists on using the locale based time in the _time column of search results; even though my LC_TIME locale is en_DK.utf8; this gives me a nice short big-to-small time format | |
| // @author https://github.com/jettero | |
| // @require https://openuserjs.org/src/libs/sizzle/GM_config.js | |
| // @match *://*splunk*/*-*/app/*/search* | |
| // @match *://*/splunk/*-*/app/*/search* | |
| // @match *://*splunk*/*-*/app/*/report* | |
| // @match *://*/splunk/*-*/app/*/report* | |
| // @grant GM_setValue | |
| // @grant GM_getValue | |
| // @grant GM_registerMenuCommand | |
| // ==/UserScript== | |
| (function() { | |
| var fix_times = function(ev){ | |
| var format = GM_config.get("format"); | |
| var sformat = ('<span style="white-space: nowrap">' + format + '</span>').replace("|","</span><br><span>"); | |
| var nowrap = GM_config.get("nowrap"); | |
| $(ev.target).find('*[data-time-iso]').each(function(){ | |
| var new_html = $(this).html( new Date($(this).attr('data-time-iso')).strftime(sformat) ); | |
| if( nowrap ) | |
| new_html.find("span").css({'white-space': 'nowrap'}); | |
| }); | |
| }; | |
| GM_config.init({ | |
| 'id': 'MyConfig', | |
| 'fields': { | |
| 'format': { | |
| 'label': 'strftime-format', | |
| 'title': 'pipe characters split the resulting <span>', | |
| 'type': 'text', | |
| 'default': '%Y-%m-%d|%H:%M:%S' | |
| }, | |
| 'nowrap': { | |
| 'label': 'add nowrap style to spans', | |
| 'type': 'checkbox', | |
| 'default': true | |
| } | |
| }, | |
| 'events': { | |
| 'save': function(values) { | |
| fix_times({'target': document.body}); | |
| GM_config.close(); | |
| } | |
| } | |
| }); | |
| GM_registerMenuCommand('Splunk-time to Rational-time Preferences', function(){GM_config.open();}); | |
| $(window).on('DOMNodeInserted', fix_times); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment