@@ -8,11 +8,11 @@ import org.matrix.chromext.Chrome
88
99private val blocksReg =
1010 Regex (
11- """ (?<metablock>[\S\s]*?// ==UserScript==\r?\n( [\S\s]*?) \r?\n// ==/UserScript==\s+)(?<code>[\S\s]*)""" )
11+ """ (?<metablock>[\S\s]*?// ==UserScript==\r?\n[\S\s]*?\r?\n// ==/UserScript==\s+)(?<code>[\S\s]*)""" )
1212private val metaReg = Regex (""" ^//\s+@(?<key>[\w-]+)\s+(?<value>.+)""" )
1313
1414fun parseScript (input : String , storage : String? = null): Script ? {
15- val blockMatchGroup = blocksReg.matchEntire(input)?.groups as ? MatchNamedGroupCollection
15+ val blockMatchGroup = blocksReg.matchEntire(input)?.groups
1616 if (blockMatchGroup == null ) {
1717 return null
1818 }
@@ -25,15 +25,15 @@ fun parseScript(input: String, storage: String? = null): Script? {
2525 var grant = mutableListOf<String >()
2626 var exclude = mutableListOf<String >()
2727 var require = mutableListOf<String >()
28- val meta = (blockMatchGroup.get( " metablock " ) ?.value as String )
29- val code = blockMatchGroup.get( " code " ) ?.value as String
28+ val meta = (blockMatchGroup[ 1 ] ?.value as String )
29+ val code = blockMatchGroup[ 2 ] ?.value as String
3030 var storage: JSONObject ? = null
3131 }
3232 script.meta.split(" \n " ).forEach {
33- val metaMatchGroup = metaReg.matchEntire(it)?.groups as ? MatchNamedGroupCollection
33+ val metaMatchGroup = metaReg.matchEntire(it)?.groups
3434 if (metaMatchGroup != null ) {
35- val key = metaMatchGroup.get( " key " ) ?.value as String
36- val value = metaMatchGroup.get( " value " ) ?.value as String
35+ val key = metaMatchGroup[ 1 ] ?.value as String
36+ val value = metaMatchGroup[ 2 ] ?.value as String
3737 when (key) {
3838 " name" -> script.name = value.replace(" :" , " " )
3939 " namespace" -> script.namespace = value
0 commit comments