MediaWiki:Common.js: Difference between revisions

From greek.doctor
No edit summary
No edit summary
 
Line 2: Line 2:


var currentPageTitle = $("h1").text();
var currentPageTitle = $("h1").text();
var currentPageNumber = parseInt(currentPageTitle);
var currentPageID = [];
var parentCategory = [];
var parentCategory = [];
var myTitles = [];
var parentCategorySubpages = [];


/* Gets a JSON containing the category of the current page */
/* TODO:
jQuery.getJSON(
- Find the index (currentPageCategoryIndex) of parentCategorySubpages whose pageid corresponds to currentPageID
mw.util.wikiScript( 'api' ),
- Create a variable (nextPagePageID) containing the pageID of currentPageCategoryIndex + 1 (and -1)
{
- Get the URL (nextPageURL) of nextPagePageID
'action': 'query',
- Create a hyperlink to nextPageURL at the bottom of the page
                'format': 'json',
                'prop': 'categories',
                'titles': currentPageTitle,
                'formatversion': '2'
},
)


*/
/* Receives the pageID of the current page */
$.ajax({
        url: mw.util.wikiScript( 'api' ),
        data:
            {
                'action': 'query',
                'format': 'json',
                'prop': 'pageprops',
                'titles': currentPageTitle,
                'formatversion': '2'
            },
        async: false,
        datatype: 'json',
        success: function (json) {
            currentPageID = json.query.pages[0].pageid;
        }
});
console.log("currentPageID is " + currentPageID);
/* Receives a variable "parentCategory" from JSON */
$.ajax({
        url: mw.util.wikiScript( 'api' ),
        data:
            {
                'action': 'query',
                'format': 'json',
                'prop': 'categories',
                'titles': currentPageTitle,
                'formatversion': '2'
            },
        async: false,
        datatype: 'json',
        success: function (json) {
            parentCategory = json.query.pages[0].categories[0].title;
        }
});
/* Gets a JSON containing the subpages of the category of the current page */
$.ajax({
        url: mw.util.wikiScript( 'api' ),
        data:
            {
                'action': 'query',
                'format': 'json',
                "list": "categorymembers",
                "cmtitle": parentCategory,
                'formatversion': '2',
                "cmlimit": "max"
            },
        async: false,
        datatype: 'json',
        success: function (json) {
            parentCategorySubpages = json.query.categorymembers;
        }
});
console.log("currentPageNumber is " + currentPageNumber);
console.log("parentCategory is " + parentCategory);
console.log("parentCategorySubpages is " + parentCategorySubpages);


/* var numWords = $("#mw-content-text > div").text().split(" ").length;
/* var numWords = $("#mw-content-text > div").text().split(" ").length;

Latest revision as of 21:00, 21 December 2024

/* Any JavaScript here will be loaded for all users on every page load. */

var currentPageTitle = $("h1").text();
var currentPageNumber = parseInt(currentPageTitle);
var currentPageID = [];
var parentCategory = [];
var parentCategorySubpages = [];

/* TODO:
- Find the index (currentPageCategoryIndex) of parentCategorySubpages whose pageid corresponds to currentPageID
- Create a variable (nextPagePageID) containing the pageID of currentPageCategoryIndex + 1 (and -1)
- Get the URL (nextPageURL) of nextPagePageID
- Create a hyperlink to nextPageURL at the bottom of the page

*/

/* Receives the pageID of the current page */
$.ajax({
        url: mw.util.wikiScript( 'api' ),
        data:
            {
                'action': 'query',
                'format': 'json',
                'prop': 'pageprops',
                'titles': currentPageTitle,
                 'formatversion': '2'
            },
        async: false,
        datatype: 'json',
        success: function (json) {
            currentPageID = json.query.pages[0].pageid;
        }
});
console.log("currentPageID is " + currentPageID);

/* Receives a variable "parentCategory" from JSON */
$.ajax({
        url: mw.util.wikiScript( 'api' ),
        data:
            {
                'action': 'query',
                'format': 'json',
                'prop': 'categories',
                'titles': currentPageTitle,
                 'formatversion': '2'
            },
        async: false,
        datatype: 'json',
        success: function (json) {
            parentCategory = json.query.pages[0].categories[0].title;
        }
});

/* Gets a JSON containing the subpages of the category of the current page */
$.ajax({
        url: mw.util.wikiScript( 'api' ),
        data:
            {
                'action': 'query',
                'format': 'json',
                "list": "categorymembers",
                "cmtitle": parentCategory,
                'formatversion': '2',
                "cmlimit": "max"
            },
        async: false,
        datatype: 'json',
        success: function (json) {
            parentCategorySubpages = json.query.categorymembers;
        }
});

console.log("currentPageNumber is " + currentPageNumber);
console.log("parentCategory is " + parentCategory);
console.log("parentCategorySubpages is " + parentCategorySubpages);

/* var numWords = $("#mw-content-text > div").text().split(" ").length;
var headerWords = $("h1").text().split(" ").length;
var totalWords = numWords + headerWords;
var timeInMinutes = totalWords / 200;
var header = $("h1").text();
text(header + " (it will take you " + timeInMinutes + " minutes to read this page)");
*/