import java.util.*;
import java.util.zip.*;
import java.util.List;
import java.util.regex.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.concurrent.locks.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.table.*;
import java.io.*;
import java.net.*;
import java.lang.reflect.*;
import java.lang.ref.*;
import java.lang.management.*;
import java.security.*;
import java.security.spec.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.*;
import java.math.*;
class main {
static void test_autoLoadJQuery() {
String html = hjs("$('bla').bla();");
assertFalse(jqueryLoaded(html));
assertTrue(html, neq(autoLoadJQuery(html), html));
html = hjs("document.bla();");
assertEqualsVerbose(html, autoLoadJQuery(html));
html = hbutton("bla", "onclick" , "$(this).hide();");
assertTrue(html, neq(autoLoadJQuery(html), html));
}
static String hjs(String script) {
return hjavascript(script);
}
static void assertFalse(Object o) {
if (!(eq(o, false) /*|| isFalse(pcallF(o))*/))
throw fail(str(o));
}
static boolean assertFalse(boolean b) {
if (b) throw fail("oops");
return b;
}
static boolean assertFalse(String msg, boolean b) {
if (b) throw fail(msg);
return b;
}
static boolean jqueryLoaded(String html) {
for (String tag : findAllTagsNamed("script",html))
if (cic(tagParam(tag, "src"), "/jquery"))
return true;
return false;
}
static void assertTrue(Object o) {
if (!(eq(o, true) /*|| isTrue(pcallF(o))*/))
throw fail(str(o));
}
static boolean assertTrue(String msg, boolean b) {
if (!b)
throw fail(msg);
return b;
}
static boolean assertTrue(boolean b) {
if (!b)
throw fail("oops");
return b;
}
static boolean neq(Object a, Object b) {
return !eq(a, b);
}
static String autoLoadJQuery(String html) {
if (jqueryUsed(html) && !jqueryLoaded(html))
return loadJQuery2() + html;
return html;
}
static A assertEqualsVerbose(Object x, A y) {
assertEqualsVerbose((String) null, x, y);
return y;
}
// x = expected, y = actual
static A assertEqualsVerbose(String msg, Object x, A y) {
if (!eq(x, y)) {
throw fail((msg != null ? msg + ": " : "") + "expected: "+ x + ", got: " + y);
} else
print("OK" + (empty(msg) ? "" : " " + msg) + ": " + /*sfu*/(x));
return y;
}
static String hbutton(String text, Object... params) {
return hfulltag("button", text, params);
}
static String hjavascript(String script) {
return tag("script", script, "type", "text/javascript");
}
static boolean eq(Object a, Object b) {
return a == b || a != null && b != null && a.equals(b);
}
static RuntimeException fail() { throw new RuntimeException("fail"); }
static RuntimeException fail(Throwable e) { throw asRuntimeException(e); }
static RuntimeException fail(Object msg) { throw new RuntimeException(String.valueOf(msg)); }
static RuntimeException fail(String msg) { throw new RuntimeException(msg == null ? "" : msg); }
static RuntimeException fail(String msg, Throwable innerException) { throw new RuntimeException(msg, innerException); }
static String str(Object o) {
return o == null ? "null" : o.toString();
}
static String str(char[] c) {
return new String(c);
}
// tok = parsed with htmlTok
static List findAllTagsNamed(List tok, String tag) {
List out = new ArrayList();
for (int i = 1; i < l(tok); i += 2)
if (isTag(tok.get(i), tag))
out.add(tok.get(i));
return out;
}
static List findAllTagsNamed(String tag, List tok) {
return findAllTagsNamed(tok, tag);
}
// Note the reversed parameters
static List findAllTagsNamed(String tag, String html) {
return findAllTagsNamed(htmlTok(html), tag);
}
static boolean cic(Collection l, String s) {
return containsIgnoreCase(l, s);
}
static boolean cic(String[] l, String s) {
return containsIgnoreCase(l, s);
}
static boolean cic(String s, char c) {
return containsIgnoreCase(s, c);
}
static boolean cic(String a, String b) {
return containsIgnoreCase(a, b);
}
static String tagParam(String tag, String key) {
return getHtmlTagParameter(tag, key);
}
// param of opening tag
static String tagParam(List tok, String key) {
return getHtmlTagParameter(second(tok), key);
}
// assumes jquery is used with $(...)
static boolean jqueryUsed(String html) {
if (!regexpFind("\\$\\s*\\(", html)) return false;
for (String script : allJavascriptFromHTML(html))
if (jcontains(jsTok(script), "$(")) return true;
for (String tag : codeTokens(htmlTok(html)))
for (Map.Entry extends String, ? extends String> __0 : _entrySet( tagParams(tag)))
{ String key = __0.getKey(); String value = __0.getValue(); if (swic(key, "on") && contains(value, "$(")) return true; }
return false;
}
static String loadJQuery2() {
return "";
}
static volatile StringBuffer local_log = new StringBuffer(); // not redirected
static volatile Appendable print_log = local_log; // might be redirected, e.g. to main bot
// in bytes - will cut to half that
static volatile int print_log_max = 1024*1024;
static volatile int local_log_max = 100*1024;
static boolean print_silent = false; // total mute if set
static Object print_byThread_lock = new Object();
static volatile ThreadLocal