Difference between revisions of "User:Jacky720/common.js"

Explain xkcd: It's 'cause you're dumb.
Jump to: navigation, search
(let's try)
 
(I have normal rollback now and phonetic pronunciation is banned.)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
console.log("your JS loaded it didn't do anything");
 
/**
 
/**
 
  * Rollback
 
  * Rollback
Line 4: Line 5:
 
  * @author Ozank
 
  * @author Ozank
 
  */
 
  */
(function() {
+
/*(function() {
 
     'use strict';
 
     'use strict';
 
     // Exit if normal rollback links are present or the wiki disabled the script
 
     // Exit if normal rollback links are present or the wiki disabled the script
     if ($('.mw-rollback-link').length || window.RollbackWikiDisable) {
+
     if ($('.mw-rollback-link').length || window.RollbackWikiDisable || true) {
 
         return;
 
         return;
 
     }
 
     }
Line 16: Line 17:
 
             'wgPageName'
 
             'wgPageName'
 
         ]),
 
         ]),
 +
        user: 'Ex Kay Cee Dee',
 
         _preload: 1,
 
         _preload: 1,
        getPageType: function() {
 
            if (
 
                this.config.wgAction === 'history' &&
 
                $('#pagehistory li').length > 1
 
            ) {
 
                return 'history';
 
            } else if (
 
                this.config.wgCanonicalSpecialPageName === 'Contributions'
 
            ) {
 
                return 'contributions';
 
            } else if (
 
                mw.util.getParamValue('diff') &&
 
                $('#differences-nextlink').length === 0
 
            ) {
 
                return 'diff';
 
            }
 
        },
 
 
         preload: function() {
 
         preload: function() {
 
             if (--this._preload === 0) {
 
             if (--this._preload === 0) {
Line 43: Line 28:
 
             this.performRollbackCallback = this.performRollbackCallback
 
             this.performRollbackCallback = this.performRollbackCallback
 
                 .bind(this);
 
                 .bind(this);
             var type = this.getPageType();
+
             this.getTop().then(function(data) {
            if (type) {
+
                 const arr = data.query.usercontribs;
                 this[type]();
+
                console.log(arr);
            }
+
                if (arr.length > 100) {
            mw.hook('quickdiff.ready').add(this.quickDiff.bind(this));
+
                    const interval = setInterval(function() {
        },
+
                        const rev = arr.shift();
        getLink: function(page, user) {
+
                        if (!rev) {
            return $('<a>', {
+
                            clearInterval(interval);
                'click': this.click.bind(this),
+
                            window.location.reload();
                'data-id': page,
+
                            return;
                'data-user': user,
+
                        }
                'href': '#',
+
                        this.getRevisionIdAndContent(rev.title, rev.user);
                'text': 'rollback'
+
                        console.log(arr.length);
            });
+
                    }.bind(this), 50);
        },
+
                } else {
        history: function() {
+
                    const interval = setInterval(function() {
            $('#pagehistory li:first .mw-history-undo a').before(
+
                        const rev = arr.shift();
                $('<span>', {
+
                        if (!rev) {
                    'class': 'mw-custom-rollback-link'
+
                            clearInterval(interval);
                }).append(this.getLink(
+
                            //window.location.reload();
                    this.config.wgPageName,
+
                             return;
                    $('.mw-userlink:first').text()
+
                         }
                )),
+
                        this.getRevisionIdAndContent(rev.title, rev.user);
                ' | '
+
                        console.log(arr.length);
            );
+
                    }.bind(this), 50);
        },
 
        contributions: function() {
 
            $('#mw-content-text ul li').each(function(_, el) {
 
                // Fix context
 
                var $this = $(el);
 
                if ($this.find('.mw-uctop').length) {
 
                    $this.append(
 
                        ' ',
 
                        $('<span>', {
 
                             'class': 'mw-custom-rollback-link'
 
                         }).append(
 
                            '[',
 
                            this.getLink(
 
                                $this.find('a:first').attr('title'),
 
                                this.config.wgPageName.split('/')[1]
 
                            ),
 
                            ']'
 
                        )
 
                    );
 
 
                 }
 
                 }
 
             }.bind(this));
 
             }.bind(this));
 
         },
 
         },
         diff: function() {
+
         getTop: function() {
             $('.mw-usertoollinks:last').after(
+
             return this.api.get({
                 '&nbsp;&nbsp;&nbsp;&nbsp;',
+
                 action: 'query',
                $('<span>', {
+
                 list: 'usercontribs',
                    'class': 'mw-custom-rollback-link'
+
                 ucuser: this.user,
                }).append(
+
                 uctoponly: 1,
                    '[',
+
                 uclimit: 'max'
                    this.getLink(
+
             });
                        this.config.wgPageName,
 
                        $('#mw-diff-ntitle2 .mw-userlink').text()
 
                    ),
 
                    ']'
 
                 )
 
            );
 
        },
 
        quickDiff: function(modal) {
 
            // See getDiffTitle from QuickDiff.
 
            var prevTitle = modal.data.content
 
                .find('#mw-diff-otitle1 a')
 
                .attr('title'),
 
                 currTitle = modal.data.content
 
                .find('#mw-diff-ntitle1 a')
 
                .attr('title');
 
            if (prevTitle !== currTitle) {
 
                // This is a Special:ComparePages diff.
 
                return;
 
            }
 
            modal.$content.find('.mw-usertoollinks:last').after(
 
                '&nbsp;&nbsp;&nbsp;&nbsp;',
 
                 $('<span>', {
 
                    'class': 'mw-custom-rollback-link'
 
                }).append(
 
                    '[',
 
                    this.getLink(
 
                        currTitle,
 
                        modal.$content
 
                            .find('#mw-diff-ntitle2 .mw-userlink')
 
                            .text()
 
                    ),
 
                    ']'
 
                 )
 
            );
 
        },
 
        click: function(event) {
 
            event.preventDefault();
 
            if (this.confirm && !confirm('confirm pls')) {
 
                return;
 
             }
 
            var $this = $(event.target);
 
            this.getRevisionIdAndContent(
 
                $this.data('id'),
 
                $this.data('user').replace(/_/g, ' ')
 
            );
 
            $this.parent().remove();
 
 
         },
 
         },
 
         getRevisionIdAndContent: function(title, target) {
 
         getRevisionIdAndContent: function(title, target) {
Line 166: Line 86:
 
             // Don't rollback if the page has been edited by somebody else
 
             // Don't rollback if the page has been edited by somebody else
 
             if (target !== revisions[0].user) {
 
             if (target !== revisions[0].user) {
                 this.outputError('editConflict');
+
                 console.log('edit conflict');
 +
                // this.outputError('editConflict');
 
                 return;
 
                 return;
 
             }
 
             }
Line 223: Line 144:
 
                 this.outputError('editFail', data.error.code);
 
                 this.outputError('editFail', data.error.code);
 
             } else {
 
             } else {
                 mw.notify('Reverted successfully');
+
                 // mw.notify('Reverted successfully');
 
             }
 
             }
 
         },
 
         },
 
         outputError: function(message, code) {
 
         outputError: function(message, code) {
             mw.notify('error: ' + code, {
+
             mw.notify('error: ' + message + ' ' + code, {
 
                 type: 'error'
 
                 type: 'error'
 
             });
 
             });
Line 238: Line 159:
 
         'mediawiki.notification'
 
         'mediawiki.notification'
 
     ], Rollback.preload.bind(Rollback));
 
     ], Rollback.preload.bind(Rollback));
})();
+
})();*/
 +
//console.log("no of course it did something");

Latest revision as of 14:58, 24 May 2022

console.log("your JS loaded it didn't do anything");
/**
 * Rollback
 * @description Perform rollbacks without needing to be in the usergroup
 * @author Ozank
 */
/*(function() {
    'use strict';
    // Exit if normal rollback links are present or the wiki disabled the script
    if ($('.mw-rollback-link').length || window.RollbackWikiDisable || true) {
        return;
    }
    var Rollback = $.extend(window.Rollback, {
        config: mw.config.get([
            'wgAction',
            'wgCanonicalSpecialPageName',
            'wgPageName'
        ]),
        user: 'Ex Kay Cee Dee',
        _preload: 1,
        preload: function() {
            if (--this._preload === 0) {
                this.init();
            }
        },
        init: function() {
            this.api = new mw.Api();
            this.performRollbackCallback = this.performRollbackCallback
                .bind(this);
            this.getTop().then(function(data) {
                const arr = data.query.usercontribs;
                console.log(arr);
                if (arr.length > 100) {
                    const interval = setInterval(function() {
                        const rev = arr.shift();
                        if (!rev) {
                            clearInterval(interval);
                            window.location.reload();
                            return;
                        }
                        this.getRevisionIdAndContent(rev.title, rev.user);
                        console.log(arr.length);
                    }.bind(this), 50);
                } else {
                    const interval = setInterval(function() {
                        const rev = arr.shift();
                        if (!rev) {
                            clearInterval(interval);
                            //window.location.reload();
                            return;
                        }
                        this.getRevisionIdAndContent(rev.title, rev.user);
                        console.log(arr.length);
                    }.bind(this), 50);
                }
            }.bind(this));
        },
        getTop: function() {
            return this.api.get({
                action: 'query',
                list: 'usercontribs',
                ucuser: this.user,
                uctoponly: 1,
                uclimit: 'max'
            });
        },
        getRevisionIdAndContent: function(title, target) {
            this.api.get({
                action: 'query',
                cb: Date.now(),
                indexpageids: 1,
                prop: 'revisions',
                rvlimit: 'max',
                rvprop: 'user|ids',
                titles: title
            }).done(this.getRevisionIdCallback.bind(this, target)).fail(
                this.outputError.bind(this, 'revisionFail')
            );
        },
        getRevisionIdCallback: function(target, data) {
            if (data.error) {
                this.outputError('revisionFail', data.error.code);
                return;
            }
            var revisions = data.query.pages[data.query.pageids[0]].revisions;
            // Don't rollback if the page has been edited by somebody else
            if (target !== revisions[0].user) {
                console.log('edit conflict');
                // this.outputError('editConflict');
                return;
            }
            var lastUser, revId;
            for (var i in revisions) {
                if (revisions[i].user !== target) {
                    // Remember last author
                    lastUser = revisions[i].user;
                    // Get revision to revert to
                    revId = revisions[i].revid;
                    break;
                }
            }
            if (!lastUser) {
                this.outputError('singleEditor');
                return;
            }
            this.api.get({
                action: 'query',
                cb: Date.now(),
                indexpageids: 1,
                prop: 'revisions',
                revids: revId,
                rvprop: 'content'
            }).done(
                this.getRevisionContentCallback.bind(this, target, lastUser)
            ).fail(
                this.outputError.bind(this, 'contentFail', undefined)
            );
        },
        getRevisionContentCallback: function(target, lastUser, data) {
            if (data.error) {
                this.outputError('contentFail', data.error.code);
                return;
            }
            // Can be no content on page
            var page = data.query.pages[data.query.pageids[0]],
                content = page.revisions ? page.revisions[0]['*'] : '';
            this.performRollback(page.title, content, target, lastUser);
        },
        performRollback: function(page, text, user, user2) {
            this.api.post({
                action: 'edit',
                bot: true,
                minor: true,
                summary: 'rv',
                text: text,
                title: page,
                token: mw.user.tokens.get('editToken')
            }).done(this.performRollbackCallback).fail(
                this.outputError.bind(this, 'editFail')
            );
        },
        performRollbackCallback: function(data) {
            if (data.error) {
                this.outputError('editFail', data.error.code);
            } else {
                // mw.notify('Reverted successfully');
            }
        },
        outputError: function(message, code) {
            mw.notify('error: ' + message + ' ' + code, {
                type: 'error'
            });
        }
    });
    mw.loader.using([
        'mediawiki.api',
        'mediawiki.user',
        'mediawiki.util',
        'mediawiki.notification'
    ], Rollback.preload.bind(Rollback));
})();*/
//console.log("no of course it did something");