// ==UserScript==
// @name MHQ ago
// @namespace none
// @version 2018.11.26.1340
// @description Show timestamps
// @supportURL https://Discord.me/TheShoeStore
// @author technical13
// @match https://www.munzee.com/m/*
// @grant none
// ==/UserScript==
// jshint esversion: 6
var isDebug = false;
var intVerbosity = 0;
const ver = '2018.11.26.1340';
const scriptName = 'MHQ ago v' + ver;
function log( intV, strConsole, strLog, ...arrArgs ) {
if ( strConsole === undefined ) { strConsole = 'log'; }
if ( strLog === undefined ) { strLog = '%o'; }
if ( intVerbosity >= intV && ( strConsole === 'groupEnd' ) ) { console[ strConsole ](); }
if ( intV === 0 || ( isDebug && intVerbosity >= intV ) ) { console[ strConsole ]( '[%i]: %s: ' + strLog, intV, scriptName, ...arrArgs ); }
}
const intParamsStart = ( document.URL.indexOf( '?' ) + 1 );
const strParams = document.URL.substr( intParamsStart );
const arrParamSets = strParams.split( '&' );
var objParams = {};
arrParamSets.forEach( function( strParam ) {
let arrParam = strParam.split( '=' );
let strParamName = ( arrParam[ 0 ].toLowerCase() || '' );
if ( strParamName === 'verbosity' ) {
isDebug = toBoolean( arrParam[ 1 ] );
intVerbosity = ( arrParam[ 1 ] ? ( parseInt( arrParam[ 1 ] ) < 0 ? 0 : ( parseInt( arrParam[ 1 ] ) > 9 ? 9 : parseInt( arrParam[ 1 ] ) ) ) : 9 );
} else if ( strParamName === 'debug' ) {
isDebug = toBoolean( arrParam[ 1 ] );
intVerbosity = 1;
}
} );
log( 1, 'warn', 'Debug mode is on with verbosity level: %o', intVerbosity );
log( 1, 'groupCollapsed', 'Verbosity options: (click to expand)' );
log( 1, 'log', '1) Summary\n2) Parameters retrieved from URL\n3) Variables set to objParams\n4) Function returns\n9) ALL debugging info and this notice.' );
log( 1, 'groupEnd' );
function toBoolean( val ) {
const arrTrue = [ undefined, null, '', true, 'true', 1, '1', 'on', 'yes' ];
val = ( typeof( val ) === 'string' ? val.toLowerCase() : val );
log( 4, 'log', 'toBoolean() is returning: %o', ( arrTrue.indexOf( val ) !== -1 ? true : false ) );
return ( arrTrue.indexOf( val ) !== -1 ? true : false );
}
const objFullTimeStringHQ = {
year: 'numeric', month: 'long', day: 'numeric',
hour: 'numeric', minute: 'numeric', second: 'numeric',
timeZone: 'America/Chicago', timeZoneName: 'short', hour12: false };
const objShorTimeStringHQ = {
year: 'numeric', month: 'short', day: 'numeric',
hour: 'numeric', minute: 'numeric', second: 'numeric',
timeZone: 'America/Chicago', timeZoneName: 'short', hour12: false };
const address = document.URL.replace( /https?:\/\/www\.munzee\.com\/m\//i, '' ).split( '/' );
const userName = ( address[ 0 ] || undefined );
const subPage = ( address[ 1 ] || undefined );
log( 1, 'info', 'userName = %s\nsubPage = %s', userName, subPage );
( function() {
'use strict';
log( 0, 'info', 'Script loaded.' );
$( '.deployed-at' ).each( function( i, elem ) {
var strDeployed = new Date( $( elem ).attr( 'data-deployed-at' ) );
switch( subPage ) {
case 'archived' :
case 'captures' :
case 'deploys' :
$( elem ).append( '<br />' + strDeployed.toLocaleDateString( 'en-US', objShorTimeStringHQ ) );
break;
case 'blast' :
case 'feed' :
default:
$( elem ).text( strDeployed.toLocaleDateString( 'en-US', objFullTimeStringHQ ) + ' (' + $( elem ).text() + ')' );
}
} );
$( '.captured-at' ).each( function( i, elem ) {
var strCaptured = new Date( $( elem ).attr( 'data-captured-at' ) );
switch( subPage ) {
case 'archived' :
case 'captures' :
case 'deploys' :
$( elem ).append( '<br />' + strCaptured.toLocaleDateString( 'en-US', objShorTimeStringHQ ) );
break;
case 'blast' :
case 'feed' :
default:
$( elem ).text( strCaptured.toLocaleDateString( 'en-US', objFullTimeStringHQ ) + ' (' + $( elem ).text() + ')' );
}
} );
$( '.blasted-at' ).each( function( i, elem ) {
var strBlasted = new Date( $( elem ).attr( 'data-blasted-at' ) );
$( elem ).append( '<p>' + strBlasted.toLocaleDateString( 'en-US', objFullTimeStringHQ ) + '</p>' );
} );
} )();