forked from AnYiEE/AwesomeGadgets
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
371 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* SPDX-License-Identifier: CC-BY-SA-4.0 | ||
* _addText: '{{Gadget Header|license=CC-BY-SA-4.0}}' | ||
* | ||
* @source {@link https://git.qiuwen.net.cn/InterfaceAdmin/QiuwenGadgets/src/branch/master/src/LoginToEdit} | ||
* @license CC-BY-SA-4.0 {@link https://www.qiuwenbaike.cn/wiki/H:CC-BY-SA-4.0} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {WG_USER_NAME} from './modules/constant'; | ||
import {getBody} from 'ext.gadget.Util'; | ||
import {initDialog} from './modules/initDialog'; | ||
|
||
void getBody().then(function loginToEdit($body: JQuery<HTMLBodyElement>): void { | ||
if (WG_USER_NAME) { | ||
return; | ||
} | ||
|
||
initDialog($body); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"enable": true, | ||
"description": "<sup><abbr title=\"默认为所有用户启用\">D</abbr></sup><span id=\"Gadget-LoginToEdit\"></span> 提示“登录以贡献”", | ||
"default": true, | ||
"dependencies": ["ext.gadget.i18n", "ext.gadget.Util", "mediawiki.util", "oojs-ui-windows"], | ||
"hidden": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const WG_ACTION: MediaWikiConfigMapWgAction = mw.config.get('wgAction'); | ||
const WG_PAGE_NAME: string = mw.config.get('wgPageName'); | ||
const WG_SKIN: string = mw.config.get('skin'); | ||
const WG_USER_NAME: string | null = mw.config.get('wgUserName'); | ||
|
||
const IS_WG_EDIT_OR_SUBMIT_ACTION: boolean = ['edit', 'submit'].includes(WG_ACTION); | ||
|
||
export {WG_PAGE_NAME, WG_SKIN, WG_USER_NAME, IS_WG_EDIT_OR_SUBMIT_ACTION}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import {localize} from 'ext.gadget.i18n'; | ||
|
||
const getI18nMessages = () => { | ||
return { | ||
Cancel: localize({ | ||
en: 'Cancel', | ||
ja: 'キャンセル', | ||
'zh-hans': '暂不登录账号', | ||
'zh-hant': '暫不登入賬號', | ||
}), | ||
Edit: localize({ | ||
en: 'Edit', | ||
ja: '編集', | ||
'zh-hans': '编辑', | ||
'zh-hant': '編輯', | ||
}), | ||
Login: localize({ | ||
en: 'Login', | ||
ja: 'ログイン', | ||
'zh-hans': '登录已有账号', | ||
'zh-hant': '登入已有賬號', | ||
}), | ||
Register: localize({ | ||
en: 'Register', | ||
ja: 'アカウントを作成', | ||
'zh-hans': '注册新的账号', | ||
'zh-hant': '註冊新的賬號', | ||
}), | ||
DialogTitle: localize({ | ||
en: 'Welcome to Youshou Archives!', | ||
ja: '有獣アーカイブスへようこそ!', | ||
'zh-hans': '欢迎来到有兽档案馆!', | ||
'zh-hant': '歡迎來到有獸檔案館!', | ||
}), | ||
DialogMessage: localize({ | ||
en: 'You have not yet logged in. Register and log in to your account to contribute.', | ||
ja: 'あなたはまだ有獣アーカイブスにログインしていません。アカウントを作成し、ログインして有獣アーカイブスを改善することができます。', | ||
'zh-hans': '您尚未登录到有兽档案馆。您可以注册并登录账号,帮助完善有兽档案馆。', | ||
'zh-hant': '您尚未登錄到有獸檔案館。您可以注冊並登錄賬戶,幫助完善有獸檔案館。', | ||
}), | ||
}; | ||
}; | ||
|
||
const i18nMessages = getI18nMessages(); | ||
|
||
const getMessage: GetMessages<typeof i18nMessages> = (key) => { | ||
return i18nMessages[key] || key; | ||
}; | ||
|
||
export {getMessage}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import * as OPTIONS from '~/AjaxLogin/options.json'; | ||
import {IS_WG_EDIT_OR_SUBMIT_ACTION, WG_PAGE_NAME, WG_SKIN} from './constant'; | ||
import {generateMessageDialogProperty} from './util/generateMessageDialogProperty'; | ||
import {getMessage} from './i18n'; | ||
import {initWindowManager} from './initWindowManager'; | ||
|
||
const isCitizen: boolean = WG_SKIN === 'citizen'; | ||
const loginURL: string = mw.util.getUrl('Special:UserLogin', { | ||
returnto: WG_PAGE_NAME, | ||
}); | ||
const registerURL: string = mw.util.getUrl('Special:CreateAccount', { | ||
returnto: WG_PAGE_NAME, | ||
}); | ||
|
||
let messageDialog: OO.ui.MessageDialog; | ||
|
||
const initDialog = ($body: JQuery<HTMLBodyElement>): void => { | ||
const windowManager: OO.ui.WindowManager = initWindowManager(); | ||
windowManager.$element.appendTo($body); | ||
|
||
const messageDialogProperty: OO.ui.WindowManager.WindowOpeningData = generateMessageDialogProperty(); | ||
|
||
const openDialog = (): void => { | ||
if (messageDialog) { | ||
if (messageDialog.isOpened()) { | ||
messageDialog.close(); | ||
} else { | ||
messageDialog.open(messageDialogProperty); | ||
} | ||
return; | ||
} | ||
|
||
messageDialog = new OO.ui.MessageDialog(); | ||
messageDialog.getActionProcess = (action: string): OO.ui.Process => { | ||
if (action === 'login') { | ||
const $element: JQuery<HTMLAnchorElement> = $(OPTIONS.loginElementSelector); | ||
if ($element.length) { | ||
$element.trigger('click'); | ||
} else { | ||
location.href = loginURL; | ||
} | ||
} else if (action === 'register') { | ||
location.href = registerURL; | ||
} | ||
return new OO.ui.Process((): void => { | ||
void windowManager.closeWindow(messageDialog); | ||
}); | ||
}; | ||
|
||
windowManager.addWindows([messageDialog]); | ||
void windowManager.openWindow(messageDialog, messageDialogProperty); | ||
}; | ||
|
||
const $caViewsource: JQuery = $body.find('#ca-viewsource'); | ||
if ($caViewsource.length) { | ||
const editIcon: string = isCitizen ? '<span class="citizen-ui-icon mw-ui-icon-wikimedia-edit"></span>' : ''; | ||
$caViewsource | ||
.attr('id', 'ca-edit') | ||
.find('a') | ||
.attr('aria-label', getMessage('DialogMessage')) | ||
.html(editIcon + getMessage('Edit')) | ||
.on('click', (event: JQuery.ClickEvent): void => { | ||
event.preventDefault(); | ||
openDialog(); | ||
}); | ||
} | ||
|
||
if (IS_WG_EDIT_OR_SUBMIT_ACTION) { | ||
openDialog(); | ||
} | ||
}; | ||
|
||
export {initDialog}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const initWindowManager = (): OO.ui.WindowManager => { | ||
const windowManager: OO.ui.WindowManager = new OO.ui.WindowManager(); | ||
|
||
return windowManager; | ||
}; | ||
|
||
export {initWindowManager}; |
32 changes: 32 additions & 0 deletions
32
src/LoginToEdit/modules/util/generateMessageDialogProperty.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {getMessage} from '../i18n'; | ||
|
||
const generateMessageDialogProperty = (): OO.ui.WindowManager.WindowOpeningData => { | ||
const $title: JQuery = $('<b>').addClass('oo-ui-window-head').text(getMessage('DialogTitle')); | ||
const $message: JQuery = $('<span>').addClass('oo-ui-window-foot').text(getMessage('DialogMessage')); | ||
|
||
const messageDialogProperty: OO.ui.WindowManager.WindowOpeningData = { | ||
title: $title, | ||
message: $message, | ||
actions: [ | ||
{ | ||
action: 'login', | ||
flags: ['primary', 'progressive'], | ||
label: $('<b>').text(getMessage('Login')), | ||
}, | ||
{ | ||
action: 'register', | ||
flags: 'progressive', | ||
label: $('<b>').text(getMessage('Register')), | ||
}, | ||
{ | ||
action: 'cancel', | ||
flags: ['safe', 'close'], | ||
label: $('<b>').text(getMessage('Cancel')), | ||
}, | ||
], | ||
}; | ||
|
||
return messageDialogProperty; | ||
}; | ||
|
||
export {generateMessageDialogProperty}; |