MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 705: Line 705:


$(document).ready(function() {
$(document).ready(function() {
     alert('Inline Script is running');
     // Get the page title
    var pageTitle = mw.config.get('wgTitle');


     var pageTitle = mw.config.get('wgTitle');
    // Encode the title and replace spaces with '%20'
     var encodedTitle = encodeURIComponent(pageTitle).replace(/%20/g, '%20'); // Correctly handle spaces


     var downloadButton = document.createElement('a');
    // Create the download button
    downloadButton.href = '/find_epub.php?title=' + encodeURIComponent(pageTitle);
     var downloadButton = $('<a>')
    downloadButton.innerText = 'Download EPUB';
        .attr('href', 'https://wiki.ekatrafoundation.org/images/epub/' + encodedTitle + '.epub')
    downloadButton.style.display = 'inline-block';
        .attr('download', '') // Suggests to download the file rather than opening it
    downloadButton.style.padding = '8px 16px';
        .text('Download EPUB')
    downloadButton.style.backgroundColor = '#4CAF50';
        .css({
    downloadButton.style.color = '#ffffff';
            'display': 'inline-block',
    downloadButton.style.textAlign = 'center';
            'padding': '8px 16px',
    downloadButton.style.borderRadius = '4px';
            'background-color': '#4CAF50',
    downloadButton.style.textDecoration = 'none';
            'color': '#ffffff',
    downloadButton.style.marginTop = '10px';
            'text-align': 'center',
    downloadButton.style.marginBottom = '10px';
            'border-radius': '4px',
            'text-decoration': 'none',
            'margin-top': '10px'
        });


     var contentArea = document.getElementById('mw-content-text');
     // Add the button to the page content
     if (contentArea) {
     $('#bodyContent').append(downloadButton);
        contentArea.insertBefore(downloadButton, contentArea.firstChild);
    } else {
        console.error('Content area not found.');
    }
});
});

Navigation menu