사용자:하늘/addArticleMenuItem-func.js: 두 판 사이의 차이

잔글 (하늘님이 사용자:하늘/move to series han dict.js 문서를 넘겨주기를 만들지 않고 사용자:하늘/addArticleMenuItem-func.js 문서로 이동했습니다)
편집 요약 없음
27번째 줄: 27번째 줄:
newDropdownItemTest = new newDropdownItem(document.querySelector('.content-tools .dropdown-item:last-child'));
newDropdownItemTest = new newDropdownItem(document.querySelector('.content-tools .dropdown-item:last-child'));
newDropdownItemTest.AddItem(function () {
newDropdownItemTest.AddItem(function () {
         new mw.Api().get({
         mw.loader.load('/index.php?title=사용자:하늘/moveCategory.js&action=raw&ctype=text/javascript');
            action: 'query',
}, '분류 이동하기', '분류를 통째로 이동합니다. !클릭 주의!');
            list: 'categorymembers',
            cmtitle: originCategoryName,
            cmlimit: 'max',
            format: 'json'
        }).then(function (json) {
            json.query.categorymembers.forEach(function (data) {
                console.log(data.title + "\n" + originCategoryName + " -> 분류:" + toCategoryName);
                new mw.Api().edit(
                    data.title,
                    function (revision) {
                        var pattern = new RegExp("\[\[[ ]*분류[ ]*:[ ]*" + originCategoryTitle + "[ ]*\]\]");
                        var pattern2 = new RegExp("\[\[[ ]*분류[ ]*:[ ]*" +
                            originCategoryTitle.charAt(0).toLowerCase() + originCategoryTitle.slice(1) +
                            "[ ]*\]\]");
 
                        var replaced = revision.content.replace(pattern, "[[분류:" + toCategoryName +
                            "]]").replace(pattern2, "[[분류:" + toCategoryName +
                                "]]");
 
                        return {
                            text: replaced
                        };
                    }).then(function (data) {
                        console.log(data);
                    }).fail(function (data) {
                        console.log(data);
                    });
            });
        });
    }, '분류 이동하기', '분류를 통째로 이동합니다. !클릭 주의!');
}
}



2022년 5월 13일 (금) 15:30 판

function page(title) {
    this.title = "";
    this.SetTitle = function (title) { this.title = title; };
    this.Moveto = function (to, reason) {
        new mw.Api().postWithToken('csrf', {
            "action": "move",
            "format": "json",
            "formatversion": "latest",
            "utf8": 1,
            "from": this.title,
            "to": to,
            "reason": "시리즈 이전",
            "movetalk": 1,
            "noredirect": 1,
            "movesubpages": 1
        }).done(data => {
            mw.notify('이동 완료!');
            location.href = mw.config.values.wgServer + "/wiki/" + to;
        }).fail(data => {
            mw.notify('이동 실패');
            console.log(data);
        });
    };
}

if (mw.config.get('wgCanonicalNamespace') == 'Category') {
	newDropdownItemTest = new newDropdownItem(document.querySelector('.content-tools .dropdown-item:last-child'));
	newDropdownItemTest.AddItem(function () {
        mw.loader.load('/index.php?title=사용자:하늘/moveCategory.js&action=raw&ctype=text/javascript');
	}, '분류 이동하기', '분류를 통째로 이동합니다. !클릭 주의!');
}

if (mw.config.get('wgCanonicalNamespace') == 'User' && mw.config.get('wgPageContentModel') == 'wikitext') {
    newDropdownItemTest = new newDropdownItem(document.querySelector('.content-tools .dropdown-item:last-child'));

    newDropdownItemTest.AddItem(function () {
        wgPageName = mw.config.get('wgPageName');
        mw.notification.autoHideSeconds = { 'short': 2 };
        const to = '시리즈:리브레 한자사전/' + wgPageName.split('/').pop(); //시리즈:리브레 한자사전/櫻
        new mw.Api().postWithToken('csrf', {
            "action": "move",
            "format": "json",
            "formatversion": "latest",
            "utf8": 1,
            "from": wgPageName,
            "to": to,
            "reason": "시리즈 이전",
            "movetalk": 1,
            "noredirect": 1,
            "movesubpages": 1
        }).done(data => {
            mw.notify('이동 완료!');
            new mw.Api().postWithEditToken({
                "action": "edit", "format": "json", "contentmodel": "wikitext",
                "title": to.split('/').pop(), //櫻
                "text": "#넘겨주기 [[" + to + "]]",  // #넘겨주기[[시리즈:리브레 한자사전/櫻]]
            }).done(data => {
                console.log(data);
            }).fail(data => { console.log(data); });
            location.href = mw.config.values.wgServer + "/wiki/" + to;
        }).fail(data => {
            mw.notify('이동 실패');
            console.log(data);
        });
    }, '시리즈:한자사전으로 이동', '시리즈:리브레 한자사전으로 이동하기');

    newDropdownItemTest.AddItem(function () {
        wgPageName = mw.config.get('wgPageName');
        mw.notification.autoHideSeconds = { 'short': 2 };
        const to = wgPageName.split('/').pop(); //시리즈:리브레 한자사전/櫻
        page1 = new page();
        page1.title = wgPageName;
        page1.Moveto(to);

    }, '본문으로 이전', '사용자 문서를 본문으로 이동합니다.');
}