| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -5,9 +5,7 @@ import com.script.SimpleBindings | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import io.legado.app.constant.AppConst | 
					 | 
					 | 
					 | 
					import io.legado.app.constant.AppConst | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import io.legado.app.exception.RegexTimeoutException | 
					 | 
					 | 
					 | 
					import io.legado.app.exception.RegexTimeoutException | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import io.legado.app.help.CrashHandler | 
					 | 
					 | 
					 | 
					import io.legado.app.help.CrashHandler | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import io.legado.app.help.coroutine.Coroutine | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import kotlinx.coroutines.suspendCancellableCoroutine | 
					 | 
					 | 
					 | 
					import kotlinx.coroutines.suspendCancellableCoroutine | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import splitties.init.appCtx | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import kotlin.coroutines.resume | 
					 | 
					 | 
					 | 
					import kotlin.coroutines.resume | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import kotlin.coroutines.resumeWithException | 
					 | 
					 | 
					 | 
					import kotlin.coroutines.resumeWithException | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -20,7 +18,7 @@ private val handler by lazy { buildMainHandler() } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					suspend fun CharSequence.replace(regex: Regex, replacement: String, timeout: Long): String { | 
					 | 
					 | 
					 | 
					suspend fun CharSequence.replace(regex: Regex, replacement: String, timeout: Long): String { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    val charSequence = this | 
					 | 
					 | 
					 | 
					    val charSequence = this | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    return suspendCancellableCoroutine { block -> | 
					 | 
					 | 
					 | 
					    return suspendCancellableCoroutine { block -> | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        val coroutine = Coroutine.async { | 
					 | 
					 | 
					 | 
					        val thread = Thread { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            try { | 
					 | 
					 | 
					 | 
					            try { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                if (replacement.startsWith("@js:")) { | 
					 | 
					 | 
					 | 
					                if (replacement.startsWith("@js:")) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    val js = replacement.substring(4) | 
					 | 
					 | 
					 | 
					                    val js = replacement.substring(4) | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -43,18 +41,17 @@ suspend fun CharSequence.replace(regex: Regex, replacement: String, timeout: Lon | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                block.resumeWithException(e) | 
					 | 
					 | 
					 | 
					                block.resumeWithException(e) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            } | 
					 | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        thread.start() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        handler.postDelayed(timeout) { | 
					 | 
					 | 
					 | 
					        handler.postDelayed(timeout) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            if (coroutine.isActive) { | 
					 | 
					 | 
					 | 
					            if (thread.isAlive) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                val timeoutMsg = "替换超时,3秒后还未结束将重启应用\n替换规则$regex\n替换内容:${this}" | 
					 | 
					 | 
					 | 
					                runCatching { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                    @Suppress("DEPRECATION") | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                    thread.stop() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                val timeoutMsg = "替换超时,将禁用替换规则" | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                val exception = RegexTimeoutException(timeoutMsg) | 
					 | 
					 | 
					 | 
					                val exception = RegexTimeoutException(timeoutMsg) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                block.cancel(exception) | 
					 | 
					 | 
					 | 
					                block.cancel(exception) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                appCtx.longToastOnUi(timeoutMsg) | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                CrashHandler.saveCrashInfo2File(exception) | 
					 | 
					 | 
					 | 
					                CrashHandler.saveCrashInfo2File(exception) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                handler.postDelayed(3000) { | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    if (coroutine.isActive) { | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        appCtx.restart() | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    } | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                } | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            } | 
					 | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
  |