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

< 사용자:하늘‎ | 메모장
하늘 (토론 | 기여)님의 2022년 8월 7일 (일) 14:06 판
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.tagName == 'TABLE'; iter = iter.nextElementSibling);
iter.before(topush);

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