Bulk TB Logger

Easy way to log multiple TBs at once!

目前為 2018-10-02 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Bulk TB Logger
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  Easy way to log multiple TBs at once!
// @author       Technical_13
// @supportURL   https://Discord.me/TheShoeStore
// @include      *logthemall.org/*
// @grant        none
// ==/UserScript==
var isDebug = false;
var intVerbosity = 1;
const ver = '1.3';
const scriptName = 'Bulk TB Logger v' + ver;
console.info( scriptName + ' loaded.' );

function toBoolean( val ) {
    const arrTrue = [ undefined, null, '', true, 'true', 1, '1', 'on', 'yes' ];
    val = ( typeof( val ) === 'string' ? val.toLowerCase() : val );
    return ( arrTrue.indexOf( val ) !== -1 ? true : false );
}

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( '=' );
    if ( arrParam[ 0 ] === 'debug' ) {
        isDebug = toBoolean( arrParam[ 1 ] );
    } else if ( arrParam[ 0 ] === 'verbosity' ) {
        intVerbosity = ( arrParam[ 1 ] ? ( parseInt( arrParam[ 1 ] ) < 0 ? 0 : ( parseInt( arrParam[ 1 ] ) > 9 ? 9 : parseInt( arrParam[ 1 ] ) ) ) : 9 );
    }
} );
if ( isDebug ) { console.log( 'Debug mode is on with verbosity level: %d', intVerbosity ); }
arrParamSets.forEach( function( strParam ) {
    let arrParam = strParam.split( '=' );
    if ( arrParam[ 0 ] === 'debug' || arrParam[ 0 ] === 'verbosity' ) {
        objParams.debug = isDebug;
        objParams.verbosity = intVerbosity;
    } else if ( arrParam[ 0 ] === 'date' ) {
        let arrDate = arrParam[ 1 ].split( '/' );
        if ( isDebug && intVerbosity > 3 ) { console.log( scriptName + ': Date parameter found: %o', arrDate ); }
        if ( arrDate.length !== 3 ) {
            console.error( 'Unable to parse date: please use mm/dd/yyyy format' );
        } else {
            let strMonth = ( arrDate[ 0 ] < 10 ? '0' : '' ) + arrDate[ 0 ];
            let strDate = ( arrDate[ 1 ] < 10 ? '0' : '' ) + arrDate[ 1 ];
            let intYear = ( new Date() ).getFullYear().toString().substr( 2 );
            let intCentury = ( new Date() ).getFullYear().toString().substr( 0, 2 );
console.log( 'pdy: %o; intYear: %o; intCentury: %o', arrDate[ 2 ], intYear, intCentury );
            let strFullYear = ( arrDate[ 2 ] < 100 ? ( arrDate[ 2 ] <= intYear ? intCentury : ( intCentury - 1 ) ) + arrDate[ 2 ] : arrDate[ 2 ] );
            let objDate = ( new Date( strMonth + '-' + strDate + '-' + strFullYear + 'T00:00:00.000Z' ) );
            let intMonth = ( objDate.getMonth() + 1 );
            let intDate = objDate.getDate();
            let intFullYear = ( objDate.getFullYear() + 1 );
            objParams.date = strMonth + '/' + strDate + '/' + strFullYear;
        }
    } else if ( arrParam[ 0 ] === 'spellcheck' ) {
        objParams.spellcheck = toBoolean( arrParam[ 0 ] );
    } else {
        objParams[ arrParam[ 0 ].toLowerCase() ] = ( arrParam[ 1 ] || '' );
    }
} );

( function() {
    if ( isDebug && intVerbosity > 1 ) { console.log( scriptName + ': Parameters: %o', objParams ) }
    if ( objParams.date ) {
        if ( isDebug && intVerbosity > 2 ) { console.log( scriptName + ': Setting date to: %o', objParams.date ) }
        document.getElementsByName( 'datedisc' )[ 0 ].value = objParams.date;
    }
    document.getElementById( 'Codes' ).setAttribute( 'spellcheck', false );
    if ( objParams.codes ) {
        if ( isDebug && intVerbosity > 2 ) { console.log( scriptName + ': Filling in codes: %o', objParams.codes ) }
        document.getElementById( 'Codes' ).value = objParams.codes.toUpperCase();
    }
    document.getElementById( 'LogEntry' ).setAttribute( 'spellcheck', toBoolean( objParams.spellcheck ) );
    if ( objParams.logentry ) {
        if ( isDebug && intVerbosity > 2 ) { console.log( scriptName + ': Filling in Log Entry: %o', objParams.logentry ) }
        document.getElementById( 'LogEntry' ).value = decodeURIComponent( objParams.logentry );
    }
} )();