提交 e7b15dab authored 作者: yujiejie's avatar yujiejie

admintikuwancheng,xuyaoshanchuxijieanniu

上级 db364b7c
差异被折叠。
$root = 'd:\codebuddyfile\1008cs3.0\1008studyweb_Prototype_v2.0'
$browser = 'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe'
$html = Get-Content -Raw -Encoding UTF8 (Join-Path $root 'index.html')
$inject = @'
<script>
window.__errs = [];
window.onerror = function(m, s, l, c, e) { window.__errs.push(m + ' @' + s + ':' + l); return false; };
function clickByText(txt) {
var btns = document.querySelectorAll('button');
for (var i = 0; i < btns.length; i++) {
if ((btns[i].textContent || '').indexOf(txt) !== -1) { btns[i].click(); return true; }
}
return false;
}
window.addEventListener('load', function() {
var out = [];
try { doLoginAs('admin'); } catch (e) { out.push('ERR:login::' + e.message); }
try { switchPage('admin-question-bank'); } catch (e) { out.push('ERR:bank::' + e.message); }
out.push('clickAdd:' + clickByText('添加试题'));
out.push('page:' + String(currentPage));
out.push('clickManual:' + clickByText('手动录题'));
out.push('afterManual:' + String(currentPage) + '/tab=' + String(qbState && qbState.createTab));
out.push('clickAi:' + clickByText('AI 出题'));
out.push('afterAi:' + String(currentPage) + '/tab=' + String(qbState && qbState.createTab));
out.push('clickBatch:' + clickByText('批量录入'));
out.push('afterBatch:' + String(qbState && qbState.createTab));
var d = document.createElement('div');
d.id = 'ERROUT';
d.textContent = 'RESULT>>> ' + out.join(' | ') + ' >>>WINERR: ' + window.__errs.join(' | ');
document.body.appendChild(d);
});
</script>
'@
$html = $html -replace '</body>', ($inject + '</body>')
$preview = Join-Path $root '_preview_click.html'
Set-Content -Path $preview -Value $html -Encoding UTF8
$domFile = 'd:\codebuddyfile\1008cs3.0\.codebuddy\dom.html'
& $browser '--headless=new' '--disable-gpu' '--virtual-time-budget=4000' '--dump-dom' ('file:///' + ($preview -replace '\\', '/')) 2>$null | Set-Content -Path $domFile -Encoding UTF8
$dom = Get-Content -Raw -Encoding UTF8 $domFile
$idx = $dom.IndexOf('<div id="ERROUT">')
if ($idx -ge 0) { Write-Output $dom.Substring($idx, [Math]::Min(900, $dom.Length - $idx)) } else { Write-Output 'NO_ERROUT_DIV' }
$files = @(
'd:\codebuddyfile\1008cs3.0\1008studyweb_Prototype_v2.0\pages\admin\question-bank.js',
'd:\codebuddyfile\1008cs3.0\1008studyweb_Prototype_v2.0\pages\admin\exam-paper.js'
)
foreach ($f in $files) {
$txt = Get-Content -Raw -Encoding UTF8 $f
$a = ([regex]::Matches($txt, "difficulty: '容易'")).Count
$b = ([regex]::Matches($txt, "difficulty: '中等'")).Count
$txt = $txt -replace "difficulty: '容易'", "difficulty: '简单'"
$txt = $txt -replace "difficulty: '中等'", "difficulty: '普通'"
Set-Content -Path $f -Value $txt -Encoding UTF8
Write-Output ("{0}: 容易->{1}, 中等->{2}" -f (Split-Path $f -Leaf), $a, $b)
}
$root = 'd:\codebuddyfile\1008cs3.0\1008studyweb_Prototype_v2.0'
$browser = 'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe'
$html = Get-Content -Raw -Encoding UTF8 (Join-Path $root 'index.html')
$inject = @'
<script>
window.__errs = [];
window.onerror = function(m, s, l, c, e) { window.__errs.push(m + ' @' + s + ':' + l); return false; };
window.addEventListener('load', function() {
var out = [];
function step(name, fn) { try { fn(); out.push('OK:' + name); } catch (e) { out.push('ERR:' + name + '::' + (e && e.message)); } }
step('login', function() { doLoginAs('admin'); });
step('bank', function() { switchPage('admin-question-bank'); });
step('createPage', function() { qbOpenCreatePage(); });
step('tabManual', function() { qbCreateSetTab('manual'); });
step('tabAi', function() { qbCreateSetTab('ai'); });
step('tabBatch', function() { qbCreateSetTab('batch'); });
step('editPage', function() { qbOpenEditPage(5); });
step('examPaper', function() { switchPage('admin-exam-paper'); });
step('examCreate', function() { epOpenCreatePaper(); });
step('examEdit', function() { epOpenPaperDrawer(1); });
step('examPicker', function() { epOpenPicker(0); });
step('examSettings', function() { epOpenExamSettings(1); });
step('tags', function() { switchPage('admin-knowledge-tags'); });
step('projects', function() { switchPage('admin-projects'); });
step('flow', function() { switchPage('admin-training-flow'); });
var d = document.createElement('div');
d.id = 'ERROUT';
d.textContent = 'RESULT>>> ' + out.join(' | ') + ' >>>WINERR: ' + window.__errs.join(' | ');
document.body.appendChild(d);
});
</script>
'@
$html = $html -replace '</body>', ($inject + '</body>')
$preview = Join-Path $root '_preview_rt.html'
Set-Content -Path $preview -Value $html -Encoding UTF8
$domFile = 'd:\codebuddyfile\1008cs3.0\.codebuddy\dom.html'
& $browser '--headless=new' '--disable-gpu' '--virtual-time-budget=4000' ('--dump-dom') ('file:///' + ($preview -replace '\\', '/')) 2>$null | Set-Content -Path $domFile -Encoding UTF8
$dom = Get-Content -Raw -Encoding UTF8 $domFile
$idx = $dom.IndexOf('<div id="ERROUT">')
if ($idx -ge 0) {
$seg = $dom.Substring($idx, [Math]::Min(1500, $dom.Length - $idx))
Write-Output ("FOUND: " + $seg)
} else {
Write-Output 'NO_ERROUT_DIV'
}
$root = 'd:\codebuddyfile\1008cs3.0\1008studyweb_Prototype_v2.0'
$shots = 'd:\codebuddyfile\1008cs3.0\.codebuddy\shots'
if (-not (Test-Path $shots)) { New-Item -ItemType Directory -Path $shots -Force | Out-Null }
$candidates = @(
'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe',
'C:\Program Files\Microsoft\Edge\Application\msedge.exe',
'C:\Program Files\Google\Chrome\Application\chrome.exe',
'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
)
$browser = $null
foreach ($c in $candidates) { if (Test-Path $c) { $browser = $c; break } }
if (-not $browser) { Write-Output 'NO_BROWSER'; exit 1 }
Write-Output ("BROWSER: " + $browser)
$html = Get-Content -Raw -Encoding UTF8 (Join-Path $root 'index.html')
$inject = '<script>window.addEventListener("load",function(){try{doLoginAs("admin");switchPage("admin-question-bank");}catch(e){document.title="ERR:"+e.message;}});</script>'
$html = $html -replace '</body>', ($inject + '</body>')
$preview = Join-Path $root '_preview_qb.html'
Set-Content -Path $preview -Value $html -Encoding UTF8
$out = Join-Path $shots 'question-bank.png'
$args = @(
'--headless=new',
'--disable-gpu',
'--hide-scrollbars',
'--window-size=1680,1500',
('--screenshot=' + $out),
('file:///' + ($preview -replace '\\', '/'))
)
& $browser $args 2>&1 | Out-Null
Start-Sleep -Seconds 3
if (Test-Path $out) {
$fi = Get-Item $out
Write-Output ("SHOT: " + $out + " (" + $fi.Length + " bytes)")
} else {
Write-Output 'SHOT_FAILED'
}
$files = @(
'd:\codebuddyfile\1008cs3.0\1008studyweb_Prototype_v2.0\pages\admin\question-bank.js',
'd:\codebuddyfile\1008cs3.0\1008studyweb_Prototype_v2.0\pages\admin\exam-paper.js'
)
foreach ($f in $files) {
$txt = Get-Content -Raw -Encoding UTF8 $f
$before = ([regex]::Matches($txt, "stem: '\[[^\]]+\]")).Count
$txt = [regex]::Replace($txt, "stem: '\[[^\]]+\]\s*", "stem: '")
Set-Content -Path $f -Value $txt -Encoding UTF8
Write-Output ("{0} -> removed {1} prefixes" -f (Split-Path $f -Leaf), $before)
}
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论