User:Doğu/Adiutor.js

/* * Adiutor: A gadget to assist various user actions * Author: Vikipolimer * Licencing and attribution: tr:VP:Adiutor * Module: Loader */ /* */ $.when(mw.loader.using(["mediawiki.user", "oojs-ui-core", "oojs-ui-widgets", "oojs-ui-windows", "oojs-ui.styles.icons-interactions", "oojs-ui.styles.icons-movement", "oojs-ui.styles.icons-content", "oojs-ui.styles.icons-moderation"]), $.ready).then(function {   var mwConfig = mw.config.get(["skin", "wgAction", "wgPageName", "wgNamespaceNumber", "wgTitle", "wgUserGroups", "wgUserName"]);    api = new mw.Api;    checkOptions('User:' + mwConfig.wgUserName + '/Adiutor-options.js').then(function(data) { if (data.query.pages["-1"]) { Options = JSON.stringify([{               "name": "csdSendMessageToCreator",                "value": false            }, {                "name": "csdLogNominatedPages",                "value": false            }, {                "name": "csdLogPageName",                "value": "CSD Log Adi"            }, {                "name": "afdSendMessageToCreator",                "value": false            }, {                "name": "afdLogNominatedPages",                "value": false            }, {                "name": "afdLogPageName",                "value": "AfD Log Adi"            }, {                "name": "prdSendMessageToCreator",                "value": false            }, {                "name": "prdLogNominatedPages",                "value": false            }, {                "name": "prdLogPageName",                "value": "Propose Deletion Log"            }, { "name": "afdNominateOpinionsLog", "value": false }, {               "name": "afdOpinionLogPageName", "value": "AfD Opinion Log" }, {               "name": "showMyStatus", "value": false }, {               "name": "MyStatus", "value": true }]);           var params = {                action: 'edit',                title: 'User:' + mwConfig.wgUserName + '/Adiutor-options.js',                appendtext: Options,                summary: 'Created setting file',                format: 'json'            };            api = new mw.Api;            api.postWithToken('csrf', params).done(function { //location.reload; });       } else {            var userSettingsParams = {                action: 'parse',                page: 'User:' + mwConfig.wgUserName + '/Adiutor-options.js',                prop: 'wikitext',                format: "json"            };            api.get(userSettingsParams).done(function(data) { var AdiutorOptions = JSON.parse([data.parse.wikitext['*']]); for (var i in AdiutorOptions) { localStorage.setItem((AdiutorOptions[i]).name, (AdiutorOptions[i]).value); }           });        }    });    var DefaultMenuItems = []; switch (mwConfig.wgNamespaceNumber) { case -1: case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 14: case 10: case 11: case 100: case 101: case 102: case 103: case 118: case 828: case 829: // LOAD MODULES if (mwConfig.wgNamespaceNumber === 3) { checkMentor; }           mw.loader.load('//en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:Vikipolimer/Adiutor-AFD-Helper.js'); /*           if (/(?:\?|&)(?:action|diff|oldid)=/.test(window.location.href)) { DefaultMenuItems.push(new OO.ui.MenuOptionWidget({ icon: 'cancel', data: 'rdr', label: 'RVDL Request', classes: ['adiutor-top-rrd-menu'], }));           }            if (mwConfig.wgPageName.includes('Special:Contributions') || mwConfig.wgNamespaceNumber === 2 || mwConfig.wgNamespaceNumber === 3 && !mwConfig.wgPageName.includes(mwConfig.wgUserName)) { DefaultMenuItems.push(new OO.ui.MenuOptionWidget({ icon: 'cancel', data: 'report', label: 'Report User', }),                   new OO.ui.MenuOptionWidget({ icon: 'stopHand', data: 'warn', label: 'Warn User', }), new OO.ui.MenuOptionWidget({ icon: 'speechBubbleAdd', data: 'welcome', label: 'Welcome User', classes: ['adiutor-top-user-menu'], })               );            } */            if (!mwConfig.wgPageName.includes('Özel:Katkılar')) { DefaultMenuItems.push(new OO.ui.MenuOptionWidget({ icon: 'add', data: 1, label: 'Create Speedy Deletion', }),                   new OO.ui.MenuOptionWidget({ icon: 'add', data: 2, label: 'Propose deletion', }),                   /*new OO.ui.MenuOptionWidget({ icon: 'add', data: 3, label: 'Article for Deletion', }),                   new OO.ui.MenuOptionWidget({ icon: 'arrowNext', data: 'pmr', label: 'Request Move', }),*/                   new OO.ui.MenuOptionWidget({ icon: 'lock', data: 'rpp', label: 'Request Protection', }),                   new OO.ui.MenuOptionWidget({ icon: 'history', data: 4, label: 'Recent Diff', }),                   new OO.ui.MenuOptionWidget({ icon: 'checkAll', data: 5, label: 'Copyvio Detector', }),                   new OO.ui.MenuOptionWidget({ icon: 'settings', data: 6, label: 'Adiutor Settings', classes: ['adiutor-top-settings-menu'], }));           }            var adiutorMenu = new OO.ui.ButtonMenuSelectWidget({                icon: 'ellipsis',                label: 'Adi',                invisibleLabel: true,                framed: false,                title: 'More options',                align: 'force-right',                classes: ['adiutor-top-selector', 'mw-indicator'],                menu: {                    horizontalPosition: 'end',                    items: DefaultMenuItems,                    classes: ['adiutor-top-menu'],                }            }); adiutorMenu.getMenu.on('choose', function(menuOption) {               switch (menuOption.getData) {                    case 1:                        mw.loader.load('//en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:Vikipolimer/Adiutor-CSD.js');                        break;                    case 2:                        mw.loader.load('//en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:Vikipolimer/Adiutor-PRD.js');                        break;                    case 3:                        mw.loader.load('//en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:Vikipolimer/Adiutor-AFD.js');                        break;                    case 4:                        window.location = '/w/index.php?title=' + mwConfig.wgPageName + "&diff=cur&oldid=prev&diffmode=source";                        break; case 5: mw.loader.load('//en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:Vikipolimer/Adiutor-COV.js'); break; case 6: mw.loader.load('//en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:Vikipolimer/Adiutor-OPT.js'); break; case 'report': mw.loader.load('//en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:Vikipolimer/Adiutor-AIV.js'); break; case 'warn': OO.ui.alert('Coming soon :)').done(function {});                       break;                    case 'welcome':                        OO.ui.alert('Coming soon :)').done(function {}); break; case 'rdr': mw.loader.load('//en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:Vikipolimer/Adiutor-RDR.js'); break; case 'pmr': mw.loader.load('//en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:Vikipolimer/Adiutor-PMR.js'); break; case 'rpp': mw.loader.load('//en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:Vikipolimer/Adiutor-RPP.js'); break; }           });            switch (mwConfig.skin) {                case 'vector':						$('.mw-portlet-cactions').parent.append(adiutorMenu.$element);						break;					case 'vector-2022':						$('.vector-collapsible').append(adiutorMenu.$element);						break;					case 'monobook':						$('.mw-indicators').append(adiutorMenu.$element);						break;					case 'timeless':						$('.mw-portlet-body').append(adiutorMenu.$element);						break;					case 'minerva':						$('.page-actions-menu__list').append(adiutorMenu.$element);						break;            }            break;    }

function checkOptions(title) { return api.get({           action: 'query',            prop: 'revisions',            rvlimit: 1,            rvprop: ['user'],            rvdir: 'newer',            titles: title,        }); }   switch (mwConfig.wgNamespaceNumber) { case 2: case 3: var CurrentUserPage = mwConfig.wgPageName.replace(/User(\s|\_)mesaj\s*?\:\s*?(.*)/gi, "User:$2"); checkOptions(CurrentUserPage + '/Adiutor-options.js').then(function(data) {               if (data.query.pages["-1"]) {                    //                } else {                    var XUserParams = {                        action: 'parse',                        page: CurrentUserPage + '/Adiutor-options.js',                        prop: 'wikitext',                        format: "json"                    };                    api.get(XUserParams).done(function(data) { var AdiutorOptions = JSON.parse([data.parse.wikitext['*']]); var ShowStatus; var UserStatus; $.each(AdiutorOptions, function {                           if (this.name == "showMyStatus") {                                ShowStatus = this.value;                            }                        }); $.each(AdiutorOptions, function {                           if (this.name == "MyStatus") {                                UserStatus = this.value;                            }                        }); if (ShowStatus) { switch (UserStatus) { case "active": buttonSelect = new OO.ui.ButtonOptionWidget({                                       framed: false,                                        label: 'Active',                                        data: 'active',                                        classes: ['adiutor-user-status-active'],                                    }); $('.mw-first-heading').append(buttonSelect.$element); break; case "passive": buttonSelect = new OO.ui.ButtonOptionWidget({                                       framed: false,                                        label: 'Passive',                                        data: 'passive',                                        classes: ['adiutor-user-status-passive'],                                    }); $('.mw-first-heading').append(buttonSelect.$element); break; case "away": buttonSelect = new OO.ui.ButtonOptionWidget({                                       framed: false,                                        label: 'Away',                                        data: 'away',                                        classes: ['adiutor-user-status-away'],                                    }); $('.mw-first-heading').append(buttonSelect.$element); break; }                           var checkLoggedUserPage = mwConfig.wgPageName.includes(mwConfig.wgUserName); if (checkLoggedUserPage) { buttonSelect.on('click', (function { buttonSelect.$element.hide; var dropdown = new OO.ui.DropdownWidget({                                       menu: {                                            items: [                                                new OO.ui.MenuOptionWidget({ data: 'active', label: 'Active' }),                                               new OO.ui.MenuOptionWidget({ data: 'passive', label: 'Passive' }),                                               new OO.ui.MenuOptionWidget({ data: 'away', label: 'Away' })                                           ],                                        },                                        label: 'Status',                                        classes: ['adiutor-user-status-selector']                                    }); $('.mw-first-heading').append(dropdown.$element); dropdown.getMenu.on('choose', function(menuOption) {                                       changeUserStatus(menuOption.getData);                                    }); }));                           }                        }                    });                }            });            break; }

function changeUserStatus(status) { api.get({           action: 'parse',            page: 'User:' + mwConfig.wgUserName + '/Adiutor-options.js',            prop: 'wikitext',            format: "json"        }).done(function(data) {            var AdiutorOptions = JSON.parse([data.parse.wikitext['*']]);            $.each(AdiutorOptions, function { if (this.name == "MyStatus") { this.value = status; }           });            console.log(AdiutorOptions);            api.postWithToken('csrf', { action: 'edit', title: 'User:' + mwConfig.wgUserName + '/Adiutor-options.js', text: JSON.stringify(AdiutorOptions), summary: 'Updated Adiutor settings.', format: 'json' }).done(function { location.reload; });       });    }

function checkMentor { api.get({           action: 'parse',            page: "Wikipedia:Growth Team features/Mentor list",            prop: 'wikitext',            format: "json"        }).done(function(data) {            if (data.parse.wikitext['*'].includes('User:' + mwConfig.wgUserName) && mwConfig.wgPageName.includes(mwConfig.wgUserName)) {                mw.loader.load('//en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:Vikipolimer/Adiutor-CMR.js');            }        }); } }); /* */