User:TedSwippet/Interactive calculator

 var bh_calculator_base = "Ly8gU3RhcnQgQmFzZTY0IGVuY29kaW5nIGhlcmUuCmlmICghKCJiaF8iIGluIHdpbmRvdykpCiAgd2luZG93LmJoXyA9IHt9OwoKYmhfLmNhbGN1bGF0b3IgPSB7CiAgbmFtZTogImJoXy5jYWxjdWxhdG9yIiwKCiAgaW5pdGlhbGl6ZTogZnVuY3Rpb24oaGFuZGxlciwgc2NoZW1hLCBwcmVmaXgpIHsKICAgIHZhciBzdHlsZXMgPSB7CiAgICAgIHRhYmxlOiAiYm9yZGVyLXN0eWxlOiBzb2xpZDsgYm9yZGVyLXdpZHRoOiAxcHg7IGJhY2tncm91bmQtY29sb3I6ICNmOGY5ZmEiLAogICAgICBjZWxsOiAicGFkZGluZzogMnB4IiwKICAgICAgZmllbGQ6ICJib3JkZXItc3R5bGU6IHNvbGlkOyBib3JkZXItd2lkdGg6IDFweDsgYmFja2dyb3VuZC1jb2xvcjogI2ZmZmZmZiIsCiAgICAgIGJ1dHRvbjogImJvcmRlci1zdHlsZTogc29saWQ7IGJvcmRlci13aWR0aDogMXB4OyBiYWNrZ3JvdW5kLWNvbG9yOiAjZGNkY2RjOyBwYWRkaW5nOiA0cHg7IGN1cnNvcjogcG9pbnRlciIKICAgIH07CiAgICB2YXIgaW52b2tlID0gaGFuZGxlci5uYW1lICsgIi5jYWxjdWxhdGUoXCIiICsgcHJlZml4ICsgIlwiKSI7CiAgICB2YXIgZmllbGRzID0gc2NoZW1hLmZpZWxkczsKCiAgICB2YXIgdGFibGUgPQogICAgICAgICAgIjx0YWJsZSBpZD0nIiArIHByZWZpeCArICJ0YWJsZScgc3R5bGU9JyIgKyBzdHlsZXMudGFibGUgKyAiJz48dGJvZHk+IgogICAgICAgICsgIjx0cj4iOwogICAgdmFyIHJlc3VsdDsKICAgIGZpZWxkcy5mb3JFYWNoKGZ1bmN0aW9uKGZpZWxkKSB7CiAgICAgIGlmICgiaW5pdCIgaW4gZmllbGQpIHsKICAgICAgICB2YXIgaW5pdCA9IGZpZWxkLmZvcm1hdC5yZXBsYWNlKCJ7fSIsIGZpZWxkLmluaXQpOwogICAgICAgIHRhYmxlICs9CiAgICAgICAgICAgICAgIjx0ZCBzdHlsZT0nIiArIHN0eWxlcy5jZWxsICsgIic+IgogICAgICAgICAgICArICI8bGFiZWwgZm9yPSciICsgcHJlZml4ICsgZmllbGQuaWQgKyAiJz4iICsgZmllbGQubGFiZWwgKyAiIDwvbGFiZWw+IgogICAgICAgICAgICArICI8aW5wdXQgdHlwZT0ndGV4dCcgc3R5bGU9JyIgKyBzdHlsZXMuZmllbGQgKyAiJyBzaXplPSc2JyBpZD0nIiArIHByZWZpeCArIGZpZWxkLmlkICsgIiciCiAgICAgICAgICAgICsgIiB2YWx1ZT0nIiArIGluaXQgKyAiJyBvbmNoYW5nZT0nIiArIGludm9rZSArICInPiIKICAgICAgICAgICAgKyAiPC90ZD4iOwogICAgICB9IGVsc2UgewogICAgICAgIHJlc3VsdCA9IGZpZWxkOwogICAgICB9CiAgICB9KTsKICAgIHRhYmxlICs9CiAgICAgICAgICAiPC90cj48dHI+IgogICAgICAgICsgIjx0ZCBzdHlsZT0nIiArIHN0eWxlcy5jZWxsICsgIic+IgogICAgICAgICsgIjxidXR0b24gdHlwZT0nYnV0dG9uJyBzdHlsZT0nIiArIHN0eWxlcy5idXR0b24gKyAiJyBpZD0nIiArIHByZWZpeCArICIjYnV0dG9uJyIKICAgICAgICArICIgb25jbGljaz0nIiArIGludm9rZSArICInPkNhbGN1bGF0ZTwvYnV0dG9uPjwvdGQ+IgogICAgICAgICsgIjx0ZCBzdHlsZT0nIiArIHN0eWxlcy5jZWxsICsgIic+IgogICAgICAgICsgIjxsYWJlbCBmb3I9JyIgKyBwcmVmaXggKyByZXN1bHQuaWQgKyAiJz4iICsgcmVzdWx0LmxhYmVsICsgIiA8L2xhYmVsPiIKICAgICAgICArICI8aW5wdXQgdHlwZT0ndGV4dCcgc3R5bGU9JyIgKyBzdHlsZX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