diff --git a/make.sh b/make.sh index c87c091..3f2190d 100755 --- a/make.sh +++ b/make.sh @@ -25,6 +25,7 @@ Options: -c --compress-css Compress CSS -j --compress-js Compress JavaScript -s --compress-svg Compress SVG + -l --logging-level Set logging level (0=all 10=trace 20=info 30=warning 40=error) -e --package-extension Package extension for distribution (safari-legacy requires private key) -d --no-debug-js Remove JavaScript source maps to prevent debugging -v --no-version-increment Disable automatic version incrementing @@ -41,7 +42,7 @@ while :; do -h|-\?|--help) show_help ;; -p|--profile) [[ "$2" ]] && profile=$2 ;; --profile=?*) profile=${1#*=} ;; - -t|--target) shift ;; + -l|-t|--logging-level|--target) shift ;; -?*) ;; *) break esac @@ -56,6 +57,7 @@ case $profile in compress_js=1 debug_js=0 package_ext=1 + logging_level=100 ;; release) compress_svg=1 @@ -63,6 +65,7 @@ case $profile in compress_js=1 debug_js=1 package_ext=0 + logging_level=40 ;; *) compress_svg=0 @@ -70,6 +73,7 @@ case $profile in compress_js=0 debug_js=1 package_ext=0 + logging_level=0 profile="debug" ;; esac @@ -89,6 +93,8 @@ while :; do -v|--no-version-increment) update_version=0 ;; -t|--target) [[ "$2" ]] && targets=$2 && shift ;; --target=?*) targets=${1#*=} ;; + -l|--logging-level) [[ "$2" ]] && logging_level=$2 && shift ;; + --logging-level=?*) logging_level=${1#*=} ;; -p|--profile) shift ;; -?*) ;; *) break ;; @@ -315,8 +321,13 @@ for target in "${targets[@]}"; do scripts_path=$(get_absolute_path "out/${EXTENSION_NAME}-${target}${target_extension}${common_file_path}/scripts") + defines_path="${scripts_path}/defines.js" extern_path=$(fix_absolute_path "${scripts_path}/externs.js") + defines_processed_path=$(echo "${defines_path%.*}" | sed -E 's|[/@\]|$|g' | sed -E 's/[-. ]/_/g' | sed -e 's/\[/%5B/g' -e 's/]/%5D/g' -e 's/>/%3E/g' -e 's/= LOGGING_LEVEL) ? + console.trace.bind(console) : function(){}; + +/** + * Logs informational message to console + */ +export const info = (LoggingLevel.INFO >= LOGGING_LEVEL) ? + console.info.bind(console, loggingPrefix) : function(){}; + +/** + * Logs warning message to console + */ +export const warn = (LoggingLevel.WARNING >= LOGGING_LEVEL) ? + console.warn.bind(console, loggingPrefix) : function(){}; + +/** + * Logs error message to console + */ +export const error = (LoggingLevel.ERROR >= LOGGING_LEVEL) ? + console.error.bind(console, loggingPrefix) : function(){}; \ No newline at end of file diff --git a/src/common/scripts/main.js b/src/common/scripts/main.js index e8c435f..eafcdb0 100644 --- a/src/common/scripts/main.js +++ b/src/common/scripts/main.js @@ -1,4 +1,4 @@ -'use strict'; +import { info, error } from './logger.js' /** * @typedef {{ @@ -18,9 +18,6 @@ let PiperResource; -/** @define {boolean} - Flag used by closure compiler to remove logging */ -const COMPILED = false; - const BUTTON_ID = 'PiPer_button'; const TRACK_ID = 'PiPer_track'; @@ -31,15 +28,6 @@ let /** boolean */ showingCaptions = false; let /** boolean */ showingEmptyCaption = false; let /** string */ lastUnprocessedCaption = ''; -/** - * Logs message to console - * - * @param {string} message - Message to log - */ -const log = function(message) { - !COMPILED && console.log('PiPer: ' + message); -}; - /** * Returns localized button title * @@ -100,7 +88,7 @@ const addButton = function(parent) { // Get the video element and bypass caching to accomodate for the underlying video changing (e.g. pre-roll adverts) const video = /** @type {?HTMLVideoElement} */ (currentResource.videoElement(true)); if (!video) { - log('Unable to find video'); + error('Unable to find video'); return; } @@ -108,7 +96,7 @@ const addButton = function(parent) { video.webkitSetPresentationMode(mode); }); - log('Picture in Picture button created'); + info('Picture in Picture button created'); } // Inject button into correct place @@ -129,14 +117,14 @@ const prepareCaptions = function(video) { for (let trackId = allTracks.length; trackId--;) { if (allTracks[trackId].label === TRACK_ID) { track = allTracks[trackId]; - log('Existing caption track found'); + info('Existing caption track found'); break; } } if (track) return; // Otherwise create new caption track - log('Caption track created'); + info('Caption track created'); track = video.addTextTrack('captions', TRACK_ID, 'en'); track.mode = 'showing'; }; @@ -159,7 +147,7 @@ const videoPresentationModeChanged = function(event) { lastUnprocessedCaption = ''; processCaptions(); - log('Video presentation mode changed (showingCaptions: ' + showingCaptions + ')'); + info('Video presentation mode changed (showingCaptions: ' + showingCaptions + ')'); }; /** @@ -228,7 +216,7 @@ const processCaptions = function() { } } caption = caption.trim(); - log('Showing caption "' + caption + '"'); + info('Showing caption "' + caption + '"'); track.addCue(new VTTCue(video.currentTime, video.currentTime + 60, caption)); showingEmptyCaption = false; }; @@ -246,7 +234,7 @@ const mutationObserver = function() { if (buttonParent) { addButton(buttonParent); if (currentResource.buttonDidAppear) currentResource.buttonDidAppear(); - log('Picture in Picture button added to webpage'); + info('Picture in Picture button added to webpage'); } }; @@ -1061,7 +1049,7 @@ resources['youtu'] = resources['youtube']; const domainName = location.hostname && location.hostname.match(/([^.]+)\.(?:co\.)?[^.]+$/)[1]; if (domainName in resources) { - log('Matched site ' + domainName + ' (' + location + ')'); + info('Matched site ' + domainName + ' (' + location + ')'); currentResource = resources[domainName]; initialiseCaches(); diff --git a/src/safari-legacy/update.plist b/src/safari-legacy/update.plist index e911f0d..8d10d21 100644 --- a/src/safari-legacy/update.plist +++ b/src/safari-legacy/update.plist @@ -10,7 +10,7 @@ CFBundleShortVersionString CFBundleVersion - 160 + 161 Developer Identifier BQ6Q24MF9X URL