# 一些有用的js代码

## 读取远程文件内容并渲染markdown格式

参考:[Awesome系列](https://rizon.top/share/awesome-series/)

```javascript
<!--markdown渲染工具-->
<script src="//cdn.bootcss.com/markdown.js/0.5.0/markdown.min.js"></script>

<div id="appAwesome">
    appAwesome 加载中(https://raw.githubusercontent.com/othorizon/MacAwesome/master/app.md)
</div>

<script type="text/javascript">
    let xmlHttpRequest;
    function createXmlHttpRequest() {
        if (window.ActiveXObject) { //如果是IE浏览器      
            return new ActiveXObject("Microsoft.XMLHTTP");
        } else if (window.XMLHttpRequest) { //非IE浏览器      
            return new XMLHttpRequest();
        }
    }
    function loadData(url,callback) {
        xmlHttpRequest = createXmlHttpRequest();
        xmlHttpRequest.onreadystatechange = callback;
        xmlHttpRequest.open("GET", url, true);
        xmlHttpRequest.send(null);
    }

    function loadComplete(elementId) {
        if (xmlHttpRequest.readyState == 4) {// 4 = "loaded"
            if (xmlHttpRequest.status == 200) {// 200 = OK
                document.getElementById(elementId).innerHTML = markdown.toHTML(xmlHttpRequest.responseText);
            }
            else {
                document.getElementById(elementId).innerHTML += "<BR> #加载失败";
            }
        }
    }

    let appAwesomeUrl="https://raw.githubusercontent.com/othorizon/MacAwesome/master/app.md";
    // load app awesome
    loadData(appAwesomeUrl,function(){
        loadComplete("appAwesome")
    });
</script>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.rizon.top/qian-duan/js-dai-ma-kuai.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
