사용자:하늘/메모장/js

var licenses
$(function () {
    var textBox = document.querySelector('#wpTextbox1');
    var fileinfo = textBox.value.replace(new RegExp("==[ ]*라이선스[ ]*=="), '/*/');
    var license = fileinfo.split('/*/\n')[1];
    licenses = license.match(/\{\{[^}]*\}\}/g);
    licenses.__proto__.remove = function(key) {
        for (var i=0; i < this.length; i++) {
            if (this[i] == '{{' + key + '}}') {
                this.splice(i, 1); this.repaint(); break;
            }
        }
    }
    licenses.__proto__.add = function(key) {
        this.push('{{' + key + '}}'); this.repaint()
    }
    licenses.__proto__.makeLicenseSection = function() {
        if (this.length < 1)
            return '== 라이선스 ==\n'
        else
            return '== 라이선스 ==\n' + this.join('\n') + '\n';
    }
    
    licenses.__proto__.repaint = function () {
        var textBox = document.querySelector('#wpTextbox1');
        var fileinfo = textBox.value.replace(new RegExp("==[ ]*라이선스[ ]*=="), '/*/');
        var value =
        fileinfo.split('/*/\n')[0] + this.makeLicenseSection() + fileinfo.split('/*/\n')[1].replace(/\{\{[^}]*\}\}\n/g, '');
        document.querySelector('#wpTextbox1').value = value;
    }
})

var h2 = document.querySelector('#라이선스').parentElement;
var iter 
for (iter = h2.nextElementSibling; iter.nextElementSibling != null; iter = iter.nextElementSibling);

// go to end

//드롭 다운 위키 편집기에 추가하거나 파일 업로드 시 나오는 스크립트 등등

function getStopList() {
    var stoplist = "";
    const stoplinks = document.querySelectorAll('#routeRunInfoTbody li td[class] a');

    for (let index = 0; index < stoplinks.length; index++) {
        const e = stoplinks[index];

        if (index === 0)
            stoplist += "'''" + e.innerText + "'''\n";
        else if (index === stoplinks.length - 1)
            stoplist += "----'''" + e.innerText + "'''";
        else
            stoplist += "----" + e.innerText + "\n";

    }

    return stoplist
}

var box = document.createElement("div")
box.classList.add("copybutton")
box.classList.add("myButton")

box.innerText = "노선 복사하기"
box.addEventListener('click', (e) => {
    navigator.clipboard.writeText(getStopList());
})
document.body.append(box)

var css = document.createElement('style')
css.innerText = `
.copybutton {
  position: fixed;
  top: 0px;
  left: 50%;
  padding: 0.7em;
  font-size: 1.5em;
  height: revert;
  width: revert;
}`
document.body.append(css)

vscode Lint는 quick-lint가 편하다.