MediaWiki討論:Gadget-mobileEdit.js

出自H萌娘
跳至導覽 跳至搜尋

創建請求[編輯原始碼]

請求創建小工具頁面,內容如下:

//<nowiki>
/**
 * @Source: https://llwiki.org/zh/mediawiki:gadget-mobileEdit.js
 * @Author: [[User:Bhsd]]
 * @License: CC BY-NC-SA 4.0
 * @Dependencies: ext.gadget.site-lib, mediawiki.util, oojs-ui-windows, user.options
 */
"use strict";
const script = mw.config.get( 'wgScript' ),
    pagename = mw.util.wikiUrlencode( mw.config.get( 'wgPageName' ) ),
    id = mw.config.get( 'wgRevisionId' ),
    action = mw.config.get( 'wgAction' );

$('body').on('click', 'a.new', function() {
    $(this).attr('href', function(i, val) { return val.replace('&action=edit', '&action=submit'); });
});

$(function() {
    if (action == 'view' || mw.config.get( 'wgNamespaceNumber') >= 0) {
        $( 'a.edit-page' ).filter(function() { return /^T-/.test( $(this).data('section') ); }).remove();
        $( 'a.edit-page' ).off( 'click' ).on('click', function(e) {
            e.stopImmediatePropagation();
            const section = $(this).data('section'),
                param = section ? '&section=' + section : '';
            location.href = script + '?action=submit&title=' + pagename + '&oldid=' + id + param;
        }).removeAttr('href');
    }

    if (["edit", "submit"].includes( action )) {
        const warning = mw.user.options.get( 'useeditwarning' ),
            id = mw.util.getParamValue( 'oldid' ),
            cid = mw.config.get( 'wgCurRevisionId' ),
            href = script + (id && id < cid ? '?oldid=' + id : '/' + pagename),
            cancelBtn = new OO.ui.ButtonWidget( {label: wgULS("取消编辑", "取消編輯"),
            flags: ['primary', 'destructive'], href: href} );
        cancelBtn.$element.appendTo( '.editButtons' );
        if (warning) {
            cancelBtn.$element.on('click', 'a', function(e) {
                e.preventDefault();
                OO.ui.confirm( wgULS("您要放弃这次更改吗?", "您要放棄這次更改嗎?"), {actions: [{label: "取消"},
                    {label: wgULS("确定", "確認"), flags: ['primary', 'destructive'], action: 'accept'}]} )
                    .then(function(confirm) {
                    if (confirm) { location.href = href; }
                });
            });
        }
    }
});
//</nowiki>

使用這個小工具需要在mediawiki:gadgets-definition添加

* mobileEdit[ResourceLoader|dependencies=ext.gadget.site-lib,mediawiki.util,oojs-ui-windows,user.options|rights=edit|targets=mobile]|mobileEdit.js

如果導入後不可用,請再與我聯繫。謝謝!Bhsd討論) 2021年5月7日 (五) 23:41 (CST)
@=海豚=請來看看-- PatrollerSD hehua聊天室) 2021年5月8日 (六) 18:40 (CST)回覆[回覆]

抱歉,因發現本站不遵循CC協議,以上代碼需在頂部註明使用CC BY-NC-SA 4.0協議。如果因版權協議衝突造成無法搬運,請求刪除此討論串或討論頁。Bhsd討論) 2021年5月8日 (六) 19:13 (CST)回覆[回覆]
完成 -- PatrollerSD hehua聊天室) 2021年5月8日 (六) 23:30 (CST)回覆[回覆]

編輯請求 - Bhsd[編輯原始碼]

第20行後添加

        $( '#ca-edit > a' ).off( 'click' ).on('click', function(e) {
            e.stopImmediatePropagation();
            location.href = '/index.php?action=submit&title=' + mw.util.wikiUrlencode( mw.config.get( 'wgPageName' ) ) + '&oldid=' + mw.config.get( 'wgRevisionId' );
        }).removeAttr('href');

Bhsd討論) 2021年5月8日 (六) 22:52 (CST)回覆[回覆]

完成 -- PatrollerSD hehua聊天室) 2021年5月8日 (六) 23:30 (CST)
回覆[回覆]

不知為何被清空-- PatrollerSD hehua聊天室) 2021年5月9日 (日) 09:48 (CST)回覆[回覆]

之前的修改失敗了……不過這次經我的個人JS測試能夠生效:請將第21-24行(也就是上次新增的內容)替換為
        const editBtn = $('#ca-edit')[0];
        if (editBtn) {
            editBtn.addEventListener('click', function(e) {
                e.stopPropagation();
                location.href = '/index.php?title=' + pagename + '&action=submit&oldid=' + id;
            }, true);
        }

@=海豚= 大佬自行調節一下縮進吧。Bhsd討論) 2021年5月9日 (日) 19:12 (CST)回覆[回覆]

編輯請求 - Bhsd[編輯原始碼]

請將頁面內容替換為

mw.loader.load('//cdn.jsdelivr.net/gh/bhsd-harry/[email protected]/otherwiki/gadget-mobileEdit.min.js');

Bhsd討論) 2021年6月15日 (二) 05:24 (CST)回覆[回覆]

@=海豚= 抱歉,漏了一個右半括號……Bhsd討論) 2021年6月16日 (三) 10:00 (CST)回覆[回覆]

編輯請求 - Bhsd[編輯原始碼]

@=海豚= 大佬上次說希望給取消按鈕加上邊框,那可以將頁面內容替換為

mw.loader.load('//cdn.jsdelivr.net/gh/bhsd-harry/[email protected]/otherwiki/gadget-mobileEdit.min.js');

Bhsd討論) 2021年6月21日 (一) 00:34 (CST)回覆[回覆]

完成 --<img src="https://www.hmoegirl.com/images/avatars/574894/128.png?ver=1598093246" style="width: 2.5em;border-radius: 50%;"/> =海豚=留言 · 貢獻 · 討論) 2021年6月21日 (一) 16:09 (CST)回覆[回覆]