// Path: app/src/main/java/org/houxg/leamonax/utils/StringUtils.java
// public class StringUtils {
//     public static String notNullStr(String str) {
//         return str == null ? "" : str;
//     }
// 
//     public static void find(String content, String tagExp, String targetExp, Finder finder, Object... extraData) {
//         Pattern tagPattern = Pattern.compile(tagExp);
//         Pattern targetPattern = Pattern.compile(targetExp);
//         Matcher tagMather = tagPattern.matcher(content);
//         while (tagMather.find()) {
//             String tag = tagMather.group();
//             Matcher targetMatcher = targetPattern.matcher(tag);
//             if (!targetMatcher.find()) {
//                 continue;
//             }
//             String original = targetMatcher.group();
//             finder.onFound(original);
//         }
//     }
// 
//     public static String replace(String content, String tagExp, String targetExp, Replacer replacer, Object... extraData) {
//         Pattern tagPattern = Pattern.compile(tagExp);
//         Pattern targetPattern = Pattern.compile(targetExp);
//         Matcher tagMather = tagPattern.matcher(content);
//         StringBuilder contentBuilder = new StringBuilder(content);
//         int offset = 0;
//         while (tagMather.find()) {
//             String tag = tagMather.group();
//             Matcher targetMatcher = targetPattern.matcher(tag);
//             if (!targetMatcher.find()) {
//                 continue;
//             }
//             String original = targetMatcher.group();
//             int originalLen = original.length();
//             String modified = replacer.replaceWith(original, extraData);
//             contentBuilder.replace(tagMather.start() + targetMatcher.start() + offset,
//                     tagMather.end() - (tag.length() - targetMatcher.end()) + offset,
//                     modified);
//             offset += modified.length() - originalLen;
//         }
//         return contentBuilder.toString();
//     }
// 
//     public interface Finder {
//         void onFound(String original, Object... extraData);
//     }
// 
//     public interface Replacer {
//         String replaceWith(String original, Object... extraData);
//     }
// }


import android.os.Looper;
import android.webkit.ValueCallback;
import android.webkit.WebView;
import com.elvishew.xlog.XLog;
import org.houxg.leamonax.utils.StringUtils;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
package org.houxg.leamonax.editor;






public class JsRunner implements ValueCallback<String> {
    private static final String TAG = "JsRunner:";
    private String mResult;
    private CountDownLatch mLatch;

    public String get(final WebView webView, final String script) {
        if (Looper.myLooper() == Looper.getMainLooper()) {
            XLog.w(TAG + "Call from main thread");
        }
        mLatch = new CountDownLatch(1);
        webView.post(new Runnable() {
            @Override
            public void run() {
                webView.evaluateJavascript(script, JsRunner.this);
            }
        });
        try {
            mLatch.await(1, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            mResult = null;
        }
// Path: app/src/main/java/org/houxg/leamonax/utils/StringUtils.java
// public class StringUtils {
//     public static String notNullStr(String str) {
//         return str == null ? "" : str;
//     }
// 
//     public static void find(String content, String tagExp, String targetExp, Finder finder, Object... extraData) {
//         Pattern tagPattern = Pattern.compile(tagExp);
//         Pattern targetPattern = Pattern.compile(targetExp);
//         Matcher tagMather = tagPattern.matcher(content);
//         while (tagMather.find()) {
//             String tag = tagMather.group();
//             Matcher targetMatcher = targetPattern.matcher(tag);
//             if (!targetMatcher.find()) {
//                 continue;
//             }
//             String original = targetMatcher.group();
//             finder.onFound(original);
//         }
//     }
// 
//     public static String replace(String content, String tagExp, String targetExp, Replacer replacer, Object... extraData) {
//         Pattern tagPattern = Pattern.compile(tagExp);
//         Pattern targetPattern = Pattern.compile(targetExp);
//         Matcher tagMather = tagPattern.matcher(content);
//         StringBuilder contentBuilder = new StringBuilder(content);
//         int offset = 0;
//         while (tagMather.find()) {
//             String tag = tagMather.group();
//             Matcher targetMatcher = targetPattern.matcher(tag);
//             if (!targetMatcher.find()) {
//                 continue;
//             }
//             String original = targetMatcher.group();
//             int originalLen = original.length();
//             String modified = replacer.replaceWith(original, extraData);
//             contentBuilder.replace(tagMather.start() + targetMatcher.start() + offset,
//                     tagMather.end() - (tag.length() - targetMatcher.end()) + offset,
//                     modified);
//             offset += modified.length() - originalLen;
//         }
//         return contentBuilder.toString();
//     }
// 
//     public interface Finder {
//         void onFound(String original, Object... extraData);
//     }
// 
//     public interface Replacer {
//         String replaceWith(String original, Object... extraData);
//     }
// }


// Path: app/src/main/java/org/houxg/leamonax/editor/JsRunner.java
import android.os.Looper;
import android.webkit.ValueCallback;
import android.webkit.WebView;
import com.elvishew.xlog.XLog;
import org.houxg.leamonax.utils.StringUtils;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

package org.houxg.leamonax.editor;






public class JsRunner implements ValueCallback<String> {
    private static final String TAG = "JsRunner:";
    private String mResult;
    private CountDownLatch mLatch;

    public String get(final WebView webView, final String script) {
        if (Looper.myLooper() == Looper.getMainLooper()) {
            XLog.w(TAG + "Call from main thread");
        }
        mLatch = new CountDownLatch(1);
        webView.post(new Runnable() {
            @Override
            public void run() {
                webView.evaluateJavascript(script, JsRunner.this);
            }
        });
        try {
            mLatch.await(1, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            mResult = null;
        }
        return StringUtils.notNullStr(mResult);