====== Differences ====== This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
script_customviewlog [2016/08/30 19:22] cdfa |
script_customviewlog [2016/11/18 15:24] (current) cdfa |
||
---|---|---|---|
Line 3: | Line 3: | ||
* Author : cdfa | * Author : cdfa | ||
* Link : https://plus.google.com/100430440392224314007/posts/ht4aZS8LSWg | * Link : https://plus.google.com/100430440392224314007/posts/ht4aZS8LSWg | ||
- | * Version: 1.0.5.1 | + | * Version: 1.0.6.3 |
====== How to use the script ====== | ====== How to use the script ====== | ||
Line 11: | Line 11: | ||
====== (copy/paste) ====== | ====== (copy/paste) ====== | ||
<sxh javascript> | <sxh javascript> | ||
- | var logScript=LL.getScriptByName('logScript');if(logScript){try{return eval('(function(){'+logScript.getText()+'})()');}catch(e){if(e.message!="Custom view not found!"&&e.message!="Custom view not loaded!"){alert("At line "+e.lineNumber+": "+e);}function log(){}}}else{function log(){}}/*logScriptEnd*/ | + | function log(){}try{return(function(){var logScript=getScriptByName('logScript');if(logScript){eval('function run(){'+logScript.getText()+'}');return run();}})();}catch(e){alert("At line "+e.lineNumber+": "+e);}/*logScriptEnd*/ |
</sxh> | </sxh> | ||
- | (before this gets executed you can't use the log function, errors won't get caught) | + | (before this gets executed you can't use the log function and errors won't get caught) |
- | log function: | + | usage: |
log(text, logLevel, replacements..) | log(text, logLevel, replacements..) | ||
Line 51: | Line 51: | ||
* Small fix for the log getting too big. | * Small fix for the log getting too big. | ||
* You can now run the script from an item to create a custom view with the same dimensions as the item. | * You can now run the script from an item to create a custom view with the same dimensions as the item. | ||
+ | |||
+ | 1.0.6 | ||
+ | * Your code isn't executed in eval anymore! | ||
+ | |||
+ | 1.0.6.1 | ||
+ | * Fixed a bug with the script name | ||
+ | |||
+ | 1.0.6.2 | ||
+ | * Fixed a few bugs related to unreachable logfile | ||
+ | |||
+ | 1.0.6.3 | ||
+ | * Fixed date | ||
====== Things to keep in mind ====== | ====== Things to keep in mind ====== | ||
- | * Your code is executed in eval(), so some weird stuff might happen | + | * The log won't catch syntax errors |
- | * The log won't catch errors thrown by the compiler | + | |
* For some reason the paused event doesn't get fired when you restart the app, so new logs since the last pause won't be saved | * For some reason the paused event doesn't get fired when you restart the app, so new logs since the last pause won't be saved | ||
Line 62: | Line 73: | ||
put this in script to use logScript | put this in script to use logScript | ||
- | var logScript=LL.getScriptByName('logScript');if(logScript){try{return eval('(function(){'+logScript.getText()+'})()');}catch(e){if(e.message!="Custom view not found!"&&e.message!="Custom view not loaded!"){alert("At line "+e.lineNumber+": "+e);}function log(){}}}else{function log(){}}/*logScriptEnd*/ | + | function log(){}try{return(function(){var logScript=getScriptByName('logScript');if(logScript){eval('function run(){'+logScript.getText()+'}');return run();}})();}catch(e){alert("At line "+e.lineNumber+": "+e);}/*logScriptEnd*/ |
//CONFIG | //CONFIG | ||
- | var logScript={ | + | var logScript = { |
- | logFilePath:"/storage/sdcard0/LightningLauncher/script/logScriptLog.html" | + | logFilePath: "/storage/sdcard0/LightningLauncher/script/logScriptLog.html" |
- | , lineWrapping:true // might require app restart | + | , lineWrapping: true // might require app restart |
- | , bgColor:0xff191919 | + | , bgColor: 0xff191919 |
- | , textColors:["#d0d0d0", "#ee7600"]// the script iterates through these colors with each new "session" | + | , textColors: ["#d0d0d0", "#ee7600"] // the script iterates through these colors with each new "session" |
- | , logLevel:{ | + | , logLevel: { |
- | NORMAL:{name:"[NORMAL]", color:"#ffffff"} | + | NORMAL: { |
- | , DEBUG:{name:"[DEBUG]", color:"#0000ff"} | + | name: "[NORMAL]" |
- | , ERROR:{name:"[ERROR]", color:"#ff0000"} | + | , color: "#ffffff" |
+ | } | ||
+ | , DEBUG: { | ||
+ | name: "[DEBUG]" | ||
+ | , color: "#0000ff" | ||
+ | } | ||
+ | , ERROR: { | ||
+ | name: "[ERROR]" | ||
+ | , color: "#ff0000" | ||
+ | } | ||
} | } | ||
, defaultLogLevel: "NORMAL" | , defaultLogLevel: "NORMAL" | ||
, saveMode: true | , saveMode: true | ||
- | // END CONFIG | + | // END CONFIG |
- | , getScript:function(){ | + | , currentScript: getCurrentScript() |
- | return this.script = this.script || LL.getScriptByName("logScript"); | + | , getScript: function() { |
+ | return this.script = this.script || getScriptByName("logScript"); | ||
} | } | ||
- | , scrollDown:function(sv){ | + | , scrollDown: function(sv) { |
- | sv.post(new Runnable(){ | + | sv.post(new Runnable() { |
- | run:function(){ | + | run: function() { |
- | sv.fullScroll(ScrollView.FOCUS_DOWN); | + | sv.fullScroll(ScrollView.FOCUS_DOWN); |
} | } | ||
- | }); | + | }); |
} | } | ||
- | , getCVItem:function(){ | + | , getCVItem: function() { |
- | if(!this.cvItem){ | + | if(!this.cvItem) { |
- | this.cvItem = LL.getItemById(this.getScript().getTag("cvId")); | + | this.cvItem = getActiveScreen().getAllItemsById(this.getScript().getTag("cvId"))[0]; |
if(!this.cvItem) throw new Error("Custom view not found!") | if(!this.cvItem) throw new Error("Custom view not found!") | ||
} | } | ||
return this.cvItem | return this.cvItem | ||
} | } | ||
- | , getCV:function(){ | + | , getCV: function() { |
- | if(!this.cv){ | + | if(!this.cv) { |
this.cv = this.getCVItem().getView() | this.cv = this.getCVItem().getView() | ||
if(!this.cv) throw new Error("Custom view not loaded!"); | if(!this.cv) throw new Error("Custom view not loaded!"); | ||
Line 102: | Line 122: | ||
return this.cv | return this.cv | ||
} | } | ||
- | , getSV:function(){ | + | , getSV: function() { |
- | if(!this.sv){ | + | if(!this.sv) { |
var cv = this.getCV() | var cv = this.getCV() | ||
- | for(var i=0; i<cv.getChildCount(); i++){ | + | for(var i = 0; i < cv.getChildCount(); i++) { |
- | this.sv=cv.getChildAt(i); | + | this.sv = cv.getChildAt(i); |
- | if(this.sv.getTag()=="sv") | + | if(this.sv.getTag() == "sv") |
- | break; | + | break; |
} | } | ||
} | } | ||
return this.sv | return this.sv | ||
} | } | ||
- | , getTV:function(){ | + | , getTV: function() { |
if(!this.tv) | if(!this.tv) | ||
this.tv = this.getSV().getChildAt(0); | this.tv = this.getSV().getChildAt(0); | ||
return this.tv | return this.tv | ||
} | } | ||
- | , createCVItem:function(c){ | + | , createCVItem: function(c) { |
- | var scriptId=script.getId(); | + | var script = getCurrentScript(); |
- | var cv=c.addCustomView(0, 0); | + | var scriptId = script.getId(); |
- | var prop=cv.getProperties().edit(); | + | var cv = c.addCustomView(0, 0); |
- | prop.getBox("i.box").setColor("c", "n", logScript.bgColor); | + | var prop = cv.getProperties().edit(); |
- | prop.setString("v.onCreate", scriptId).commit(); | + | |
- | prop.setEventHandler("i.resumed", EventHandler.RUN_SCRIPT, scriptId); | + | |
- | prop.setEventHandler("i.paused", EventHandler.RUN_SCRIPT, scriptId); | + | |
- | prop.commit(); | + | |
script.setTag("cvId", cv.getId()); | script.setTag("cvId", cv.getId()); | ||
+ | prop.getBox("i.box").setColor("c", "n", logScript.bgColor); | ||
+ | prop.setString("v.onCreate", scriptId).commit(); | ||
+ | prop.setEventHandler("i.resumed", EventHandler.RUN_SCRIPT, scriptId); | ||
+ | prop.setEventHandler("i.paused", EventHandler.RUN_SCRIPT, scriptId); | ||
+ | prop.commit(); | ||
return cv; | return cv; | ||
+ | } | ||
+ | , isTVAvailable: function() { | ||
+ | try { | ||
+ | logScript.getTV() | ||
+ | return true; | ||
+ | } catch(e) { | ||
+ | if(e.message != "Custom view not found!" && e.message != "Custom view not loaded!") { | ||
+ | throw e; | ||
+ | } | ||
+ | return false; | ||
+ | } | ||
} | } | ||
}; | }; | ||
- | LL.bindClass("java.io.File"); | + | bindClass("java.io.File"); |
- | LL.bindClass("java.io.FileWriter"); | + | bindClass("java.io.FileWriter"); |
- | LL.bindClass("java.io.BufferedWriter"); | + | bindClass("java.io.PrintWriter"); |
- | LL.bindClass("android.widget.TextView"); | + | bindClass("java.io.BufferedWriter"); |
- | LL.bindClass("android.text.method.ScrollingMovementMethod"); | + | bindClass("android.widget.TextView"); |
- | LL.bindClass("android.text.Html"); | + | bindClass("android.text.method.ScrollingMovementMethod"); |
- | LL.bindClass("java.io.BufferedReader"); | + | bindClass("android.text.Html"); |
- | LL.bindClass("java.io.FileReader"); | + | bindClass("java.io.BufferedReader"); |
- | LL.bindClass("android.widget.ScrollView"); | + | bindClass("java.io.FileReader"); |
- | LL.bindClass("android.view.View"); | + | bindClass("android.widget.ScrollView"); |
- | LL.bindClass("java.lang.Runnable"); | + | bindClass("android.view.View"); |
- | LL.bindClass("android.widget.Button"); | + | bindClass("java.lang.Runnable"); |
- | LL.bindClass("android.widget.FrameLayout"); | + | bindClass("android.widget.Button"); |
- | LL.bindClass("android.view.Gravity"); | + | bindClass("android.widget.FrameLayout"); |
+ | bindClass("android.view.Gravity"); | ||
- | function log(text, logLevel /**/){ | + | function log(text, logLevel /**/ ) { |
logLevel = logLevel || logScript.logLevel[logScript.defaultLogLevel]; | logLevel = logLevel || logScript.logLevel[logScript.defaultLogLevel]; | ||
- | | + | |
- | for(var i=2; i<arguments.length; i++){ | + | for(var i = 2; i < arguments.length; i++) { |
- | newText = text.replace("{}", arguments[i]); | + | var newText = text.replace("{}", arguments[i]); |
- | if(newText==text){ | + | if(newText == text) { |
break; | break; | ||
- | }else{ | + | } else { |
text = newText; | text = newText; | ||
} | } | ||
} | } | ||
- | | ||
- | var date=new Date(); | ||
- | var month=date.getMonth()+1; | ||
- | var scriptName=LL.getCurrentScript().getName(); | ||
- | var logText="<font color=#add8e6>"+date.getDate()+"-"+month+ | ||
- | "</font>"+" <font color=#ffff00>"+date.toTimeString().slice(0, 8)+ | ||
- | "</font>"+" <font color=#00ff00>"+scriptName+"</font>"+ | ||
- | " <font color="+logLevel.color+">"+logLevel.name+"</font>"+": "+ | ||
- | " <font color="+logScript.textColors[logScript.ind]+">"+text+ | ||
- | "</font>"; | ||
- | if(logScript.getSV()){ | + | var date = new Date(); |
- | var tvOldLength = logScript.getTV().length() | + | var logText = "<font color=#add8e6>" + date.getDate() + "-" + (date.getMonth() + 1) + |
- | logScript.getTV().append(Html.fromHtml(logText).append("\n")); | + | "</font>" + " <font color=#ffff00>" + date.toTimeString().slice(0, 8) + |
- | logScript.scrollDown(logScript.getSV()); | + | "</font>" + " <font color=#00ff00>" + logScript.currentScript.getName() + "</font>" + |
- | if(logScript.saveMode){ | + | " <font color=" + logLevel.color + ">" + logLevel.name + "</font>" + ": " + |
+ | " <font color=" + logScript.textColors[logScript.ind] + ">" + text + | ||
+ | "</font>"; | ||
+ | |||
+ | if(logScript.isTVAvailable()) { | ||
+ | var tv = logScript.getTV() | ||
+ | var tvOldLength = tv.length() | ||
+ | tv.append(Html.fromHtml(logText).append("\n")); | ||
+ | logScript.scrollDown(logScript.getSV()); | ||
+ | if(logScript.saveMode) { | ||
var script = logScript.getScript() | var script = logScript.getScript() | ||
- | var prevLogInd = script.getTag("prevLogInd")||-1 | + | var prevLogInd = script.getTag("prevLogInd") || -1 |
var prevLog = JSON.parse(script.getTag("log" + prevLogInd)) | var prevLog = JSON.parse(script.getTag("log" + prevLogInd)) | ||
- | var tvNewLength = logScript.getTV().length() | + | var tvNewLength = tv.length() |
- | if(prevLog && prevLog[1]==tvOldLength){ | + | if(prevLog && prevLog[1] == tvOldLength) { |
- | prevLog[1] = logScript.getTV().length() | + | prevLog[1] = tv.length() |
script.setTag("log" + prevLogInd, JSON.stringify(prevLog)); | script.setTag("log" + prevLogInd, JSON.stringify(prevLog)); | ||
- | }else{ | + | } else { |
prevLogInd++ | prevLogInd++ | ||
script.setTag("log" + prevLogInd, JSON.stringify([tvOldLength, tvNewLength])) | script.setTag("log" + prevLogInd, JSON.stringify([tvOldLength, tvNewLength])) | ||
Line 187: | Line 219: | ||
} | } | ||
} | } | ||
+ | } else { | ||
+ | logScript.logText += logText; | ||
} | } | ||
} | } | ||
- | function read(filePath){ | + | function cleanEval(text) { |
- | try{ | + | eval('function execute() {' + text + '}'); |
- | var r=new BufferedReader(new FileReader(filePath)); | + | execute(); |
- | var s=""; | + | |
- | var l; | + | |
- | while((l=r.readLine())!=null)s+=(l+"\n"); | + | |
- | return s; | + | |
- | }catch(e){ | + | |
- | return ""; | + | |
- | } | + | |
} | } | ||
- | if(LL.getCurrentScript().getName()=="logScript"){ | + | return(function() { |
- | var script=LL.getCurrentScript(); | + | function read(filePath) { |
- | + | try { | |
- | try{ | + | var r = new BufferedReader(new FileReader(filePath)); |
- | typeof item; | + | var s = ""; |
- | }catch(e){ | + | var l; |
- | // in create | + | while((l = r.readLine()) != null) s += (l + "\n"); |
- | var cv=item; | + | return s; |
- | var context=LL.getContext(); | + | } catch(e) { |
- | var tv=new TextView(context); | + | return ""; |
- | var sv=new ScrollView(context); | + | } |
- | sv.addView(tv); | + | } |
- | sv.setTag("sv"); | + | |
- | tv.setMovementMethod(new ScrollingMovementMethod()); | + | if(logScript.currentScript.getName() == "logScript") { |
- | tv.setTextColor(0xffffffff) | + | try { |
+ | typeof item; | ||
+ | } catch(e) { | ||
+ | // in create | ||
+ | var cv = item; | ||
+ | var context = getActiveScreen().getContext(); | ||
+ | var tv = new TextView(context); | ||
+ | var sv = new ScrollView(context); | ||
+ | sv.addView(tv); | ||
+ | sv.setTag("sv"); | ||
- | cv.setVerticalGrab(true); | + | tv.setMovementMethod(new ScrollingMovementMethod()); |
- | tv.setVerticalScrollBarEnabled(true); | + | tv.setTextColor(0xffffffff) |
- | if(!logScript.lineWrapping){ | + | cv.setVerticalGrab(true); |
- | tv.setHorizontallyScrolling(true); | + | tv.setVerticalScrollBarEnabled(true); |
- | cv.setHorizontalGrab(true); | + | |
- | } | + | |
- | var button=new Button(context); | + | if(!logScript.lineWrapping) { |
- | button.setText("clear log"); | + | tv.setHorizontallyScrolling(true); |
- | button.setOnClickListener(new View.OnClickListener(){ | + | cv.setHorizontalGrab(true); |
- | onClick:function(v){ | + | |
- | new File(logScript.logFilePath).delete(); | + | |
- | try{ | + | |
- | logScript.getTV(); | + | |
- | tv.setText(""); | + | |
- | logScript.getScript().setTag("prevLogInd", null) | + | |
- | }catch(e){} | + | |
} | } | ||
- | }); | ||
- | button.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.TOP|Gravity.RIGHT)); | ||
- | var layout=new FrameLayout(context); | + | var button = new Button(context); |
- | layout.addView(sv); | + | button.setText("clear log"); |
- | layout.addView(button); | + | button.setOnClickListener(new View.OnClickListener() { |
+ | onClick: function(v) { | ||
+ | new File(logScript.logFilePath).delete(); | ||
+ | try { | ||
+ | logScript.getTV(); | ||
+ | tv.setText(""); | ||
+ | logScript.getScript().setTag("prevLogInd", null) | ||
+ | } catch(e) {} | ||
+ | } | ||
+ | }); | ||
+ | button.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.TOP | Gravity.RIGHT)); | ||
- | logScript.scrollDown(sv); | + | var layout = new FrameLayout(context); |
- | return layout; | + | layout.addView(sv); |
- | } | + | layout.addView(button); |
- | var e=LL.getEvent(); | + | logScript.scrollDown(sv); |
- | var src=e.getSource(); | + | return layout; |
- | switch(src){ | + | } |
- | case "MENU_APP": | + | |
- | //in container | + | var e = getEvent(); |
- | var cv = logScript.createCVItem(e.getContainer()) | + | var src = e.getSource(); |
- | cv.setPosition(e.getTouchX(), e.getTouchY()) | + | switch(src) { |
- | break; | + | case "MENU_APP": |
- | case "MENU_ITEM": | + | //in container |
- | var it = e.getItem(); | + | var cv = logScript.createCVItem(e.getContainer()) |
- | var c = it.getParent(); | + | cv.setPosition(e.getTouchX(), e.getTouchY()) |
- | var cv = logScript.createCVItem(c); | + | break; |
- | cv.setSize(it.getWidth(), it.getHeight()); | + | case "MENU_ITEM": |
- | cv.setPosition(it.getPositionX(), it.getPositionY()) | + | var it = e.getItem(); |
- | c.removeItem(it); | + | var c = it.getParent(); |
- | break; | + | var cv = logScript.createCVItem(c); |
- | case "I_RESUMED": | + | cv.setSize(it.getWidth(), it.getHeight()); |
- | // in resume | + | cv.setPosition(it.getPositionX(), it.getPositionY()) |
- | logScript.getTV(); | + | c.removeItem(it); |
- | var savedLogText = read(logScript.logFilePath) | + | break; |
- | if(savedLogText.length>50000){ | + | case "I_RESUMED": |
- | savedLogText = savedLogText.substring(10000, savedLogText.length) | + | // in resume |
- | savedLogText = savedLogText.substring(savedLogText.indexOf("<br>"), savedLogText.length); | + | var tv = logScript.getTV(); |
+ | try { | ||
+ | var logFile = new File(logScript.logFilePath); | ||
+ | } catch(e) {} | ||
+ | |||
+ | if(logFile !== null && tv.getText().length() == 0 || logFile.lastModified() > logScript.getScript().getTag("lastLoaded")) { | ||
+ | var savedLogText = read(logScript.logFilePath) | ||
+ | |||
+ | if(savedLogText.length > 30000) { | ||
+ | savedLogText = savedLogText.substring(savedLogText.length - 20000, savedLogText.length) | ||
+ | savedLogText = savedLogText.substring(savedLogText.indexOf("<br>"), savedLogText.length); | ||
+ | } | ||
+ | tv.setText(Html.fromHtml(savedLogText)); | ||
+ | try { | ||
+ | var pw = new PrintWriter(new File(logScript.logFilePath)); | ||
+ | pw.print(""); | ||
+ | pw.write(savedLogText); | ||
+ | } catch(e) {} finally { | ||
+ | if(pw) pw.close(); | ||
+ | } | ||
+ | logScript.getScript().setTag("lastLoaded", new Date().getTime()) | ||
+ | } | ||
+ | logScript.scrollDown(logScript.getSV()); | ||
+ | break; | ||
+ | case "I_PAUSED": | ||
+ | try { | ||
+ | var bfWriter = new BufferedWriter(new FileWriter(new File(logScript.logFilePath), true)); | ||
+ | var unsavedLog; | ||
+ | var i = 0; | ||
+ | var script = logScript.getScript() | ||
+ | while(unsavedLog = script.getTag("log" + i)) { | ||
+ | var unsavedLog = JSON.parse(unsavedLog) | ||
+ | var fullText = logScript.getTV().getEditableText(); | ||
+ | if(fullText && fullText.length() != 0 && fullText.length() >= unsavedLog[1]) { | ||
+ | var unsavedLogTextString = Html.toHtml(fullText.subSequence(unsavedLog[0], unsavedLog[1])); | ||
+ | bfWriter.append(unsavedLogTextString.substring(unsavedLogTextString.indexOf('>') + 1, unsavedLogTextString.lastIndexOf('<'))); | ||
+ | } | ||
+ | script.setTag("log" + i, null) | ||
+ | i++; | ||
+ | } | ||
+ | script.setTag("prevLogInd", null); | ||
+ | } catch(e) {} finally { | ||
+ | if(bfWriter) bfWriter.close(); | ||
+ | } | ||
+ | break; | ||
+ | } | ||
+ | } else { | ||
+ | //in eval() | ||
+ | logScript.ind = parseInt(logScript.getScript().getTag("prevColorIndex") || "0"); | ||
+ | var tvAvailable = logScript.isTVAvailable() | ||
+ | if(!tvAvailable) | ||
+ | logScript.logText = ""; | ||
+ | |||
+ | var text = logScript.currentScript.getText(); | ||
+ | var returns = ""; | ||
+ | for(var i = 0; i < text.substr(0, text.search("var logScript")).split("\n").length; i++) { | ||
+ | returns += "\n"; | ||
+ | } | ||
+ | text = text.substr(text.search("logScriptEnd") + 12); | ||
+ | if(text.charAt(0) == "*") { | ||
+ | text = text.slice(2, text.length); | ||
+ | returns = returns.slice(1, returns.length); | ||
+ | } | ||
+ | var counter = 0; | ||
+ | for(var i = 0; i < text.length; i++) { | ||
+ | if(text.charAt(i) == "{") | ||
+ | counter++; | ||
+ | else if(text.charAt(i) == "}") | ||
+ | counter--; | ||
+ | |||
+ | if(counter < 0) { | ||
+ | break; | ||
} | } | ||
- | logScript.getTV().setText(Html.fromHtml(savedLogText)); | + | } |
- | logScript.scrollDown(logScript.getSV()); | + | text = returns + text.slice(0, i); |
- | break; | + | |
- | case "I_PAUSED": | + | try { |
- | try{ | + | return cleanEval(text); |
- | var bfWriter = new BufferedWriter(new FileWriter(new File(logScript.logFilePath), true)); | + | } catch(e) { |
- | var unsavedLog; | + | log("At line " + e.lineNumber + ": " + e, logScript.logLevel.ERROR); |
- | var i = 0; | + | } finally { |
- | var script = logScript.getScript() | + | logScript.getScript().setTag("prevColorIndex", logScript.ind == logScript.textColors.length - 1 ? 0 : logScript.ind + 1); |
- | while(unsavedLog = script.getTag("log"+i)){ | + | } |
- | var unsavedLog = JSON.parse(unsavedLog) | + | |
- | var fullText = logScript.getTV().getEditableText(); | + | if(!tvAvailable) { |
- | if(fullText && fullText.length()!=0){ | + | try { |
- | var unsavedLogTextString = Html.toHtml(fullText.subSequence(unsavedLog[0], unsavedLog[1])); | + | var bfWriter = new BufferedWriter(new FileWriter(new File(logScript.logFilePath), true)); |
- | bfWriter.append(unsavedLogTextString.substring(unsavedLogTextString.indexOf('>') + 1, unsavedLogTextString.lastIndexOf('<'))); | + | bfWriter.append(logScript.logText) |
- | } | + | } catch(e) { |
- | script.setTag("log"+i, null) | + | alert("At line " + e.lineNumber + ": " + e); |
- | i++; | + | } finally { |
- | } | + | if(bfWriter) bfWriter.close(); |
- | script.setTag("prevLogInd", null); | + | |
- | }catch(e){ | + | |
- | alert("At line "+e.lineNumber+": "+e); | + | |
- | } finally{ | + | |
- | bfWriter.flush(); | + | |
} | } | ||
- | break; | + | } |
} | } | ||
- | }else{ | + | })(); |
- | //in eval() | + | |
- | logScript.getTV(); | + | |
- | logScript.ind=parseInt(logScript.getScript().getTag("prevColorIndex")||"0"); | + | |
- | + | ||
- | try{ | + | |
- | return eval('(function() {' | + | |
- | + (function(){ | + | |
- | var text=LL.getCurrentScript().getText(); | + | |
- | var returns=""; | + | |
- | for(var i=0; i<text.substr(0, text.search("var logScript")).split("\n").length; i++){ | + | |
- | returns+="\n"; | + | |
- | } | + | |
- | text=text.substr(text.search("logScriptEnd")+12); | + | |
- | if(text.charAt(0)=="*"){ | + | |
- | text=text.slice(2, text.length); | + | |
- | returns=returns.slice(1, returns.length); | + | |
- | } | + | |
- | return returns+text; | + | |
- | })() | + | |
- | +'}())'); | + | |
- | }catch(e){ | + | |
- | log("At line "+e.lineNumber+": "+e, logScript.logLevel.ERROR); | + | |
- | }finally{ | + | |
- | logScript.getScript().setTag("prevColorIndex", logScript.ind==logScript.textColors.length-1?0:logScript.ind+1); | + | |
- | } | + | |
- | } | + | |
</sxh> | </sxh> |