mirror of
https://github.com/jiojciojsioe3/a3cjroijsiojiorj.git
synced 2024-11-15 15:31:51 +08:00
Plugin fixes
- Support returning a promise in the plugin load() function - strReplace can now replace more than one occurence with a parameter, specify how many occurences are expected, with Infinity being as much as possible - this.log() function now accepts multiple arguments
This commit is contained in:
parent
6ad78cc547
commit
bedcc1e5ef
@ -143,12 +143,21 @@ class Plugins{
|
||||
var length = searchString.length
|
||||
return input.slice(0, index + length) + insertedText + input.slice(index + length)
|
||||
}
|
||||
strReplace(input, searchString, insertedText){
|
||||
var index = input.indexOf(searchString)
|
||||
strReplace(input, searchString, insertedText, repeat=1){
|
||||
var position = 0
|
||||
for(var i = 0; i < repeat; i++){
|
||||
var index = input.indexOf(searchString, position)
|
||||
if(index === -1){
|
||||
if(repeat === Infinity){
|
||||
break
|
||||
}else{
|
||||
throw new Error("searchString not found: " + searchString)
|
||||
}
|
||||
return input.slice(0, index) + insertedText + input.slice(index + searchString.length)
|
||||
}
|
||||
input = input.slice(0, index) + insertedText + input.slice(index + searchString.length)
|
||||
position = index + insertedText.length
|
||||
}
|
||||
return input
|
||||
}
|
||||
|
||||
hasSettings(){
|
||||
@ -288,17 +297,25 @@ class PluginLoader{
|
||||
this.error()
|
||||
return
|
||||
}
|
||||
var output
|
||||
try{
|
||||
if(this.module.beforeLoad){
|
||||
this.module.beforeLoad(this)
|
||||
}
|
||||
if(this.module.load){
|
||||
this.module.load(this)
|
||||
output = this.module.load(this)
|
||||
}
|
||||
}catch(e){
|
||||
console.error(e)
|
||||
this.error()
|
||||
}
|
||||
if(typeof output === "object" && output.constructor === Promise){
|
||||
return output.catch(e => {
|
||||
console.error(e)
|
||||
this.error()
|
||||
return Promise.resolve()
|
||||
})
|
||||
}
|
||||
}, e => {
|
||||
console.error(e)
|
||||
this.error()
|
||||
@ -494,12 +511,12 @@ class Patch{
|
||||
beforeUnload(){
|
||||
this.edits.forEach(edit => edit.unload())
|
||||
}
|
||||
log(message){
|
||||
log(...args){
|
||||
var name = this.name || "Plugin"
|
||||
console.log(
|
||||
"%c[" + name + "]%c " + message,
|
||||
"%c[" + name + "]",
|
||||
"font-weight: bold;",
|
||||
""
|
||||
...args
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user