Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function tryToStripXpathes( xpathes ) {
- var standard_axis_number = [ -1, -1 ], // standard number for each half
- max_axis_idx = [ [], [] ], // for each half
- axis_number, half_type, cnt = 0,
- i, l, j, len, idx;
- for ( i = 0, l = xpathes.length; i < l; i += 1 ) {
- half_type = ( i & 1 ); // Bitwise! will be 0 for even, 1 for odd half
- axis_number = xpathes[i].split( "/" ).length; // -1 doesn't matter
- if ( -1 === standard_axis_number[half_type] ) {
- standard_axis_number[half_type] = axis_number;
- max_axis_idx[half_type].push( i ); // remember xpath with max axis
- } else if ( standard_axis_number[half_type] < axis_number ) {
- xpathes[i] = xpathes[i].replace(
- /\/(a|span|b|i|em|strong)$/,
- ''
- );
- i -= 1; // One step back and check number of axis again
- } else if ( standard_axis_number[half_type] > axis_number ) {
- // strip last axis from every xpathes with max axis
- for ( j = 0, len = max_axis_idx[half_type].length; j < len; j += 1 ) {
- idx = max_axis_idx[half_type][j];
- xpathes[idx] = xpathes[idx].replace(
- /\/(a|span|b|i|em|strong)$/,
- ''
- );
- }
- standard_axis_number[half_type] -= 1;
- i -= 1; // One step back and check number of axis again
- } else {
- max_axis_idx[half_type].push( i ); // remember xpath with max axis
- }
- }
- return xpathes;
- }
Advertisement
Add Comment
Please, Sign In to add comment