Bikarhêner:Balyozxane/skrîpt/js/open-random.js

Zanibe: Piştî weşandinê, ji bo dîtina guhartinan dibe ku hewce be "cache"ya geroka xwe paqij bikî.

  • Firefox / Safari: Pê li Shift û Reload bike an jî Ctrl-F5 an Ctrl-R bike (ji bo Mac: ⌘-R)
  • Google Chrome: Pê li Ctrl-Shift-R (ji bo Mac: ⌘-Shift-R) bike
  • Internet Explorer / Edge: Pê li Ctrl û Refresh bike, an jî Ctrl-F5 bike
  • Opera: Pê li Ctrl-F5 bike.
$(document).ready(function() {
    mw.loader.using(['jquery.ui'], function() {
        mw.util.addCSS('#t-openRandom { font-weight: normal; }');
		var targetContainer = mw.config.get('skin') === 'vector-2022' ? 'p-cactions' : 'p-tb';
        $(mw.util.addPortletLink(targetContainer, '#random', 'Open-random', 't-openRandom', 'Sort language codes in Werger')).click(init);
    });

    function init() {
        // API request to get a list of pages in the category
        $.getJSON('https://ku.wikipedia.org/w/api.php?action=query&list=categorymembers&cmtitle=Kategorî:Gotarên_bingehîn_ên_nehatine_sinifandin&cmlimit=max&format=json', function(data) {
            var pages = data.query.categorymembers;
            if (pages.length > 0) {
                // Randomly select a page from the list
                var randomPageIndex = Math.floor(Math.random() * pages.length);
                var randomPageTitle = pages[randomPageIndex].title;

                // Remove the "Gotûbêj:" prefix from the page title
                var pageName = randomPageTitle.replace('Gotûbêj:', '');

                // Construct the URL for the randomly selected page
                var randomPageUrl = 'https://ku.wikipedia.org/wiki/' + encodeURIComponent(pageName);

                // Redirect the user to the randomly selected page
                window.location.href = randomPageUrl;
            } else {
                console.error('No pages found in the category.');
            }
        });
    }
});