MediaWiki:Common.js: Difference between revisions
From PBARC
No edit summary |
No edit summary |
||
| Line 45: | Line 45: | ||
// End Wikipedia citation tool | // End Wikipedia citation tool | ||
if ( | if ( | ||
| Line 91: | Line 55: | ||
}) | }) | ||
} | } | ||
// MobileEcho | // MobileEcho | ||
Revision as of 15:59, 26 August 2023
// 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