Give a warning when you have undeployed temporary virtual Munzees, so they don't expire before deployed
目前為
// ==UserScript==
// @name TempZee
// @namespace none
// @version 2019.07.29.0845
// @description Give a warning when you have undeployed temporary virtual Munzees, so they don't expire before deployed
// @supportURL https://discord.me/TheShoeStore
// @author technical13
// @match https://www.munzee.com/*
// @grant none
// ==/UserScript==
// jshint esversion: 6
const ver = '2019.07.29.0845';
var isDebug = false;
var intVerbosity = 0;
const scriptName = 'TempZee v' + ver;
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 );
}
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 = { unknownParams: [] };
arrParamSets.forEach( function( strParam ) {
let arrParam = strParam.split( '=' );
let strParamName = ( arrParam[ 0 ].toLowerCase() || '' );
if ( strParamName === 'verbosity' ) {
isDebug = true;
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() {
'use strict';
log( 0, 'info', 'Script loaded.' );
var username = '';
var isLoggedIn = false;
try { isLoggedIn = ( user_id ? true : false ); } catch ( isNotLoggedIn ) { isLoggedIn = false; }
if ( isLoggedIn ) {
username = $( 'li.user > ul.user-menu > li > a' )[ 0 ].href.split( '/' )[ 4 ];
var undeployedTemporariesURL = 'https://www.munzee.com/m/' + username + '/undeploys/0/type/1245';
$.ajax( { url: undeployedTemporariesURL, success: function( data ) {
var intTemporaries = $( data ).find( '#munzee-holder' ).children().length;
if ( intTemporaries > 0 && document.URL !== undeployedTemporariesURL ) {
$( 'div.navbar-fixed-top' ).after( '<div class="alert alert-warning" style="position: sticky; top: 68px; left: 7.5%; width: 85%; z-index: 99999; text-align: center;" role="alert">I found ' + intTemporaries + ' undeployed temporary virtuals! <wbr><a href="' + undeployedTemporariesURL + '" target="_blank">Open your undeployed temporary virtual list in a new tab.</a></div>' );
}
else if ( intTemporaries > 0 && document.URL === undeployedTemporariesURL ) {
let bypassCORsURL = 'https://cors-anywhere.herokuapp.com/';
$.ajax( { url: bypassCORsURL + 'https://calendar.munzee.com/', success: function( events ) {
var domHTML = $( events )[ 42 ].innerHTML;
var intStart = ( domHTML.indexOf( 'events: ' ) + 8 );
var objFullCal = domHTML.substr( intStart, ( domHTML.indexOf( 'eventRender:' ) - intStart ) )
.replace( /,\s+\],\s+$/, ']' ).replace( /([\n\r\t]|\s{2,})/g, '' ).replace( /''/g, '""' )
.replace( /([^\\])'/g, '$1"' ).replace( /\\'/g, "'" ).replace( /id:/, '"id":' )
.replace( /([,\{] ?)(id|title|start|end|url|className|location|time|attendants):/g, '$1"$2":' );
var objEvents = JSON.parse( objFullCal );
var arrCurrEvents = objEvents.filter( event => {
let intStartIn = ( new Date( event.start ) ).valueOf() - Date.now();
let intEndIn = ( new Date( event.end ) ).valueOf() - Date.now();
if ( intStartIn >= 0 && intStartIn <= 2592000000 ) { return event; }
} );
arrCurrEvents = arrCurrEvents.sort( ( a, b ) => { return ( ( parseInt( a.attendants ) < parseInt( b.attendants ) ) ? 1 : -1 ); } );
var objCurrEvents = {};
var strCurrEventTable = '<table class="table"><tr><th>Date</th><th>Title</th><th>Location</th><th>Attendants</th></tr>';
arrCurrEvents.forEach( event => {
let id = parseInt( event.id );
let start = ( new Date( event.start ) );
let end = ( new Date( event.end ) );
let attendants = parseInt( event.attendants );
objCurrEvents[ id ] = {
id: id,
start: start,
time: event.time,
end: end,
title: event.title,
location: event.location,
url: event.url,
className: event.className,
attendants: attendants
};
strCurrEventTable += '<tr>' +
'<td>' + start.toLocaleDateString( 'en-US', { year: 'numeric', month: 'short', day: 'numeric' } ) + '</td>' +
'<td><a href="https://calendar.munzee.com' + event.url + '">' + event.title + '</a></td>' +
'<td>' + event.location + '</td>' +
'<td>' + attendants + '</td>' +
'</tr>';
} );
strCurrEventTable += '</table>';
$( $( '.col-xs-12' )[ 2 ] ).append( strCurrEventTable ).change();
// console.log('%o',objCurrEvents);
} } );
}
} } );
}
} )();