クリップボードの文字列をインデントするには?

ショコラ
ショコラ

クリップボードの文字列をインデントするには?

HTAアプリでキメマス。
①文字列をコピーしてクリップボード入れる。
②indent+2.hta をダブルクリック
③ペーストでキメマス。

もっさん先輩
もっさん先輩

こちらのリンクを右クリックしてファイルをダウンロードできます。

https://answorz.com/4310/indent+2.hta

スクリプトの説明

<!DOCTYPE html>
<html lang="ja">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=9">
<meta charset="utf-8">
<hta:application id="hta"/>
<script>
var arr = /indent([\+\-])([0-9]+).hta"/.exec(hta.commandLine);
var space = '          '.substr(0,arr[2]);
var lines = window.clipboardData.getData('Text').replace(/\r\n|\r/g,'\n').split('\n');
lines.forEach(function(line,i){
  if ('+' == arr[1]) {
    if (0 < lines.length) {
      lines[i] = space + line;
    }
  }
  if ('-' == arr[1]) {
    var reg = new RegExp('^' + space);
    lines[i] = line.replace(reg,'');
  }
});
window.clipboardData.setData('Text',lines.join('\r\n'));
close();
</script>
</head>
</html>

逆インデント版はこちらです。

https://answorz.com/4310/indent-2.hta

スクリプトの説明

<!DOCTYPE html>
<html lang="ja">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=9">
<meta charset="utf-8">
<hta:application id="hta"/>
<script>
var arr = /indent([\+\-])([0-9]+).hta"/.exec(hta.commandLine);
var space = '          '.substr(0,arr[2]);
var lines = window.clipboardData.getData('Text').replace(/\r\n|\r/g,'\n').split('\n');
lines.forEach(function(line,i){
  if ('+' == arr[1]) {
    if (0 < lines.length) {
      lines[i] = space + line;
    }
  }
  if ('-' == arr[1]) {
    var reg = new RegExp('^' + space);
    lines[i] = line.replace(reg,'');
  }
});
window.clipboardData.setData('Text',lines.join('\r\n'));
close();
</script>
</head>
</html>
Scroll to Top