text: var monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]; var dayNames= ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];var newDate = new Date();newDate.setDate(newDate.getDate());$('#Date').html(dayNames[newDate.getDay()] + " " + newDate.getDate() + ' ' + monthNames[newDate.getMonth()] + ' ' + newDate.getFullYear());setInterval( function() {var seconds = new Date().getSeconds();$("#sec").html(( seconds < 10 ? "0" : "" ) + seconds);},1000);setInterval( function() {var minutes = new Date().getMinutes();$("#min").html(( minutes < 10 ? "0" : "" ) + minutes);},1000);setInterval( function() {var hours = new Date().getHours();$("#hours").html(( hours < 10 ? "0" : "" ) + hours);}, 1000); var initStatus;var crawlTotalCount = 0;var crawlCompleteCount = 0;var crawlFailCount = 0;function getUrl(url,callback){$.ajax({type: "GET",url: url,timeout: 60000,success:function(data) {callback(data);crawlCompleteCount++;setTimeout(function(){var percent =(100* (Number(crawlCompleteCount/crawlTotalCount))).toFixed(0) ;$('.progress-bar-success').html("Crawling ["+crawlCompleteCount+" / "+crawlTotalCount+"]").css('width',percent+'%');},500);crawlStatus();},error:function(error){crawlFailCount++;setTimeout(function(){var percent =(100* (Number(crawlFailCount/crawlTotalCount))).toFixed(0) ;$('.progress-bar-danger').html("Crawling  ["+crawlFailCount+" / "+crawlTotalCount+"]").css('width',percent+'%');},500);crawlStatus();}});}var crawlStatus = function(){  var sum = crawlCompleteCount+crawlFailCount;if(crawlTotalCount == sum){$('#crawl_success').html(" "+crawlCompleteCount);$('#crawl_fail').html(" "+crawlFailCount);initStatus = false;$('.btn-info').show();}};function parsing(data){var RegExpTag = "<[^<|>]*>";  data = data.replace("<br>","");data = data.replace(RegExpTag,""); data = data.replace(/(<([^>]+)>)/ig,"");RegExpJS = "/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi";data = data.replace(RegExpJS,""); RegExpCSS = "/<style\b[^<]*(?:(?!<\/style>)<[^<]*)*<\/style>/gi";RegExpCSS = "s!<(s(?:cript|tyle))[^>]*>.*?</\1>!!gis";data = data.replace(RegExpCSS,""); RegExpDS = /<!--[^>](.*?)-->/g;   data = data.replace(RegExpDS,""); data = data.replace("&laquo;","");data = data.replace("&raquo;","");data = data.replace("&nbsp;","");data = data.replace("/[\r|\n|\t]/g", ""); return data;}function getDate(in_date){var date = new Date(in_date);var yyyy = date.getFullYear().toString();var mm = (date.getMonth()+1).toString();var dd  = date.getDate().toString();var hh = date.getHours().toString();var MM = date.getMinutes().toString();var ss = date.getSeconds().toString();var mmChars = mm.split('');var ddChars = dd.split('');var hhChars = hh.split('');var MMChars = MM.split('');var ssChars = ss.split('');var datestring = yyyy + '-' + (mmChars[1]?mm:"0"+mmChars[0]) + '-' + (ddChars[1]?dd:"0"+ddChars[0]) + ' ' + (hhChars[1]?hh:"0"+hhChars[0]) + ':' + (MMChars[1]?MM:"0"+MMChars[0]) + ':' + (ssChars[1]?ss:"0"+ssChars[0]);return datestring;}Map = function(){this.map = new Object();};   Map.prototype = {   put : function(key, value){   this.map[key] = value;},   get : function(key){   return this.map[key];},containsKey : function(key){    return key in this.map;},containsValue : function(value){    for(var prop in this.map){if(this.map[prop] == value) return true;}return false;},isEmpty : function(key){    return (this.size() == 0);},clear : function(){   for(var prop in this.map){delete this.map[prop];}},remove : function(key){    delete this.map[key];},keys : function(){   var keys = new Array();   for(var prop in this.map){   keys.push(prop);}   return keys;},values : function(){   var values = new Array();   for(var prop in this.map){   values.push(this.map[prop]);}   return values;},size : function(){var count = 0;for (var prop in this.map) {count++;}return count;}};var createStatement = "CREATE TABLE IF NOT EXISTS bookmark (id TEXT PRIMARY KEY, parentId TEXT, title TEXT, url TEXT, idx INTEGER, flag TEXT , date TEXT, level INTEGER, domain TEXT, text TEXT, crawlYN TEXT, childrenSize INTEGER)";var createEnvStatement = "CREATE TABLE IF NOT EXISTS environment (initFlag TEXT, updatedDate TEXT, imageFilePath TEXT, selectBackground TEXT, clockChecked INTEGER , googleSearchChecked INTEGER)";var dropStatement = "DROP TABLE bookmark";var dropEnvStatement = "DROP TABLE environment";var selectEnvStatement = "SELECT * FROM environment";var selectAllStatement = "SELECT  id,  parent,   CASE WHEN(flag=='folder') THEN text||' [<font color=red><b>'||childrenSize||'</b></font>]' ELSE text END AS text,   icon,   data,   flag  FROM ( SELECT id,  CASE WHEN(parentId=='0') THEN '#' ELSE parentId END as parent,   CASE WHEN(crawlYN is null  AND flag=='file')  THEN '<font color=red><del>' ||title||'</del> <font color=blue>[disconnect]</font> </font>' ELSE title END as text,   CASE WHEN(flag == 'file') THEN 'chrome://favicon/'||url ELSE '' END as icon,    id || ' ' || flag||' '||url||' '|| CASE WHEN (crawlYN is null) THEN 'n' ELSE 'y' END as data,    childrenSize ,   flag FROM bookmark) A ";var selectAllforFileStatement = "SELECT id, url as data FROM bookmark WHERE flag == 'file'";var updateTextStatement = "UPDATE bookmark SET text = ? , crawlYN = ? WHERE id = ?";var selectHostGroup = "SELECT  domain as id ,   '#' AS parent ,   domain || ' [<font color=red><b>'||COUNT(domain) ||'</b></font>]' AS text,   'chrome://favicon/'||url AS icon,   id || ' ' || 'folder ' || url||' '|| CASE WHEN (crawlYN is null) THEN 'n' ELSE 'y' END as data FROM bookmark WHERE domain != '' GROUP BY domain UNION ALL SELECT   id,    domain AS parent,    CASE WHEN(crawlYN is null  AND flag=='file')  THEN '<font color=red><del>' ||title||'</del> <font color=blue>[disconnect]</font> </font>' ELSE title END as text,    CASE WHEN(flag == 'file') THEN 'chrome://favicon/'||url ELSE '' END as icon,   id ||' '|| flag || ' ' || url||' '|| CASE WHEN (crawlYN is null) THEN 'n' ELSE 'y' END as data FROM bookmark WHERE flag ='file' AND domain != ''";var insertStatement = "INSERT INTO bookmark(id,parentId,title,url,idx,flag,date,level,domain,childrenSize) VALUES (?,?,?,?,?,?,?,?,?,?)";var insertInitStatement = "INSERT INTO environment(initFlag, updatedDate, selectBackground) values (?,?,?)";var db = openDatabase("BMM", "1.0", "Bookmark Manager", 200000);   var updateImageFilePath = "UPDATE environment SET imageFilePath = ?";var dataset;var backup = [];var moveElementStatement = "UPDATE bookmark SET parentId = ? WHERE id = ?";function dbConnect(){if(!!window.openDatabase) {dbInit(dropTable);}else{bootbox.alert("Your browser does not support the current expansion program.", function() {});}}function dbInit(callback_drop){callback_drop(createTable);}function dropTable(callback_createTable){db.transaction(function (tx){tx.executeSql(dropStatement,[]);});db.transaction(function (tx){tx.executeSql(dropEnvStatement,[]);});callback_createTable(initData);}function initData(){var initFlag = "N", updatedDate ="", selectBackground="bookmark";db.transaction(function(tx){tx.executeSql(insertInitStatement,[initFlag , updatedDate,selectBackground]);});}function createTable(callback_init){db.transaction(function(tx){tx.executeSql(createStatement,[]);});db.transaction(function(tx){tx.executeSql(createEnvStatement,[]);});callback_init();}function updateImageFile(imageFilePath){db.transaction(function(tx){tx.executeSql(updateImageFilePath,[imageFilePath]);});}function updateText(id, crawlYN, text, callback){var obj = [];obj[0] = text;obj[1] = crawlYN;obj[2] = id;callback(obj);}function insertData(data,callback){if(data == null){return false;}var id,parentId,title,url,idx,flag,date,level,domain,siteText,childrenSize=0;var a;id = data.id;parentId = data.parentId;title = data.title;url = data.url;idx = data.index;a = document.createElement('a');a.href = url;domain = a.host;if(data.children){flag = "folder";childrenSize = data.children.length;}else{flag="file";}date = getDate(data.dateAdded);level = map.get(id);var object=[];object[0]=id;object[1]=parentId;object[2]=title;object[3]=url;object[4]=idx;object[5]=flag;object[6]=date;object[7]=level;object[8]=domain;object[9]=childrenSize;callback(object);}function selectRow(query, callBack){ var data = [];db.transaction(function (tx) {tx.executeSql(query, [], function(tx, rs){for(var i=0; i<rs.rows.length; i++) {var row = rs.rows.item(i);data[i] = row;}callBack(data); }, onError);});} function onError(tx, error) {   if(error.code == 5){dbConnect();buttonEventInit(setEnvironment);}}var bookmarkSearchStatement = "SELECT id, parentId, CASE WHEN(crawlYN is null  AND flag=='file')  THEN '<font color=red><del>' ||title||'</del> <font color=blue>[disconnect]</font> </font>' ELSE title END as title, url, idx, flag, date, domain, text, childrenSize FROM bookmark ";function bookmarkSearch(query, parameter, callBack){var condition ="WHERE ";var conTitle = "( ";var conText = "( ";var param = parameter.split(" ");var paramSize = param.length;var bufferTitle = [];var bufferText = [];for(var i=0; i< paramSize ; i++){conTitle +=  "title LIKE '%"+param[i]+"%' ";conText += "text LIKE '%"+param[i]+"%' ";if(i < (paramSize-1)){conTitle += " AND ";conText += " AND ";}}condition += conTitle+") OR "+conText+") ORDER BY flag desc ";query += condition;var data = [];db.transaction(function (tx) {tx.executeSql(query, [], function(tx, rs){for(var i=0; i<rs.rows.length; i++) {var row = rs.rows.item(i);data[i] = row;}callBack(data); }, null);});} var updateBackgroundFlagStatement =  "UPDATE environment SET selectBackground = ?";function updateBackgroundFlag(backgroundFlag){db.transaction(function(tx){tx.executeSql(updateBackgroundFlagStatement,[backgroundFlag]);});}function moveElement(parentId,id){db.transaction(function(tx){tx.executeSql(moveElementStatement,[parentId,id]);});}var deleteItemStatement="DELETE FROM bookmark WHERE id=? OR parentId=?";function deleteItem(currentId){db.transaction(function(tx){tx.executeSql(deleteItemStatement,[currentId,currentId]);});}var updateItemStatement="UPDATE bookmark SET title=? , url=? WHERE id=?";function updateItem(title, url, id){db.transaction(function(tx){tx.executeSql(updateItemStatement,[title,url,id]);});}function createItem(currentId){}var updateInitFlagStatement = "UPDATE environment SET initFlag =?";function updateInitFlag(){var flag = "Y";db.transaction(function(tx){tx.executeSql(updateInitFlagStatement,[flag]);});}var clockCheckUpdateStatement = "UPDATE environment SET clockChecked = ?";function clockCheckUpdate(flag){db.transaction(function(tx){tx.executeSql(clockCheckUpdateStatement,[flag]);});}var googleSearchCheckUpdateStatement = "UPDATE environment SET googleSearchChecked = ?";function googleSearchCheckUpdate(flag){db.transaction(function(tx){tx.executeSql(googleSearchCheckUpdateStatement,[flag]);});}var message =["<div class='progress'>","<div class='progress-bar progress-bar-info' role='progressbar' style='width:0%'></div></div>","<div class='progress'><div class='progress-bar progress-bar-success' id='progress-complete' style='width: 0%'></div>","<div class='progress-bar progress-bar-danger' id='progress-danger' style='width: 0%'></div></div>","<span class='label label-info'>Sync</span>    <span id='sync_result'> Waiting...</span><br>","<span class='label label-success'>Crawling Success </span>    <span id='crawl_success'> Waiting...</span> <br>","<span class='label label-danger'>Crawling Fail</span>    <span id='crawl_fail'>Waiting...</span><br><br>","<span><font color='red'><b>The crawl items may differ depending on the network status.</b></font></span>"].join('');function menuToggle(menu){if(menu == "menuBookmark"){$('#pictureBackground').hide();$('#bookmarkBackground').show();$('#fileButton').hide();$('body').css('padding-top',70);$("#detailBookmark").show();$("#init").show();$('#googleCheckLabel').hide();$('#clockCheckLabel').hide();}if(menu == "menuPicture"){$('#bookmarkBackground').hide();$('#pictureBackground').show();$('#fileButton').show();$('body').css('padding-top',0);$("#detailBookmark").hide();$("#init").hide();$('#googleCheckLabel').show();$('#clockCheckLabel').show();}}function setBackgroundImage(imagePath){$('#pictureBackground').css("background-image","url("+imagePath+")");}function buttonEventInit(callback_setEnvironment){$('#bookmarkSearch').on('click',function(){ $('#data').click(); executeBookmarkSearch(); $('#searchQuery').focus();});  $('#searchQuery').on('keydown',function(event){if(event.keyCode == 13){executeBookmarkSearch();}});$('#init').on('click',function(){bootbox.dialog({message: message,title: "Synchronization for Bookmarks",closeButton: false,buttons: {done: {label: "Done",className: "btn-info",callback: function() {setEnvironment(getItems);location.reload(); }},success: {label: "Yes",className: "btn-success",callback: function() {if(initStatus){bootbox.alert("The sync is in progress.", function() {});return false;}else{initProcess(); $('.btn-success').hide();$('.btn-danger').hide();}return false;}},danger: {label: "No",className: "btn-danger",callback: function() {if(initStatus){bootbox.alert("During synchronization , you can not stop progress.", function() {});return false;  }else{}}}}});$('.btn-info').hide();});$('#bookmark_back').on('click',function(){menuToggle("menuBookmark");updateBackgroundFlag('bookmark');});$('#picture_back').on('click',function(){menuToggle("menuPicture");updateBackgroundFlag('picture');});$('#files').on('change',function(event){var preview = $('#img');var file    = this.files[0];var reader  = new FileReader();reader.onloadend = function () {updateImageFile(reader.result);setBackgroundImage(reader.result);};if (file) {reader.readAsDataURL(file);} else {preview.src = "";}});$('#fileButton').on('click',function(){$('#files').click();});$('#search').on('click',function(){var query = $('#query').val();executeSearch(query,true);});$('#query').on('keydown',function(event){if(event.keyCode == 13){var query = $('#query').val();executeSearch(query,true);}});$('#googleCheck').on('click',function(){var flag = $(this).is(":checked");if(flag==true){$("#googleSearchArea").show();googleSearchCheckUpdate('y');}else{$("#googleSearchArea").hide();googleSearchCheckUpdate('n');}});$('#clockCheck').on('click',function(){var flag = $(this).is(":checked");if(flag==true){$("#clockArea").show();clockCheckUpdate('y');}else{$("#clockArea").hide();clockCheckUpdate('n');}});callback_setEnvironment(getItems);}var tab_list= document.getElementById('tab_list'),bookmark_list= document.getElementById('bookmarks_list'), history_list= document.getElementById('history_list'),FAVICON="chrome://thumb/";var map = new Map();var resultData = [];$(document).ready(function(){buttonEventInit(setEnvironment);popoverSetting();setInterval(function(){history();},5000);});function popoverSetting(){var panelMessage = ["<ol><li> Open the Setting Flags ( URL : chrome://flags ) </li><br>","<li>Find the '#enable-panels' ( Ctrl + f )</li><br>","<li>'use' and then click Restart </li><br>","</ol><ul><br>","<font color='red'><b>※ If you do not set the Panel runs popup.</b></font>"].join('');$('#usingPanel').on('click',function(){bootbox.dialog({message: panelMessage,title: "How to use the 'Panel'?",buttons: {success: {label: "DONE",className: "btn-success",callback: function() {}}}});});var libMessage = ["<ul><li>jsTree ➡ https://www.jstree.com/</li><br>","<li>Template ➡ http://startbootstrap.com/template-overviews/creative/</li><br>","<li>Clock ➡ http://www.jqueryscript.net/time-clock/Animated-Digital-Clock-Plugin-with-jQuery-CSS3.html</li><br>","</ul>"].join('');$('#usingLib').on('click',function(){bootbox.dialog({message: libMessage,title: "Using Library & Module",buttons: {success: {label: "DONE",className: "btn-success",callback: function() {}}}});});}function getUrlTest(url,callback){$.ajax({type: "GET",url: url,success:function(data) {callback(data);},error:function(error){console.log("error",error);}});}function getTree(){var datas;chrome.bookmarks.getTree(function(roots){$.when(getTreeProcess(roots)).done(function(data){datas = data;});$.when(bookmarkInsertProcess(datas)).done(function(data){});});}var getTreeProcess = function(roots){var level = 0;var bookmarks = [];  roots.forEach( function parser(node){map.put(node.id,level);bookmarks.push(node);   if (node.children) {++level;node.children.forEach(parser);--level;}}); return bookmarks;};var bookmarkInsertProcess = function(datas){initStatus = true;var totalSize = datas.length;var count = 1;datas.forEach(function(data){if(!data.parentId && data.children){for(var idx = 0 ; idx < data.children.length ; idx++ ){insertData(data.children[idx], function(obj){db.transaction(function(tx){tx.executeSql(insertStatement,obj);},null,function(){count++;});});}};if(data.parentId && data.children){for(var idx = 0 ; idx < data.children.length ; idx++ ){insertData(data.children[idx], function(obj){db.transaction(function(tx){tx.executeSql(insertStatement,obj);},null,function(){count++;setTimeout(function(){var percent =(100* (Number(count/totalSize))).toFixed(0) ;$('.progress-bar-info').html("Bookmark Sync ["+count+" / "+totalSize+"]").css('width',percent+'%');},500);if(totalSize == count){$('#sync_result').html(count);$.when(updateUrlText()).done(function(){})};});});}};});return 0;};function updateUrlText(){initStatus = true;selectRow(selectAllforFileStatement , function(items) {crawlTotalCount = items.length;items.forEach( function(node){var url = node.data;var id = node.id;setTimeout(function(){getUrl(url ,function(data){var result = parsing(data);updateText(id,"y",result,function(obj){db.transaction(function(tx){tx.executeSql(updateTextStatement,obj);},null,function(){});});  }); },1000);});  }); }function setEnvironment(callback_getItems){selectRow(selectEnvStatement, function(items) {settingEnv(items, function(history){callback_getItems(history);});});}var initProcess = function(){$('#data').empty();dbConnect();$.when(getTree()).done(function(){updateInitFlag();});};function settingEnv(env, callback){var initFlag = env[0].initFlag,imageFilePath = env[0].imageFilePath,selectBackground = env[0].selectBackground,googleChecked = env[0].googleSearchChecked,clockChecked = env[0].clockChecked;if(initFlag == "N"){bootbox.alert("Those who first use must be synchronized.", function() {bootbox.dialog({message: message,title: "Bookmarks Sync",closeButton: false,buttons: {success: {label: "Done",className: "btn-info",callback: function() {if(initStatus){bootbox.alert("During synchronization , you can not stop progress.", function() {});return false;}else{setEnvironment(getItems);location.reload(); }}}}});initProcess();$('.btn-info').hide();});};if(selectBackground == 'bookmark'){$('#bookmark_back').click();}else{$('#picture_back').click();};if(imageFilePath == null){}else{setBackgroundImage(imageFilePath);};if(googleChecked=="y"){$('input:checkbox[id="googleCheck"]').attr("checked", true);$('#googleSearchArea').show();}else{$('input:checkbox[id="googleCheck"]').attr("checked", false);$('#googleSearchArea').hide();};if(clockChecked=="y"){$('input:checkbox[id="clockCheck"]').attr("checked", true);$('#clockArea').show();}else{$('input:checkbox[id="clockCheck"]').attr("checked", false);$('#clockArea').hide();};callback(history);}function executeSearch(query, selectedFlag){var url = "https://www.google.com/search?q="+query;newTab(url);}function executeBookmarkSearch(){var parameter = $('#searchQuery').val();var googleSearchCheck = $('#includeGoogleSearch').is(":checked");if(googleSearchCheck){executeSearch(parameter, false);};parameter = parameter.replace(/(^\s*)|(\s*$)/gi, "");if(parameter==null || parameter == ''){return false;};var result = $('#result');var preSize = 200;var postSize = 200;var text, title, totalSize;var highlight_color = 'orange';result.empty();bookmarkSearch(bookmarkSearchStatement, parameter, function(items) {if(items.length == 0){result.append("<span> No results were found for your search. </span>");}else{result.append("<span>"+items.length+" item(s) </span><hr>");};var cnt = 1;items.forEach(function(item){title = item.title;if(item.text != null){text = item.text;}else{text = "";};totalSize = text.length;var start, end ;var firstKeyword = parameter.split(" ")[0];var keywordIndex = text.indexOf(firstKeyword);start = keywordIndex - preSize;end = keywordIndex + postSize;text = text.substring(start, end);text = text.replace(firstKeyword, "<span>"+firstKeyword+"</span>");var titleKeywordIndex = title.indexOf(firstKeyword);start = titleKeywordIndex - preSize;end = titleKeywordIndex + postSize;title = title.substring(start, end);title = title.replace(firstKeyword, "<span>"+firstKeyword+"</span>");var faviconUrl = "chrome://favicon/"+item.url; var a = "<a href='#"+item.id+"' id='result_"+item.id+"' >"+cnt+". "+"<font color='blue'>["+item.date+"]</font> <img src='"+faviconUrl+"'> "+ title+"  </a>  <a href='#' id='result_new_"+item.id+"' ><img src='img/new2.png'></a><br> \<span>"+text+"</span>  <hr>";result.append(a);$('#result_new_'+item.id).on('click',function(){newPanel(item.url);});$('#result_'+item.id).on('dblclick',function(){if(item.flag=="file"){newTab(item.url);}else{$("#data").jstree('open_node', "#"+item.id, function(e,d) {for (var i = 0; i < e.parents.length; i++) {$("#data").jstree('open_node', "#"+e.parents[i]);};});$("#data").jstree('select_node', "#"+item.id);};});cnt++;})});};var bookmarkToDatabase = function(datas, callback_updateUrlText){bookmarkInsertProcess(datas,function(){callback_updateUrlText();}) };function getItems(callback_getHistory){selectRow(selectAllStatement, function(items) {createTree(items,'default');});selectRow(selectHostGroup, function(items) {createTree(items,'group');});callback_getHistory();}function history(){var cnt = 1;var opened = false;var panel = 0;chrome.history.search({text: '', maxResults: 50}, function(data) {$('#visit').empty();data.forEach(function(page) {var title = page.title;var domain = "";if(title == ""){a = document.createElement('a');a.href = page.url;domain =  a.host;title = '[notitle] '+domain;            };var a = "<a href='#' id='"+page.id+"' >"+cnt+". "+"<font color='blue'>["+getDate(page.lastVisitTime)+"]</font> <img src='chrome://favicon/"+page.url+"''> "+ title+"  <span class='badge'>"+page.visitCount+"</span></a>  <a href='#' id='new_"+page.id+"' ><img src='img/new2.png'></a><hr>";$('#visit').append(a);$('#'+page.id).on('dblclick',function(){newTab(page.url);});$('#new_'+page.id).on('click',function(){newPanel(page.url);});cnt++;});});}function updateBookmark(flag, item){var message ;var data = item.data.split(" ");var id = data[0];var type = data[1];var url = data[2];var crawlYN = data[3];var text;var parent = item.parent;if(type=="folder"){text = item.text.split("[");text = text[0];url = "This node has no URL.";}else{text = item.text;if(crawlYN == "n"){text = $(text).find('del').html();}}; if(flag =='rename'){if(parent == "#"){bootbox.alert("Top-level node can not be updated.", function() {});return false;};message = ["<div class='input-group'>","<span class='input-group-addon' id='basic-addon1'><span class='glyphicon glyphicon-tag' aria-'hidden=true'></span></span>","<input type='text' id='title' class='form-control' placeholder='TITLE' aria-describedby='basic-addon1' value='"+text+"''>","</div>","<div class='input-group'>","<span class='input-group-addon' id='basic-addon1'><span class='glyphicon glyphicon-globe' aria-hidden='true'></span></span>","<input type='text' id='url' class='form-control' placeholder='URL' aria-describedby='basic-addon1' value='"+url+"' readonly>","</div>"].join('');}else if(flag =="create"){message = ["<div class='input-group'>","<span class='input-group-addon' id='basic-addon1'><span class='glyphicon glyphicon-tag' aria-'hidden=true'></span></span>","<input type='text' id='title' class='form-control' placeholder='TITLE' aria-describedby='basic-addon1'>","</div>","<div class='input-group'>","<span class='input-group-addon' id='basic-addon1'><span class='glyphicon glyphicon-globe' aria-hidden='true'></span></span>","<input type='text' id='url' class='form-control' placeholder='URL' aria-describedby='basic-addon1'>","</div>"].join('');}else if(flag =="delete"){if(parent == "#"){bootbox.alert("Top-level node can not be deleted.", function() {});return false;};message = ["[ <font color=red>"+text+"</font> ]<br> Are you sure you want to delete this node."].join('');};bootbox.dialog({message: message,title: "Update bookmarks",buttons: {success: {label: "Yes",className: "btn-success",callback: function(current) {var title = $('#title').val();var url = $('#url').val();var data = item.data.split(" ");var type = data[1];var id = data[0];var parent;if(flag =='rename'){updateItem(title,url,id);chrome.bookmarks.update(id, {title:title}, function(){})}else if(flag =="allopen"){}else if(flag =="create"){if(type == "file"){parent = item.parent;}else{parent = item.id;}chrome.bookmarks.create({parentId: parent, title:title, url:url},function(e){});}else if(flag =="delete"){deleteItem(item.id);$('#'+item.li_attr.id).hide();chrome.bookmarks.remove(item.id,function(){});}} },danger: {label: "No",className: "btn-danger",callback: function() {}}}});}$('#detailBookmark').on('click',function(){var url = "chrome://bookmarks";chrome.windows.create({top:0,left:2000,width:800,height:500,type:'popup',url: url,focused: true},function(window){panel = window.id})});var newTab = function(url){chrome.tabs.query({ active: true, currentWindow: true },function(tab){var currentIndex = tab[0].index + 1;var windowId = tab[0].id;chrome.tabs.create({'url': url ,index:currentIndex}, function(tab) {});  chrome.tabs.onRemoved.addListener(function(tabId, removeInfo) {chrome.tabs.update(windowId, {active:true}, function(e){})});})};var newPanel = function(url){opened = true;chrome.windows.create({width:1024,height:768,type:'detached_panel',url: url ,focused: true,state:'docked'},function(window){panel = window.id})};function createTree(data,flag){var id_value;if(flag=='default'){id_value='';}else{id_value='Group';}var id ,flag, url;$('#data'+id_value).on('dblclick', '.jstree-anchor', function (e) { if(flag=='file'){newTab(url);};});$('#data'+id_value).on('select_node.jstree', function (e, data) {var splitData = data.node.data.split(" ");id = Number(splitData[0]);flag = splitData[1];url  = splitData[2]; }).jstree({'core' : {'data' : data,"check_callback" : false},plugins: ["themes","dnd","contextmenu","ui", "crrm",],"contextmenu": {"items": function ($node) {return {"Panel": {"_class": "class",  "icon": "/img/new2.png","label": "new Panel","action": function (obj) {var inst = $.jstree.reference(obj.reference),item = inst.get_node(obj.reference);var data = item.data.split(" ");var id = data[0];var flag = data[1];var url = data[2];if(flag == "file"){chrome.windows.create({top:0,left:2000,width:800,height:500,type:'detached_panel',url: url,focused: true},function(window){panel = window.id}) }else{bootbox.alert("Can't open the folder Type.", function() {});}}},"Rename": {"separator_before"  : true,"_class": "class",  "icon": "/img/rename.gif","label": "Update","action": function (obj) {var inst = $.jstree.reference(obj.reference),item = inst.get_node(obj.reference);updateBookmark('rename', item);}},"Delete": {"label": "Delete","_class": "class",  "icon": "/img/trash.gif","action": function (obj) {var inst = $.jstree.reference(obj.reference),item = inst.get_node(obj.reference);updateBookmark('delete', item);}}};}} });}