|
|
(사용자 2명의 중간 판 13개는 보이지 않습니다) |
1번째 줄: |
1번째 줄: |
| var api = new mw.Api();
| | /* #REDIRECT */mw.loader.load( "https://libertyga.me/index.php?title=%EC%82%AC%EC%9A%A9%EC%9E%90:Hsl0/%EC%97%B0%EA%B5%AC%EC%86%8C/2.js&action=raw" ); |
| var gadgetsList = Object.keys(mw.loader.moduleRegistry).reduce(function(arr, key) {
| |
| if(key.startsWith('ext.gadget.')) arr.push(key.slice(11));
| |
| return arr;
| |
| }, []);
| |
| var needed = [];
| |
| var ignored = mw.user.options.get('userjs-gadgethelper-ignored');
| |
| ignored = ignored? ignored.split('|') : [];
| |
| var allowed = getAllowedGadgets();
| |
| var ignoredChanged = 0;
| |
| | |
| function getAllowedGadgets() {
| |
| var allowed = [];
| |
| var options = mw.user.options.values;
| |
| | |
| for(var key in options) {
| |
| if(key.startsWith('gadget-') && +options[key]) allowed.push(key.slice(7));
| |
| }
| |
| | |
| return allowed;
| |
| }
| |
| | |
| function getSelected(form) {
| |
| return $(form).find('input[type=checkbox]:checked').map(function() {
| |
| return this.name;
| |
| }).get();
| |
| }
| |
| | |
| function getUnselected(form) {
| |
| return $(form).find('input[type=checkbox]:not(:checked)').map(function() {
| |
| return this.name;
| |
| }).get();
| |
| }
| |
| | |
| | |
| $('.gadgethelper').each(function() {
| |
| needed = needed.concat(this.dataset.using.split(' '));
| |
| });
| |
| | |
| needed = needed.filter(function(gadget) {
| |
| return gadgetsList.includes(gadget) && !allowed.includes(gadget);
| |
| });
| |
| | |
| function SelectDialog(config) {
| |
| SelectDialog.super.call(this, config);
| |
| }
| |
| OO.inheritClass(SelectDialog, OO.ui.ProcessDialog);
| |
| | |
| SelectDialog.static.name = 'GadgetSelectDialog';
| |
| SelectDialog.static.title = '소도구 선택';
| |
| SelectDialog.static.actions = [
| |
| {
| |
| modes: 'wait',
| |
| label: '실행',
| |
| flags: ['primary', 'progressive'],
| |
| disabled: true
| |
| },
| |
| {
| |
| modes: 'default',
| |
| action: 'execute',
| |
| label: '실행',
| |
| flags: ['primary', 'progressive']
| |
| },
| |
| {
| |
| modes: 'ignored',
| |
| action: 'clear',
| |
| label: '해제',
| |
| flags: ['primary', 'progressive']
| |
| },
| |
| {
| |
| modes: 'default',
| |
| action: 'close',
| |
| label: '닫기',
| |
| flags: 'safe'
| |
| },
| |
| {
| |
| modes: 'ignored',
| |
| action: 'cancel',
| |
| label: '취소',
| |
| flags: 'safe'
| |
| },
| |
| {
| |
| modes: 'default',
| |
| action: 'go-ignored',
| |
| label: '무시된 소도구 보기'
| |
| },
| |
| | |
| ];
| |
| if(!mw.user.isAnon()) SelectDialog.static.actions.push({
| |
| modes: 'default',
| |
| action: 'go-allowed',
| |
| label: '항상 허용된 소도구 관리'
| |
| });
| |
| | |
| SelectDialog.prototype.initialize = function() {
| |
| SelectDialog.super.prototype.initialize.apply(this, arguments);
| |
| | |
| var defaultMessage = $('<p>이 문서를 정상적으로 작동하려면 다음 소도구가 필요합니다. 실행할 소도구를 선택해 주세요.</p>');
| |
| this.defaultForm = new OO.ui.FormLayout();
| |
| this.defaultPanel = new OO.ui.PanelLayout({
| |
| padded: true,
| |
| content: [defaultMessage, this.defaultForm]
| |
| });
| |
| | |
| this.wait = new OO.ui.PanelLayout({
| |
| padded: true
| |
| });
| |
| this.wait.$element.append('<p>소도구 정보를 불러오고 있습니다... 잠시만 기다려 주세요.</p>');
| |
| | |
| var ignoredMessage = $('<p>무시한 소도구의 목록입니다. 해제할 소도구를 선택해 주세요.</p>');
| |
| this.ignoredForm = new OO.ui.FormLayout();
| |
| this.ignoredPanel = new OO.ui.PanelLayout({
| |
| padded: true,
| |
| content: [ignoredMessage, this.ignoredForm]
| |
| });
| |
| | |
| this.stackLayout = new OO.ui.StackLayout({
| |
| items: [this.wait, this.defaultPanel, this.ignoredPanel]
| |
| })
| |
| | |
| this.$body.append(this.stackLayout.$element);
| |
| };
| |
| | |
| SelectDialog.prototype.createDefaultForm = function() {
| |
| var form = this.defaultForm;
| |
| | |
| this.defaultForm.clearItems();
| |
| | |
| var all = new OO.ui.CheckboxInputWidget({
| |
| selected: true
| |
| });
| |
| all.on('change', function(checked) {
| |
| form.$element.find('input[type=checkbox]:not(:disabled)').prop('checked', checked);
| |
| });
| |
| | |
| var input = new OO.ui.CheckboxMultiselectWidget({
| |
| items: needed.filter(function(gadget) {
| |
| return !ignored.includes(gadget);
| |
| }).map(function(gadget) {
| |
| var ignore = new OO.ui.ButtonWidget({
| |
| label: '무시',
| |
| flags: 'destructive',
| |
| framed: false
| |
| });
| |
| ignore.on('click', function() {
| |
| ignore.clearFlags();
| |
| if(ignore.data) {
| |
| var index = ignored.indexOf(gadget);
| |
| if(index > -1) ignored.splice(index, 1);
| |
| ignore.setData(false);
| |
| if(index > 0) ignoredChanged--;
| |
| | |
| ignore.setLabel('무시');
| |
| ignore.setFlags('destructive');
| |
| } else {
| |
| ignoredChanged++;
| |
| ignored.push(gadget);
| |
| ignore.setData(true);
| |
| | |
| ignore.setLabel('무시 해제');
| |
| ignore.setFlags('progressive');
| |
| }
| |
| });
| |
| | |
| return new OO.ui.HorizontalLayout({
| |
| items: [
| |
| new OO.ui.CheckboxMultioptionWidget({
| |
| data: gadget,
| |
| label: mw.msg('gadget-' + gadget),
| |
| selected: true
| |
| }),
| |
| ignore
| |
| ]
| |
| });
| |
| })
| |
| });
| |
| | |
| this.defaultForm.addItems([
| |
| new OO.ui.FieldLayout(all, {
| |
| label: '모두 선택',
| |
| align: 'inline'
| |
| }),
| |
| input
| |
| ]);
| |
| };
| |
| | |
| SelectDialog.prototype.getSetupProcess = function(data) {
| |
| var dialog = this;
| |
| | |
| this.actions.setMode('wait');
| |
| | |
| return SelectDialog.super.prototype.getSetupProcess.call(this, data)
| |
| .next(api.loadMessagesIfMissing(needed.map(function(key) {
| |
| return 'gadget-' + key;
| |
| })))
| |
| .next(function() {
| |
| dialog.createDefaultForm();
| |
| | |
| dialog.stackLayout.setItem(dialog.defaultPanel);
| |
| dialog.actions.setMode('default');
| |
| });
| |
| };
| |
| | |
| SelectDialog.prototype.getActionProcess = function(action) {
| |
| var process = SelectDialog.super.prototype.getActionProcess.call(this, action);
| |
| var dialog = this;
| |
| | |
| switch(action) {
| |
| case 'execute':
| |
| return process
| |
| .next(mw.loader.using(getSelected(this.defaultForm).map(function(gadget) {
| |
| return 'ext.gadget.' + gadget;
| |
| })))
| |
| .next(function() {
| |
| dialog.close();
| |
| });
| |
| break;
| |
| | |
| case 'clear':
| |
| ignored = getUnselected(this.ignoredForm);
| |
| return process
| |
| .next(api.saveOption('userjs-gadgethelper-ignored', ignored.join('|')))
| |
| .next(function() {
| |
| mw.user.options.set('userjs-gadgethelper-ignored', ignored.join('|'));
| |
| | |
| dialog.ignoredForm.clearItems();
| |
| dialog.createDefaultForm();
| |
| | |
| dialog.stackLayout.setItem(dialog.defaultPanel);
| |
| dialog.actions.setMode('default');
| |
| });
| |
| break;
| |
|
| |
| case 'close':
| |
| return process.next(function() {
| |
| dialog.close();
| |
| });
| |
| break;
| |
| | |
| case 'cancel':
| |
| return process.next(function() {
| |
| dialog.stackLayout.setItem(dialog.defaultPanel);
| |
| dialog.actions.setMode('default');
| |
| });
| |
| break;
| |
|
| |
| case 'go-ignored':
| |
| return process
| |
| .next(function() {
| |
| dialog.stackLayout.setItem(dialog.wait);
| |
| dialog.actions.setMode('wait');
| |
| })
| |
| .next(api.loadMessagesIfMissing(ignored.map(function(key) {
| |
| return 'gadget-' + key;
| |
| })))
| |
| .next(function() {
| |
| if(!dialog.ignoredForm.items.length) {
| |
| var all = new OO.ui.CheckboxInputWidget();
| |
| all.on('change', function(checked) {
| |
| dialog.ignoredForm.$element.find('input[type=checkbox]').prop('checked', checked);
| |
| });
| |
| | |
| var input = new OO.ui.CheckboxMultiselectWidget({
| |
| items: ignored.map(function(gadget) {
| |
| return new OO.ui.CheckboxMultioptionWidget({
| |
| data: gadget,
| |
| label: mw.msg('gadget-' + gadget),
| |
| selected: true
| |
| });
| |
| })
| |
| });
| |
| dialog.ignoredForm.addItems([
| |
| new OO.ui.FieldLayout(all, {
| |
| label: '모두 선택',
| |
| align: 'inline'
| |
| }),
| |
| input
| |
| ]);
| |
| }
| |
| | |
| dialog.stackLayout.setItem(dialog.ignoredPanel);
| |
| dialog.actions.setMode('ignored');
| |
| });
| |
| break;
| |
| case 'go-allowed':
| |
| return process.next(function() {
| |
| open('/wiki/%ED%8A%B9%EC%88%98:%ED%99%98%EA%B2%BD%EC%84%A4%EC%A0%95#mw-prefsection-gadgets');
| |
| });
| |
| break;
| |
| }
| |
| | |
| return process.next(function() {
| |
| throw new TypeError('Wrong action called');
| |
| });
| |
| };
| |
| | |
| SelectDialog.prototype.getBodyHeight = function() {
| |
| return this.stackLayout.currentItem.$element.innerHeight(true);
| |
| };
| |
| | |
| var windowManager = new OO.ui.WindowManager();
| |
| windowManager.$element.appendTo(document.body);
| |
| | |
| var dialog = new SelectDialog({
| |
| size: 'large'
| |
| });
| |
| windowManager.addWindows([dialog]);
| |
| windowManager.openWindow(dialog);
| |