This works for now. Allows you to hide, show and toggle objects by name using a regular expression match. Going to add another version that takes a layer name tomorrow. Then I can hook up some buttons to make it easy to use. Any idea how to find all the objects on the current page I'm working gon? Not the Player's page, my active page. //==============================================================================================
//
// HideObjects.js (v1.0)
//
// !HideObjects hide [name]
// !HideObjects show [name]
// !HideObjects toggle [name]
//
//==============================================================================================
var HideObjects =
{
SCRIPT_NAME : "HideObjects.js",
HIDE_OFFSET : 10000,
ISHIDDEN_OFFSET : 1000,
CMD_HELP : "!HideObjects help",
CMD_HIDE : "!HideObjects hide",
CMD_SHOW : "!HideObjects show",
CMD_TOGGLE : "!HideObjects toggle",
ChatTemplate : _.template( "/w GM <div style=\"padding:1px 3px; border: 1px solid <%=border%>; background: <%=background%>; color: <%=color%>; font-size: 80%;\"><%=text%><br><br></div>" ),
//==============================================================================================
//==============================================================================================
showHelp : function ()
{
sendChat( HideObjects.SCRIPT_NAME,
HideObjects.ChatTemplate(
{
border: "#00529B",
background: "#BDE5F8",
color: "#00529B",
text: "<b>Help:</b><br>" +
"<dl>" +
"<dt>hide [name]</dt><dd>Hide all objects matching [name].</dd>" +
"<dt>show [name]</dt><dd>Show all objects matching [name].</dd>" +
"<dt>toggle [name]</dt><dd>Toggle the hidden state of all objects matching [name].</dd>" +
"</dl> " +
"All [name] params can be a regular expression."
} ));
},
//==============================================================================================
//==============================================================================================
isHidden : function( object )
{
var top = object.get( "top" );
if ( top <= -HideObjects.ISHIDDEN_OFFSET )
return true;
return false;
},
//==============================================================================================
//==============================================================================================
show : function( object, bShow )
{
var bHidden = HideObjects.isHidden( object )
var top = object.get( "top" );
if ( bShow == true )
{
if ( bHidden == true )
object.set( "top", top + HideObjects.HIDE_OFFSET );
}
else
{
if ( bHidden == false )
object.set( "top", top - HideObjects.HIDE_OFFSET );
}
//log( top + "=>" + object.get( "top" ) );
},
//==============================================================================================
//==============================================================================================
onShowByRegExp : function( searchString, bShow )
{
//log( "onShowByRegExp:" );
var pattern = new RegExp( searchString );
var allObjects = getAllObjs();
for( var index = 0; index < allObjects.length; ++index )
{
var object = allObjects[index];
var name = object.get( "name" );
if ( pattern.test( name ) == true )
{
//log( "found: " + name );
HideObjects.show( object, bShow );
}
}
},
//==============================================================================================
//==============================================================================================
onToggleByRegExp : function( searchString )
{
//log( "onToggleByRegExp:" );
var pattern = new RegExp( searchString );
var allObjects = getAllObjs();
for( var index = 0; index < allObjects.length; ++index )
{
var object = allObjects[index];
var name = object.get( "name" );
if ( pattern.test( name ) == true )
{
//log( "found: " + name );
var bHidden = HideObjects.isHidden( object );
HideObjects.show( object, bHidden );
}
}
},
//==============================================================================================
//==============================================================================================
onApiCommand : function( cmd )
{
//log( "OnApiCommand: " + cmd );
if ( cmd.startsWith( HideObjects.CMD_HELP ) == true )
{
HideObjects.showHelp();
}
else
if ( cmd.startsWith( HideObjects.CMD_HIDE ) == true )
{
HideObjects.onShowByRegExp( cmd.slice( HideObjects.CMD_HIDE.length + 1 ), false );
}
else
if ( cmd.startsWith( HideObjects.CMD_SHOW ) == true )
{
HideObjects.onShowByRegExp( cmd.slice( HideObjects.CMD_SHOW.length + 1 ), true );
}
else
if ( cmd.startsWith( HideObjects.CMD_TOGGLE ) == true )
{
HideObjects.onToggleByRegExp( cmd.slice( HideObjects.CMD_TOGGLE.length + 1 ) );
}
},
};
//==================================================================================================
//==================================================================================================
on( "chat:message", function( msg )
{
try
{
if ( msg.type == "api" )
{
HideObjects.onApiCommand( msg.content );
}
}
catch( err )
{
sendChat( "*** HideObjects Exception: ", err.message );
}
} );
log( "HideObjects COMPILED [" + (new Date()) + "]");