MediaWiki:Common.js: Difference between revisions

From creative crowd wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 10: Line 10:


const  
const  
url   = window.location.href,
url     = window.location.href,
NS     = 'Pdf',         // content namespace
NS       = 'Pdf',                 // content namespace
cssNS = NS + 'CSS'            // css namespace
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)
Line 19: Line 20:
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!'
talkAnchor.innerText = 'CSS'
// adding more buttonshttp://51.195.117.20:5555/
const pageViews  = document.querySelector('#p-views ul')
const pageViews  = document.querySelector('#p-views ul')
// wiki2print
const wiki2printButton  = document.createElement('li')
const wiki2printButton  = document.createElement('li')
wiki2printButton.classList.add('collapsible', 'mw-list-item')
wiki2printButton.classList.add('collapsible', 'mw-list-item')
wiki2printButton.id = 'ca-wiki2print'
wiki2printButton.id = 'ca-wiki2print'
wiki2printButton.innerHTML = '<a href="http://51.195.117.20:5555/">wiki2print</a>'
wiki2printButton.innerHTML = '<a href="http://51.195.117.20:5555/">wiki2print</a>'
pageViews.appendChild(wiki2printButton)
pageViews.appendChild(wiki2printButton)
// PDF
const pdfButton  = document.createElement('li')
pdfButton.classList.add('collapsible', 'mw-list-item')
pdfButton.id = 'ca-wiki2print'
pdfButton.innerHTML = '<a href="http://51.195.117.20:5555/pdf/' + pageName + '">PDF</a>'
pageViews.appendChild(pdfButton)


} else if (url.includes(cssNS + ':')) {
} else if (url.includes(cssNS + ':')) {

Revision as of 15:32, 8 December 2022

/* 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)
	
	const talkAnchor = document.querySelector('#ca-talk a')
	const talkLink = talkAnchor.href
	talkAnchor.innerText = 'CSS!'
	
	// adding more buttonshttp://51.195.117.20:5555/
	const pageViews  = document.querySelector('#p-views ul')
	
	// wiki2print
	const wiki2printButton  = document.createElement('li')
	wiki2printButton.classList.add('collapsible', 'mw-list-item')
	wiki2printButton.id = 'ca-wiki2print'
	wiki2printButton.innerHTML = '<a href="http://51.195.117.20:5555/">wiki2print</a>'
	pageViews.appendChild(wiki2printButton)
	
	// PDF
	const pdfButton  = document.createElement('li')
	pdfButton.classList.add('collapsible', 'mw-list-item')
	pdfButton.id = 'ca-wiki2print'
	pdfButton.innerHTML = '<a href="http://51.195.117.20:5555/pdf/' + pageName + '">PDF</a>'
	pageViews.appendChild(pdfButton)

} else if (url.includes(cssNS + ':')) {
	console.log('this page is in namespace', cssNS)
	
	const contentAnchor = document.querySelector('#ca-nstab-pdf a')
	const contentLink = contentAnchor.href
	
	contentAnchor.innerText = 'Content'
	
	const pageViews = document.querySelector('#p-views ul')
	const addTopicButton = document.querySelector('#ca-addsection')
		
	pageViews.removeChild(addTopicButton)	
		
	const contentButton = document.createElement('li')
		
	contentButton.classList.add('collapsible', 'mw-list-item')
	contentButton.id = 'ca-content'
	contentButton.innerHTML = '<a href="' + contentLink + '">Content!</a>'
	pageViews.appendChild(contentButton)
		
}