Jump to content

User:Coderreyansh/vector-2022.js

From Wikipedia, the free encyclopedia
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//<nowiki>
// 1. Add a Custom Tab for Wikification
mw.loader.using('mediawiki.util', function () {
    $(document).ready(function () {
        var link = mw.util.addPortletLink('p-cactions', '#', 'Wikify', 'ca-wikify', 'Mark for wikification');
        $(link).click(function (event) {
            event.preventDefault();
            doWikify();
        });
    });
});

function doWikify() {
    // Code to mark the article for wikification
    var text = "{{Wikify}}";
    var textarea = document.getElementById("wpTextbox1");
    textarea.value += text;
}

// 2. Automate Adding Categories
mw.hook('wikipage.content').add(function ($content) {
    if ($content.is('#mw-content-text')) {
        var category = "[[Category:New Pages]]";
        var textarea = document.getElementById("wpTextbox1");
        textarea.value += category;
    }
});

// 3. Enhance Search Functionality
$(document).ready(function () {
    var searchBox = $('<input id="customSearch" type="text" placeholder="Search Wikipedia">');
    searchBox.appendTo('#p-search');
    searchBox.autocomplete({
        source: function (request, response) {
            $.ajax({
                url: mw.util.wikiScript('api'),
                dataType: "json",
                data: {
                    action: 'opensearch',
                    search: request.term,
                    limit: 10,
                    format: 'json'
                },
                success: function (data) {
                    response(data);
                }
            });
        },
        select: function (event, ui) {
            window.location.href = ui.item.value;
        }
    });
});

// 4. Color Code User Contributions
$(document).ready(function () {
    var contributions = $('#mw-content-text ul');
    contributions.find('li').each(function () {
        var link = $(this).find('a');
        if (link.text().includes('edit')) {
            $(this).css('background-color', '#cff');
        } else if (link.text().includes('new')) {
            $(this).css('background-color', '#ffc');
        } else if (link.text().includes('move')) {
            $(this).css('background-color', '#fcc');
        }
    });
});

// 5. Add Quick Links to Toolbox
$(document).ready(function () {
    var toolbox = $('#p-tb');
    var link = $('<a href="#">Quick Link</a>').attr('title', 'Quick Link');
    link.appendTo(toolbox);
    link.click(function (event) {
        event.preventDefault();
        // Custom action for the link
        alert('Quick Link clicked!');
    });
});

// 6. Highlight Unsaved Changes
$(document).ready(function () {
    var originalText = document.getElementById("wpTextbox1").value;
    document.getElementById("wpTextbox1").oninput = function () {
        if (this.value !== originalText) {
            this.style.background = 'rgba(255, 255, 0, 0.2)';
        } else {
            this.style.background = '';
        }
    };
});

// 7. Automate Edit Summaries
$(document).ready(function () {
    var summary = document.getElementById("wpSummary");
    if (summary.value === '') {
        summary.value = 'Default edit summary';
    }
});

// 8. Display Page Metrics
$(document).ready(function () {
    $.getJSON(mw.util.wikiScript('api'), {
        action: 'query',
        titles: mw.config.get('wgPageName'),
        prop: 'revisions|pageviews',
        rvprop: 'ids',
        pvipdays: 30,
        format: 'json'
    }, function (data) {
        var pageId = Object.keys(data.query.pages);
        var edits = data.query.pages[pageId].revisions.length;
        var views = data.query.pages[pageId].pageviews;
        var metrics = $('<div>Edits: ' + edits + ', Views: ' + views + '</div>');
        metrics.appendTo('#bodyContent');
    });
});

// 9. Customize Watchlist
$(document).ready(function () {
    var watchlist = $('#watchlist');
    var button = $('<button>Remove from Watchlist</button>');
    button.appendTo(watchlist);
    button.click(function (event) {
        event.preventDefault();
        var pageName = mw.config.get('wgPageName');
        $.getJSON(mw.util.wikiScript('api'), {
            action: 'watch',
            title: pageName,
            unwatch: true,
            format: 'json'
        }, function (data) {
            if (data.watch.unwatch) {
                alert('Page removed from watchlist');
            }
        });
    });
});

// 10. Enhance Navigation
$(document).ready(function () {
    var navMenu = $('<ul id="customNav"></ul>');
    navMenu.appendTo('#p-navigation');
    var pages = ['Main_Page', 'Special:RecentChanges', 'Special:Watchlist'];
    pages.forEach(function (page) {
        var link = $('<a href="' + mw.util.wikiScript(page) + '">' + page.replace(/_/g, ' ') + '</a>');
        link.wrap('<li>').parent().appendTo(navMenu);
    });
});
//</nowiki>