Three solutions for slow opening of android help documents

  • 2020-05-09 19:20:25
  • OfStack

It was found that the web page in the local document has the following js code that will load the information in the network. Just comment it out


<script src="http://www.google.com/jsapi" type="text/javascript"></script>

Batch comments can be made with 1 click of java code


package cn.sd.fxd.android;
/*
 *  To get rid of Android The document needs to be networked javascript code 
 */
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class FormatDoc {
    public static int j=1;
    /**
     * @param args
     */
    public static void main(String[] args) {

        File file = new File("D:/android/android-sdk-windows/docs/");
        searchDirectory(file, 0);
        System.out.println("OVER");
    }
    public static void searchDirectory(File f, int depth) {
        if (!f.isDirectory()) {
            String fileName = f.getName();
            if (fileName.matches(".*?.html")) {
                String src = "<script src=\"http://www.google.com/jsapi\" type=\"text/javascript\"></script>";
                String dst = "<!-- <script src=\"http://www.google.com/jsapi\" type=\"text/javascript\"></script> -->";
                // If it is html The file comments out the specific javascript code 
                annotation(f, src, dst);
            }
        } else {
            File[] fs = f.listFiles();
            depth++;
            for (int i = 0; i < fs.length; ++i) {
                File file = fs[i];
                searchDirectory(file, depth);
            }
        }
    }
    /*
     * f  The file in which you are going to modify specific content  
     * src  The content to be replaced  
     * dst  The content of the layer will be replaced 
     */
    public static void annotation(File f, String src, String dst) {
        String content = FormatDoc.read(f);
        content = content.replaceAll(src, dst);
        FormatDoc.write(content, f);
        System.out.println(j++);
        return;
    }
    public static String read(File src) {
        StringBuffer res = new StringBuffer();
        String line = null;
        try {
            BufferedReader reader = new BufferedReader(new FileReader(src));
            int i=0;
            while ((line = reader.readLine()) != null) {
                if (i!=0) {
                    res.append('\n');
                }
                res.append(line);
                i++;
            }
            reader.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return res.toString();
    }
    public static boolean write(String cont, File dist) {
        try {
            BufferedWriter writer = new BufferedWriter(new FileWriter(dist));
            writer.write(cont);
            writer.flush();
            writer.close();
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }
}

One way to do this on the web is to delete that line of js code via shell, which is very simple and convenient, 100 times more convenient than the java I wrote, I HATE JAVA


find . -name "*.html"|xargs grep -l "jsapi"|xargs sed -i '/jsapi/d'

Another option is to disconnect from the Internet, or use IE or firefox to browse offline


Related articles: