Printing a transcript

This works in the desktop player, in Chrome, and in Firefox for me.


The game (UPDATED):

CLICK HERE TO VIEW THE GAME'S CODE
<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Printing a Transcript">
    <gameid>e007e8ee-d46d-4838-9d6d-8b69a814c51b</gameid>
    <version>0.0.9</version>
    <firstpublished>2017</firstpublished>
    <showscore type="boolean">false</showscore>
    <feature_advancedscripts />
    <commandpane />
    <subtitle>(version {game.version})</subtitle>
    <showpanes />
    <inituserinterface type="script"><![CDATA[
      JS.setCommands ("Print_Transcript;Clear_Screen;<br/>;Jump;Look;Xyzzy;Restart;<br/><br/>;Print", "black")
    ]]></inituserinterface>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <description type="script"><![CDATA[
      msg ("<img src=\"https://i.imgur.com/FOIjtApb.png\" />")
    ]]></description>
    <enter type="script">
    </enter>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
  </object>
  <command name="JScmd">
    <pattern>JS.#text#</pattern>
    <script>
      JS.eval (text)
    </script>
  </command>
  <command name="print">
    <pattern>print</pattern>
    <script>
      if (not game.showpanes) {
        JS.print ()
      }
      else {
        ask ("NOTE: THIS WILL NOT PRINT ANY CLEARED TEXT!\n(You can enter TRANSCRIPT to print all output.)\n\nWould you like to hide the panes?") {
          if (result) {
            JS.panesVisible (false)
            JS.eval ("print();alert(\"Printing is complete!\");panesVisible(true);")
          }
          else {
            JS.eval ("print();alert(\"Printing is complete!\");")
          }
        }
      }
    </script>
  </command>
  <command name="transcript">
    <pattern>script;transcript;print transcript;print_transcript</pattern>
    <script>
      JS.eval ("var iframe = document.createElement('iframe');document.body.appendChild(iframe);iframe.contentWindow.document.write($('#divOutput').html());iframe.contentWindow.print();document.body.removeChild(iframe);")
    </script>
  </command>
  <command name="clearthescreencmd">
    <pattern>clr;clear;clear_screen;clear screen</pattern>
    <script>
      JS.clearScreen ()
    </script>
  </command>
  <command name="restart">
    <pattern>restart</pattern>
    <script><![CDATA[
      JS.eval ("if (webPlayer){window.location.reload();} else {addTextAndScroll('<h1><center>You are playing offline.<br/>You will need to press CTRL+R</center></h1>');}")
    ]]></script>
  </command>
  <javascript src="javascript.js" />
</asl>

The JS (UPDATED):

CLICK HERE TO VIEW THE JS
var clearedOnce = false;

clearScreen = function() {
    addText("<hr/>SCREEN CLEARED");
    $("#divOutput").append("<hr class=\"clearedAbove\" />");
    if (!clearedOnce){
      addText("<style>#divOutput > .clearedScreen { display: none; }</style>");
    }
    clearedOnce = true;
    $("#divOutput").children().addClass("clearedScreen");
    $("#divOutput").css("min-height", 0);
    createNewDiv("left");
    beginningOfCurrentTurnScrollPosition = 0;
    setTimeout(function () {
        $("html,body").scrollTop(0);
    }, 100);
}
  

http://textadventures.co.uk/games/view/dbtxp7q5euw7ygj6vodavw/printing-a-transcript

(UPDATED)


BIG thanks to mrangel!


BONUS CODE:

Command
Command Pattern: print

Script:

if (not game.showpanes) {
  JS.print ()
}
else {
  ask ("NOTE: THIS WILL NOT PRINT ANY CLEARED TEXT!\n(You can enter TRANSCRIPT to print all output.)\n\nWould you like to hide the panes?") {
    if (result) {
      JS.panesVisible (false)
      JS.eval ("print();alert(\"Printing is complete!\");panesVisible(true);")
    }
    else {
      JS.eval ("print();alert(\"Printing is complete!\");")
    }
  }
}

Here's the one-liner for printing the transcript (only works with the separate clearScreen function):

Command
Command pattern: script;transcript;print transcript

Script

JS.eval("var iframe = document.createElement('iframe');document.body.appendChild(iframe);iframe.contentWindow.document.write($('#divOutput').html());iframe.contentWindow.print();document.body.removeChild(iframe);")

clearScreen (in the JS file, which needs to be 'included')

var clearedOnce = false;

clearScreen = function() {
    addText("<hr/>SCREEN CLEARED");
    $("#divOutput").append("<hr class=\"clearedAbove\" />");
    if (!clearedOnce){
      addText("<style>#divOutput > .clearedScreen { display: none; }</style>");
    }
    clearedOnce = true;
    $("#divOutput").children().addClass("clearedScreen");
    $("#divOutput").css("min-height", 0);
    createNewDiv("left");
    beginningOfCurrentTurnScrollPosition = 0;
    setTimeout(function () {
        $("html,body").scrollTop(0);
    }, 100);
}

wow, your testgame crashes my firefox :-)


Ruh-roh!

The first browser I tested on was the most recent firefox with ads and popups blocked...

What did I do, Pertex? Might it be all the JS.alerts?


EDIT:

I had a few lines of code that added to and read from Storage when the game loaded. I've removed that now, and I moved the transcript function from the JS file into a JS.eval in the game.

Let me know if it still causes problems, please.


It does not print in IE, works with Chrome andFirefox 56 32-bit, but crashes Firefox 57 64bit


Strange...

I'm running Firefox 57 64-bit, and it works on my machine.

Does it crash whether you enter PRINT or TRANSCRIPT?

Well, I guess I wouldn't be testing things that might crash my browser if I were you...

Hrmm...

I wonder if there's a way to check if the function is supported before running it.


crashes in all combinations: pressing Print_Transcript, typing print or transcript

edit: OK , seems to be a right problem. When starting firefox as an admin, I can print the transcript. Strange, no such problems with the previous version of firefox


Thanks for checking it out, Pertex.

It sucks that it crashes the browser.

Maybe I'll add a warning via Ask when you try to print anything:

"WARNING! THIS MAY CAUSE YOUR BROWSER TO CRASH! IF YOU'RE BRAVE ENOUGH TO CONTINUE, YOU MAY WANT TO SAVE EVERYTHING YOU'RE WORKING ON FIRST! WOULD YOU STILL LIKE TO PRINT?"


@ Pertex,

Can you print anything from Firefox when not running as an admin?


witch firefox 56 I can print the transcript, with ff 57 not at all


What about just printing a normal page when not running as admin? Have you tried printing anything besides this from Firefox?

(I'm just curious. I believe you, don't doubt that. It's just that I've tested this on three machines, and I can't get Firefox to crash. ...but there is only one user setup on each machine.)


@KV: I've seen other people with this issue.

There is an open issue on the firefox bugtracker; "Print preview crashes firefox when not running as administrator"

(and half a dozen similarly named issues, which I suspect will be merged real soon now. And hopefully fixed shortly after given the number of people going "Oh, I'll switch to Chrome" on those threads)


Whew!

It's print preview then, not the code. (Whoo-hoo!)


I notice Firefox doesn't open print preview at all. It just opens the print prompt. Chrome does load the print preview, though. Even on my Android.


Thanks, mrangel!

I was starting to get a little discouraged. So many things don't work online that do work offline, and vice-versa. Then, all the different browsers act differently.

I won't even mention all the different display settings...


Log in to post a reply.

Support

Forums