How do I get HTML of an object in App Lab?

331 Views Asked by At

I'm using Code.org's App Lab to make a chatroom, and the chat messages are shown using the innerHTML() function.

However, there doesn't seem to be a way to get the inner HTML of an object.

I've tried assigning the HTML to a variable, such as html, and when html is updated, the inner HTML of chatArea is updated as well:

var html;
onRecordEvent("Messages", {}, function (rec) {
  html = html + "<div style='background: white; border-radius: 5px; padding: 10px'><div><b>" + rec.username + "</b></div><div>" + rec.message + "</div></div>";
  innerHTML("chatArea", html);
});

However, this requires that chatArea is empty at first, otherwise it will be emptied the first time html is edited.

Is there any way to get the innerHTML of an object, since document is disabled?

1

There are 1 best solutions below

0
On

The only way I could see this being done is by using tampermonkey or some script to fetch it from the actual source.

I haven't seen anything on getting the html either so I'm sorry there. Also you can just send the messages to a textarea without html.

A little bit off-track, you can create a record every time a new chat is sent then ever so often loop thru the chat records to see what new chats should be added. This is a tadbit of code I always use for my chat screens for the Dungeon Destiny games.

//chat info
go("goChat", "warnChat");
go("acceptWarn", "chatt");
go("backChat", "home");
 

sayCS('home', 'announcements');
sayCS('warnChat', 'warnTxt');
sayCS('tosLog', 'tosLogTxt');
sayCS('tos', 'tosTxt');

function sayCS(scr, text){
  onEvent(scr, "keydown", function(event){
    if(event.key=='Alt'){
      playSpeech(getText(text), "female", "English (UK)");
    }
  });
}

onEvent("chatt", "keydown", function(event){
  if(event.key=="Enter"){
    if (getText("setMessage")==''||null) {
      setProperty("setMessage", "placeholder", "Please Type Something Before You Send It");
      setTimeout(function() {
        setProperty("setMessage", "placeholder", "Type A Message Here");
      }, 2000);
    } else if(getText("setMessage")!=''||null) {
        if(username != '' ||null){
          createRecord("chat", {from: username, message:(getText("setMessage"))}, function(){});
        } else if(username == '' ||null){
            createRecord("chat", {from: username, message:(getText("setMessage"))}, function(){});
        }
    }
    setText("setMessage", "");
  }
});

var messages;
function setChat() {
  messages=[];
  readRecords("chat", {}, function(records) {
    for (var i =0; i < records.length; i++) {
      if(!records[i].message.includes("fuck")){
        appendItem(messages,(records[i]).from+ ": "+(records[i]).message);
      }
      }
    messages.reverse();
    setText("chat", messages.join("\n"));
  });
}