"use strict";
function BugReporter() {
    var highLightLevel = ["h1", "h2", "h3"];
    var sections = document.querySelectorAll(".sect2");
    var tocAList = document.querySelectorAll("#toc a");
    this.highlighterUtil = new TOCHighlighter(sections, tocAList, highLightLevel);
    this.github_issue_point = "https://github.com/azu/promises-book/issues/new";
    this.github_issue_title = "";
    this.github_issue_body = "";
    this.github_issue_labels = "フィードバック";
}
BugReporter.prototype.getSelectedText = function () {
    var sel, text = "";
    if (window.getSelection) {
        text = "" + window.getSelection();
    } else if ((sel = document.selection) && sel.type == "Text") {
        text = sel.createRange().text;
    }
    return text;
};
BugReporter.prototype.getURLs = function () {
    return this.highlighterUtil.currentTOCElements().map(function (tocElement) {
        return location.protocol + "//" + location.host + location.pathname + tocElement.hash;
    });
};
BugReporter.prototype.setTitle = function (title) {
    this.github_issue_title = title;
};
BugReporter.prototype.setBody = function (body) {
    this.github_issue_body = body;
};
BugReporter.prototype.report = function () {
    var url = this.github_issue_point + "?title=" + encodeURIComponent(this.github_issue_title)
        + "&body=" + encodeURIComponent(this.github_issue_body)
        + "&labels=" + encodeURIComponent(this.github_issue_labels);
    window.open(url, "_blank");
};
window.addEventListener("load", function (event) {

    function quoteText(text){
        return text.split("\n").map(function(line){
            return "> " + line;
        }).join("\n");
    }
    var reportElement = document.createElement("button");
    reportElement.textContent = "バグ報告";
    reportElement.setAttribute("style", "position:fixed; right:0;bottom:0;");
    reportElement.addEventListener("click", function (event) {
        var bug = new BugReporter();
        var selectedText = bug.getSelectedText().trim();
        console.log(selectedText);
        var body = 'URL : ' + bug.getURLs() + "\n";
        if (selectedText && selectedText.length > 0) {
            body += "\n" + quoteText(selectedText) + "\n";
        }
        bug.setBody(body);
        bug.report();
    });
    document.body.appendChild(reportElement);
});


@@ -1550,16 +1550,17 @@
 xt(text)
+ 
 %7B%0A      
@@ -1601,14 +1601,16 @@
 tion
+ 
 (line)
+ 
 %7B%0A  
@@ -1664,24 +1664,25 @@
 %5Cn%22);%0A    %7D%0A
+%0A
     var repo
@@ -1841,24 +1841,96 @@
 ottom:0;%22);%0A
+    var clickEvent = (%22ontouchstart%22 in window) ? %22touchend%22 : %22click%22;%0A
     reportEl
@@ -1952,23 +1952,26 @@
 istener(
-%22
 click
-%22
+Event
 , functi
@@ -2081,43 +2081,8 @@
 ();%0A
-        console.log(selectedText);%0A
     

support iOS