Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
const my_title = mw.config.get('wgPageName'); fetch(`/w/index.php?title=${my_title}&action=info`) .then(response => response.text()) .then(data => { const parser = new DOMParser(); const doc = parser.parseFromString(data, 'text/html'); const creationDateElement = doc.querySelector('#mw-pageinfo-firsttime td:nth-child(2) a'); var pageViewsElement = doc.querySelector('#mw-pvi-month-count td:nth-child(2) .mw-pvi-month'); //console.log(pageViewsElement); //console.log(doc.querySelector('#mw-pvi-month-count')); //console.log(doc.querySelector('#mw-pvi-month-count').innerHTML); const infoDiv = document.createElement('div'); //infoDiv.style.position = 'absolute'; //infoDiv.style.top = '1.805cm'; // infoDiv.style.top = '1.605cm'; //infoDiv.style.fontSize = 'small'; infoDiv.style.position = 'absolute'; infoDiv.style.top = '2.25cm'; infoDiv.style.marginRight = '5px'; infoDiv.style.right = '1%'; // infoDiv.style.left = '15%'; infoDiv.style.fontSize = 'small'; // infoDiv.style.color = 'red'; infoDiv.style.color ='green' // infoDiv.style.backgroundColor = '#FFFACD'; // lighter yellow // infoDiv.style.backgroundColor = '#FFD700' // yellow // infoDiv.style.borderRadius = '8.5px'; // infoDiv.style.border = '2.5px solid green'; // red border // infoDiv.style.borderRadius = '10px'; // rounded border // infoDiv.style.boxShadow = '0 2px 6px rgba(0, 0, 0, 0.2)'; infoDiv.style.lineHeight = '1.4'; infoDiv.style.padding = '9px 12px'; //infoDiv.style.backgroundColor = 'rgba(255, 255, 204, 0.25)'; // infoDiv.style.color = 'crimson'; // infoDiv.style.padding = '2px'; if (creationDateElement) { var creationDate = creationDateElement.textContent.trim(); creationDate = creationDate.split(" ").slice(1) creationDate[1] = creationDate.at(1).at(0).toUpperCase() + creationDate.at(1).slice(1) let final_string = creationDate.join(" ") infoDiv.textContent = `Page created: ` + final_string // infoDiv.textContent = `Page created: ${final_string}`; } if (pageViewsElement) { const pageViews = pageViewsElement.textContent.trim(); const pageViewsText = document.createElement('div'); pageViewsText.textContent = `Page views (last month): ${pageViews}`; infoDiv.appendChild(pageViewsText); } document.body.appendChild(infoDiv); }) .catch(error => { console.error('Error fetching page info:', error); });