回复 33# kidzgy
直接正则替换效率提高的 练手一下
PS- <# :
- @echo off
- PowerShell -NoProfile -C ". ([ScriptBlock]::Create((gc -Literal '%~f0') -join \"`r`n\"))"
- pause & exit/b
- #>
- $oid = [Io.Directory]::GetCurrentDirectory() -replace '\\','\\'
- $pat = '(?<="path":")[^"]+(?=\\\\Profiles\\\\extensions\\\\|\\\\browser\\\\features\\\\)'
- $(gc extensions.json -Raw -Encoding UTF8) -replace $pat , $oid | sc 'extensions.json' -Encoding UTF8
复制代码 JS代码长,效率不低- @if(0)==(0) @echo off
- set "file=extensions.json"
- set "ph=%~dp0"
- cscript.exe -NoLogo -E:JScript %0 "%file%" "%ph:~,-1%"
- PAUSE & exit/b
- @end
- function adoLoadText(filename, charset) {
- stream = new ActiveXObject("ADODB.Stream");
- stream.type = 2;
- stream.charset = charset;
- stream.open();
- stream.loadFromFile(filename);
- text = stream.readText(-1);
- stream.close();
- return(text);
- }
-
- function adoSaveText(filename, text) {
- var stream;
- stream = new ActiveXObject("ADODB.Stream");
- stream.type = 2;
- stream.charset ='utf-8';
- stream.open();
- stream.writeText(text);
- stream.saveToFile(filename, 2);
- stream.close();
- }
-
- var file = WSH.Arguments.Item(0);
- var p = WSH.Arguments.Item(1).replace(/\\/g,"\\\\");
- var jsontext =adoLoadText(file, "UTF-8");
- var re =/("path":")[^"]+(?=\\\\Profiles\\\\extensions\\\\|\\\\browser\\\\features\\\\)/ig;
- adoSaveText('extensions.json',jsontext.replace( re, function($a,$b ) {return($b+p)}));
复制代码
|