MediaWiki:Common.js: Difference between revisions

From PBARC
No edit summary
No edit summary
 
(20 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
document.querySelector("li#footer-info-lastmod").innerHTML += ' Article text is licensed under <a href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-ShareAlike 4.0 International</a>, unless otherwise noted. Contributors have agreed that a link to the article is sufficient attribution. This license does not automatically apply to any pictures or other files that may be used or linked to in the page. Click a picture to check for licensing information. If no license is given, the image may not be reused without explicit permission from the copyright holder except under <a href="https://en.wikipedia.org/wiki/Fair_use">fair use</a>.'
document.querySelectorAll('audio').forEach(
  function(e){
    e.controls = 'controls';
    delete e.disabled;
  }
);


document.querySelectorAll('.mw-tmh-play').forEach(
// Wikipedia citation tool
  function(e){
const textbox = document.querySelector("#wpTextbox1")
    e.style.display = 'none';
  }
);


if (textbox) {
    const summaryBox = document.querySelector(
        "#wpSummaryLabel > div:nth-child(1)"
    )


let buttonsAdded = false;
    const label = summaryBox.querySelector("label")
    label.setAttribute("for", "citations")
    label.textContent =
        'If you quoted a Wikipedia article, paste its Web address (starting with "https://en.wikipedia.org/") here, then click "Add citation." Do this for each article quoted. This is not necessary if the article is already cited in this page.'
 
    const input = summaryBox.querySelector("input")
    input.id = "citations"
    input.setAttribute("name", "citations")
    input.setAttribute("title", "Enter URLs to Wikipedia articles")
 
    const button = document.createElement("button")
    button.classList = ["oo-ui-inputWidget-input", "oo-ui-buttonElement-button"]
    button.style.marginBottom = "1em"
    button.textContent = "Add citation"
    summaryBox.appendChild(button)
 
    button.addEventListener("click", function (e) {
        e.preventDefault()
 
        const url = input.value
 
        const regex = /\/wiki\/(.+)/ // Regex pattern to extract the title
        const match = url.match(regex) // Perform matching
 
        if (url.search("en.wikipedia.org") != -1 && match && match.length > 1) {
            const title = decodeURIComponent(match[1]).replace(/_/g, " ")
            const citation = "{{Wikipedia|" + title + "}}"
            if (textbox.value.search(citation) == -1) {
                textbox.value = textbox.value.trim() + "\n\n" + citation
                input.value = ""
            }
        } else {
            alert("That URL does not seem to be a Wikipedia article.")
        }
    })
}
// End Wikipedia citation tool
 
 
if (
    document.querySelector("#p-personal-label").textContent == "Not logged in"
) {
    document.querySelectorAll("a.new, .new a").forEach(function (redlink) {
        var span = document.createElement("span")
        span.textContent = redlink.textContent
        redlink.replaceWith(span)
    })
}
 
// MobileEcho
var buttonsAdded = false


function echoLoading() {
function echoLoading() {
document.body.classList.add('mobileecho-hide-overflow');
    document.body.classList.add("mobileecho-hide-overflow")


if (! buttonsAdded) {
    if (!buttonsAdded) {
setTimeout(
        setTimeout(function () {
function() {
            var closeButton = document.createElement("button")
let closeButton = document.createElement('button');
            closeButton.setAttribute(
closeButton.setAttribute('class', "mobileecho-close-button oo-ui-widget oo-ui-widget-enabled oo-ui-iconElement oo-ui-iconElement-icon oo-ui-icon-close oo-ui-labelElement-invisible oo-ui-iconWidget");
                "class",
                "mobileecho-close-button oo-ui-widget oo-ui-widget-enabled oo-ui-iconElement oo-ui-iconElement-icon oo-ui-icon-close oo-ui-labelElement-invisible oo-ui-iconWidget"
            )


let headers = document.querySelectorAll('.oo-ui-popupWidget-head');
            var headers = document.querySelectorAll(".oo-ui-popupWidget-head")
let header;
            console.log(headers)
            var header


for (header in headers) {
            for (header in headers) {
let newCloseButton = closeButton.cloneNode();
                var newCloseButton = closeButton.cloneNode()
newCloseButton.addEventListener(
                newCloseButton.addEventListener("click", function () {
'click',
                    document.body.click()
function() {
                })
document.body.click();
                headers[header].appendChild(newCloseButton)
}
            }
);
        }, 500)
headers[header].appendChild(newCloseButton);
        buttonsAdded = true
}
    }
},
500
);
buttonsAdded = true;
}


setTimeout(
    setTimeout(function () {
function() {
        document
document.querySelector('a.oo-ui-icon-bell').addEventListener(
            .querySelector("a.oo-ui-icon-bell")
'click', echoLoading
            .addEventListener("click", echoLoading)
);


document.querySelector('a.oo-ui-icon-tray').addEventListener(
        document
'click', echoLoading
            .querySelector("a.oo-ui-icon-tray")
);
            .addEventListener("click", echoLoading)
},
    }, 500)
500
);
}
}


document.body.addEventListener(
document.body.addEventListener("click", function (e) {
'click',
    if (
function(e) {
        !document.querySelector(".mw-echo-ui-overlay").contains(e.target) &&
if (! document.querySelector('.mw-echo-ui-overlay').contains(e.target) && ! document.querySelector('#personal-extra').contains(e.target)) {
        !document.querySelector("#personal-extra").contains(e.target)
document.body.classList.remove('mobileecho-hide-overflow');
    ) {
}
        document.body.classList.remove("mobileecho-hide-overflow")
}
    }
);
})


document.querySelector('a.oo-ui-icon-bell').addEventListener(
document
'click', echoLoading
    .querySelector("a.oo-ui-icon-bell")
);
    .addEventListener("click", echoLoading)


document.querySelector('a.oo-ui-icon-tray').addEventListener(
document
'click', echoLoading
    .querySelector("a.oo-ui-icon-tray")
);
    .addEventListener("click", echoLoading)


// END MobileEcho JS
// End MobileEcho

Latest revision as of 17:13, 15 May 2024

document.querySelector("li#footer-info-lastmod").innerHTML += ' Article text is licensed under <a href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-ShareAlike 4.0 International</a>, unless otherwise noted. Contributors have agreed that a link to the article is sufficient attribution. This license does not automatically apply to any pictures or other files that may be used or linked to in the page. Click a picture to check for licensing information. If no license is given, the image may not be reused without explicit permission from the copyright holder except under <a href="https://en.wikipedia.org/wiki/Fair_use">fair use</a>.'

// Wikipedia citation tool
const textbox = document.querySelector("#wpTextbox1")

if (textbox) {
    const summaryBox = document.querySelector(
        "#wpSummaryLabel > div:nth-child(1)"
    )

    const label = summaryBox.querySelector("label")
    label.setAttribute("for", "citations")
    label.textContent =
        'If you quoted a Wikipedia article, paste its Web address (starting with "https://en.wikipedia.org/") here, then click "Add citation." Do this for each article quoted. This is not necessary if the article is already cited in this page.'

    const input = summaryBox.querySelector("input")
    input.id = "citations"
    input.setAttribute("name", "citations")
    input.setAttribute("title", "Enter URLs to Wikipedia articles")

    const button = document.createElement("button")
    button.classList = ["oo-ui-inputWidget-input", "oo-ui-buttonElement-button"]
    button.style.marginBottom = "1em"
    button.textContent = "Add citation"
    summaryBox.appendChild(button)

    button.addEventListener("click", function (e) {
        e.preventDefault()

        const url = input.value

        const regex = /\/wiki\/(.+)/ // Regex pattern to extract the title
        const match = url.match(regex) // Perform matching

        if (url.search("en.wikipedia.org") != -1 && match && match.length > 1) {
            const title = decodeURIComponent(match[1]).replace(/_/g, " ")
            const citation = "{{Wikipedia|" + title + "}}"
            if (textbox.value.search(citation) == -1) {
                textbox.value = textbox.value.trim() + "\n\n" + citation
                input.value = ""
            }
        } else {
            alert("That URL does not seem to be a Wikipedia article.")
        }
    })
}
// End Wikipedia citation tool


if (
    document.querySelector("#p-personal-label").textContent == "Not logged in"
) {
    document.querySelectorAll("a.new, .new a").forEach(function (redlink) {
        var span = document.createElement("span")
        span.textContent = redlink.textContent
        redlink.replaceWith(span)
    })
}

// MobileEcho
var buttonsAdded = false

function echoLoading() {
    document.body.classList.add("mobileecho-hide-overflow")

    if (!buttonsAdded) {
        setTimeout(function () {
            var closeButton = document.createElement("button")
            closeButton.setAttribute(
                "class",
                "mobileecho-close-button oo-ui-widget oo-ui-widget-enabled oo-ui-iconElement oo-ui-iconElement-icon oo-ui-icon-close oo-ui-labelElement-invisible oo-ui-iconWidget"
            )

            var headers = document.querySelectorAll(".oo-ui-popupWidget-head")
            console.log(headers)
            var header

            for (header in headers) {
                var newCloseButton = closeButton.cloneNode()
                newCloseButton.addEventListener("click", function () {
                    document.body.click()
                })
                headers[header].appendChild(newCloseButton)
            }
        }, 500)
        buttonsAdded = true
    }

    setTimeout(function () {
        document
            .querySelector("a.oo-ui-icon-bell")
            .addEventListener("click", echoLoading)

        document
            .querySelector("a.oo-ui-icon-tray")
            .addEventListener("click", echoLoading)
    }, 500)
}

document.body.addEventListener("click", function (e) {
    if (
        !document.querySelector(".mw-echo-ui-overlay").contains(e.target) &&
        !document.querySelector("#personal-extra").contains(e.target)
    ) {
        document.body.classList.remove("mobileecho-hide-overflow")
    }
})

document
    .querySelector("a.oo-ui-icon-bell")
    .addEventListener("click", echoLoading)

document
    .querySelector("a.oo-ui-icon-tray")
    .addEventListener("click", echoLoading)

// End MobileEcho