MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
(Created page with "→Any JavaScript here will be loaded for all users on every page load.: // Any JavaScript here will be loaded for all // users on every page load. console.log('hello from common.js') // rename 'Discussion' tab or context menu button // to 'CSS' in the 'Publishing' namespace. const url = window.location.href, NS = 'Publishing', // content namespace cssNS = NS + 'CSS' // css namespace if (url.includes(NS + ':')) { console.log('thi...") |
No edit summary |
||
(16 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
// rename 'Discussion' tab or context menu button | // rename 'Discussion' tab or context menu button | ||
// to 'CSS' in the ' | // to 'CSS' in the 'Pdf' namespace. | ||
const | const | ||
url | url = window.location.href, | ||
NS | NS = 'Pdf', // content namespace | ||
cssNS | cssNS = NS + 'CSS', // css namespace | ||
pageName = mw.config.get("wgPageName").split(":")[1] | |||
if (url.includes(NS + ':')) { | if (url.includes(NS + ':')) { | ||
console.log('this page is in namespace', NS) | console.log('this page is in namespace', NS) | ||
// Change Discussion into CSS button | |||
const talkAnchor = document.querySelector('#ca-talk a') | const talkAnchor = document.querySelector('#ca-talk a') | ||
const talkLink = talkAnchor.href | const talkLink = talkAnchor.href | ||
talkAnchor.innerText = 'CSS!' | |||
const talkButton = document.querySelector('#ca-talk') | |||
talkButton.classList.add('wiki2print') | |||
// adding more buttons | |||
const pageViews = document.querySelector('#p-views ul') | |||
const pageViews = document. | // View HTML | ||
const | const htmlButton = document.createElement('li') | ||
htmlButton.classList.add('collapsible', 'mw-list-item', 'wiki2print') | |||
htmlButton.id = 'ca-html' | |||
htmlButton.innerHTML = '<a href="https://cc.vvvvvvaria.org/wiki-to-print/html/' + pageName + '" target="_blank">View HTML</a>' | |||
pageViews.appendChild(htmlButton) | |||
pageViews.appendChild( | |||
// View PDF | |||
const pdfButton = document.createElement('li') | |||
pdfButton.classList.add('collapsible', 'mw-list-item', 'wiki2print') | |||
pdfButton.id = 'ca-pdf' | |||
pdfButton.innerHTML = '<a href="https://cc.vvvvvvaria.org/wiki-to-print/pdf/' + pageName + '" target="_blank">View PDF</a>' | |||
pageViews.appendChild(pdfButton) | |||
// UPDATE | |||
const updateButton = document.createElement('li') | |||
updateButton.classList.add('collapsible', 'mw-list-item', 'wiki2print') | |||
updateButton.id = 'ca-update' | |||
updateButton.innerHTML = '<a href="https://cc.vvvvvvaria.org/wiki-to-print/update/' + pageName + '" target="_blank">Update text</a>' | |||
pageViews.appendChild(updateButton) | |||
// FULL UPDATE | |||
const fullupdateButton = document.createElement('li') | |||
fullupdateButton.classList.add('collapsible', 'mw-list-item', 'wiki2print') | |||
fullupdateButton.id = 'ca-full-update' | |||
fullupdateButton.innerHTML = '<a href="https://cc.vvvvvvaria.org/wiki-to-print/update/' + pageName + '?full=true" target="_blank">Update media</a>' | |||
pageViews.appendChild(fullupdateButton) | |||
} else if (url.includes(cssNS + ':')) { | } else if (url.includes(cssNS + ':')) { | ||
console.log('this page is in namespace', cssNS) | console.log('this page is in namespace', cssNS) | ||
const contentAnchor = document.querySelector('#ca-nstab- | // Change "Page" button into "Content" button | ||
const contentAnchor = document.querySelector('#ca-nstab-pdf a') | |||
const contentLink = contentAnchor.href | const contentLink = contentAnchor.href | ||
contentAnchor.innerText = 'Content' | |||
// Change "Discussion" button into "CSS" button | |||
const talkAnchor = document.querySelector('#ca-talk a') | |||
const talkLink = talkAnchor.href | |||
talkAnchor.innerText = 'CSS!' | |||
const talkButton = document.querySelector('#ca-talk') | |||
talkButton.classList.add('wiki2print') | |||
// adding more buttons | |||
const pageViews = document.querySelector('#p-views ul') | |||
const pageViews = document. | // View HTML | ||
const | const htmlButton = document.createElement('li') | ||
htmlButton.classList.add('collapsible', 'mw-list-item', 'wiki2print') | |||
pageViews. | htmlButton.id = 'ca-html' | ||
htmlButton.innerHTML = '<a href="https://cc.vvvvvvaria.org/wiki-to-print/html/' + pageName + '" target="_blank">View HTML</a>' | |||
const | pageViews.appendChild(htmlButton) | ||
// View PDF | |||
const pdfButton = document.createElement('li') | |||
pdfButton.classList.add('collapsible', 'mw-list-item', 'wiki2print') | |||
pageViews.appendChild( | pdfButton.id = 'ca-pdf' | ||
pdfButton.innerHTML = '<a href="https://cc.vvvvvvaria.org/wiki-to-print/pdf/' + pageName + '" target="_blank">View PDF</a>' | |||
pageViews.appendChild(pdfButton) | |||
// UPDATE | |||
const updateButton = document.createElement('li') | |||
updateButton.classList.add('collapsible', 'mw-list-item', 'wiki2print') | |||
updateButton.id = 'ca-update' | |||
updateButton.innerHTML = '<a href="https://cc.vvvvvvaria.org/wiki-to-print/update/' + pageName + '" target="_blank">Update text</a>' | |||
pageViews.appendChild(updateButton) | |||
// FULL UPDATE | |||
const fullupdateButton = document.createElement('li') | |||
fullupdateButton.classList.add('collapsible', 'mw-list-item', 'wiki2print') | |||
fullupdateButton.id = 'ca-full-update' | |||
fullupdateButton.innerHTML = '<a href="https://cc.vvvvvvaria.org/wiki-to-print/update/' + pageName + '?full=true" target="_blank">Update media</a>' | |||
pageViews.appendChild(fullupdateButton) | |||
} | } |
Latest revision as of 13:30, 20 January 2023
/* Any JavaScript here will be loaded for all users on every page load. */
// Any JavaScript here will be loaded for all
// users on every page load.
console.log('hello from common.js')
// rename 'Discussion' tab or context menu button
// to 'CSS' in the 'Pdf' namespace.
const
url = window.location.href,
NS = 'Pdf', // content namespace
cssNS = NS + 'CSS', // css namespace
pageName = mw.config.get("wgPageName").split(":")[1]
if (url.includes(NS + ':')) {
console.log('this page is in namespace', NS)
// Change Discussion into CSS button
const talkAnchor = document.querySelector('#ca-talk a')
const talkLink = talkAnchor.href
talkAnchor.innerText = 'CSS!'
const talkButton = document.querySelector('#ca-talk')
talkButton.classList.add('wiki2print')
// adding more buttons
const pageViews = document.querySelector('#p-views ul')
// View HTML
const htmlButton = document.createElement('li')
htmlButton.classList.add('collapsible', 'mw-list-item', 'wiki2print')
htmlButton.id = 'ca-html'
htmlButton.innerHTML = '<a href="https://cc.vvvvvvaria.org/wiki-to-print/html/' + pageName + '" target="_blank">View HTML</a>'
pageViews.appendChild(htmlButton)
// View PDF
const pdfButton = document.createElement('li')
pdfButton.classList.add('collapsible', 'mw-list-item', 'wiki2print')
pdfButton.id = 'ca-pdf'
pdfButton.innerHTML = '<a href="https://cc.vvvvvvaria.org/wiki-to-print/pdf/' + pageName + '" target="_blank">View PDF</a>'
pageViews.appendChild(pdfButton)
// UPDATE
const updateButton = document.createElement('li')
updateButton.classList.add('collapsible', 'mw-list-item', 'wiki2print')
updateButton.id = 'ca-update'
updateButton.innerHTML = '<a href="https://cc.vvvvvvaria.org/wiki-to-print/update/' + pageName + '" target="_blank">Update text</a>'
pageViews.appendChild(updateButton)
// FULL UPDATE
const fullupdateButton = document.createElement('li')
fullupdateButton.classList.add('collapsible', 'mw-list-item', 'wiki2print')
fullupdateButton.id = 'ca-full-update'
fullupdateButton.innerHTML = '<a href="https://cc.vvvvvvaria.org/wiki-to-print/update/' + pageName + '?full=true" target="_blank">Update media</a>'
pageViews.appendChild(fullupdateButton)
} else if (url.includes(cssNS + ':')) {
console.log('this page is in namespace', cssNS)
// Change "Page" button into "Content" button
const contentAnchor = document.querySelector('#ca-nstab-pdf a')
const contentLink = contentAnchor.href
contentAnchor.innerText = 'Content'
// Change "Discussion" button into "CSS" button
const talkAnchor = document.querySelector('#ca-talk a')
const talkLink = talkAnchor.href
talkAnchor.innerText = 'CSS!'
const talkButton = document.querySelector('#ca-talk')
talkButton.classList.add('wiki2print')
// adding more buttons
const pageViews = document.querySelector('#p-views ul')
// View HTML
const htmlButton = document.createElement('li')
htmlButton.classList.add('collapsible', 'mw-list-item', 'wiki2print')
htmlButton.id = 'ca-html'
htmlButton.innerHTML = '<a href="https://cc.vvvvvvaria.org/wiki-to-print/html/' + pageName + '" target="_blank">View HTML</a>'
pageViews.appendChild(htmlButton)
// View PDF
const pdfButton = document.createElement('li')
pdfButton.classList.add('collapsible', 'mw-list-item', 'wiki2print')
pdfButton.id = 'ca-pdf'
pdfButton.innerHTML = '<a href="https://cc.vvvvvvaria.org/wiki-to-print/pdf/' + pageName + '" target="_blank">View PDF</a>'
pageViews.appendChild(pdfButton)
// UPDATE
const updateButton = document.createElement('li')
updateButton.classList.add('collapsible', 'mw-list-item', 'wiki2print')
updateButton.id = 'ca-update'
updateButton.innerHTML = '<a href="https://cc.vvvvvvaria.org/wiki-to-print/update/' + pageName + '" target="_blank">Update text</a>'
pageViews.appendChild(updateButton)
// FULL UPDATE
const fullupdateButton = document.createElement('li')
fullupdateButton.classList.add('collapsible', 'mw-list-item', 'wiki2print')
fullupdateButton.id = 'ca-full-update'
fullupdateButton.innerHTML = '<a href="https://cc.vvvvvvaria.org/wiki-to-print/update/' + pageName + '?full=true" target="_blank">Update media</a>'
pageViews.appendChild(fullupdateButton)
}