Moovit Improver

Adiciona a quantidade de horários e a frequência média entre as viagens ao buscar linhas no Moovit (https://moovitapp.com). Baseado no script Transalvador Improver.

当前为 2024-01-15 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Moovit Improver
// @namespace   none
// @version     1.0.0
// @author	Roger Pestana ([email protected])
// @grant       none
// @license	GNU General Public License v3.0
// @description Adiciona a quantidade de horários e a frequência média entre as viagens ao buscar linhas no Moovit (https://moovitapp.com). Baseado no script Transalvador Improver.
// @include	*moovitapp.com/index/pt-br/transporte_p*time*
// @date	14/jan/2024
// ==/UserScript==

/* jshint laxbreak: true, esversion: 6 */

( function( window ) {
'use strict';

function $qsa( el ) {
	return document.querySelectorAll( el );
}

function format_time( time ) {
	let hour = Math.floor( time / 60 ),
		minutes = Math.floor( time % 60 );

	return ( time < 60 ) ? parseInt( time ) + 'm' : ( `${ ( hour < 10 && '0' ) + hour }h` ) + ( `${ ( minutes < 10 && '0' ) + minutes }m` );
}

// Main function
// @return {undefined}
function moovit_improver() {
	let i, j, hour_diff, hour_part,
		trips = new Map();
	const HOURS_TBODY = '.table-wrapper table tbody td';
	const HOURS_THEAD = '.table-wrapper table thead th';

	for ( i = 0; i < $qsa( HOURS_THEAD ).length; i++ )
		trips.set( i, { list: [], average: [], average_sum: 0 } );
	
	const HOURS_THEAD_COUNT = trips.size;

	// Gets the data
	$qsa( HOURS_TBODY ).forEach( ( hour, index ) => {
		if ( hour.textContent === '-' )
			return;
		
		hour_part = hour.textContent.split( ':' );
		trips.get( index % HOURS_THEAD_COUNT ).list.push( parseInt( hour_part[ 0 ] ) + ( parseInt( hour_part[ 1 ] ) / 60 ) );
	} );

	// Gets the average between trips
	for ( i = 0; i < trips.size; i++ ) {
		for ( j = 0; j < trips.get( i ).list.length - 1; j++ ) {
			hour_diff = parseFloat( parseFloat( ( trips.get( i ).list[ j + 1 ] - trips.get( i ).list[ j ] ) * 60 ).toPrecision( 4 ) );
			trips.get( i ).average_sum += hour_diff;
			trips.get( i ).average.push( hour_diff );
		}

		trips.get( i ).average_sum = trips.get( i ).average_sum / trips.get( i ).average.length;
	}

	// Shows the data
	$qsa( HOURS_THEAD ).forEach(
		( hour_block, index ) => hour_block.innerHTML +=
			`<br /><small>Viagens: ${ trips.get( ( index % HOURS_THEAD_COUNT ) ).list.length }`
			+ `<br />Média entre as viagens: ${ format_time( trips.get( ( index % HOURS_THEAD_COUNT ) ).average_sum ) }</small>`
	);
}

// Inits
if ( location.href.indexOf( 'https://moovitapp.com/index/pt-br/transporte_p%C3%BAblico-time-' ) !== -1 )
	window.onload = moovit_improver;
}( window ) );