User:SSCreader/common.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | The accompanying .css page for this skin is at User:SSCreader/common.css. |
if (mw.config.get('wgNamespaceNumber') === 0 || mw.config.get('wgNamespaceNumber') === 14
|| mw.config.get("wgNamespaceNumber") == 4 || mw.config.get("wgNamespaceNumber") == 2
|| mw.config.get("wgNamespaceNumber") == 10 || mw.config.get("wgNamespaceNumber") == 12
|| mw.config.get("wgNamespaceNumber") == 100 || mw.config.get("wgNamespaceNumber") == 6
||mw.config.get("wgNamespaceNumber") == 5 || mw.config.get("wgNamespaceNumber") == 3
|| mw.config.get("wgNamespaceNumber") == 118 || mw.config.get("wgNamespaceNumber") == 848
|| mw.config.get("wgNamespaceNumber") == 126 || mw.config.get("wgNamespaceNumber") == 119
|| mw.config.get("wgNamespaceNumber") == 1 || mw.config.get("wgNamespaceNumber") == 8
|| mw.config.get("wgNamespaceNumber") == 15)
{
var pageTitle = mw.config.get('wgPageName');
// Fetch the page info from the action=info page
fetch(`/w/index.php?title=${pageTitle}&action=info`)
.then(response => response.text())
.then(data => {
const parser = new DOMParser();
const doc = parser.parseFromString(data, 'text/html');
function getWordCountLabel(wordCount) {
if (wordCount <= 999) return 'Very short'
if (wordCount >= 1000 && wordCount <= 2500) return 'Short';
if (wordCount >= 2501 && wordCount <= 5500) return 'Medium';
if (wordCount >= 5500 && wordCount <= 9500) return 'Long';
if (wordCount >= 9500) return 'Very long'
return "fail"
}
function getWordCount() {
const text = document.body.innerText || '';
let words = text.trim().split(/\s+/).filter(Boolean);
let ref_idx = words.lastIndexOf("References[edit")
words = words.slice(0, ref_idx)
return words.length;
}
const creationDateElement = doc.querySelector('#mw-pageinfo-firsttime td:nth-child(2) a');
const pageViewsElement = doc.querySelector('#mw-pvi-month-count td:nth-child(2) a');
const infoDiv = document.createElement('div');
infoDiv.style.position = 'absolute';
infoDiv.style.top = '2.25cm';
infoDiv.style.right = '5%';
infoDiv.style.fontSize = 'small';
infoDiv.style.backgroundColor = '#fff8e1'; // Soft light ivory
infoDiv.style.color = '#cc0000'; // Deep, saturated red
infoDiv.style.boxShadow = '0 4px 16px rgba(0, 0, 0, 0.25)';
infoDiv.style.borderRadius = '8.5px';
infoDiv.style.border = '2.5px solid black';
infoDiv.style.lineHeight = '1.4';
infoDiv.style.padding = '9px 12px';
// infoDiv.style.fontWeight = '900';
// infoDiv.style.border = '2px solid rgba(255, 255, 255, 0.2)';
// infoDiv.style.color = 'red';
// infoDiv.style.color = '#B22222'; // lighter red
// infoDiv.style.borderRadius = '12px';
// infoDiv.style.backgroundColor = '#FFFACD'; // lighter yellow
// infoDiv.style.backgroundColor = '#FFD700' // yellow
// infoDiv.style.backgroundColor = '#FFD700'; // Strong gold
// infoDiv.style.textShadow = '1px 1px 2px rgba(0,0,0,0.4)'; // Soft black shadow for legibility
// infoDiv.style.color = '#c60000'; // Richer red
// infoDiv.style.boxShadow = '0 4px 10px rgba(0, 0, 0, 0.3)'; // Clean lift
// infoDiv.style.boxShadow = '0 2px 6px rgba(0, 0, 0, 0.2)';
// infoDiv.style.boxShadow = '0 4px 12px rgba(0, 0, 0, 0.3)'; // darker shadow
// infoDiv.style.border = '2.5px solid green';
// infoDiv.style.borderRadius = '10px'; // rounded border
// infoDiv.style.backgroundColor = 'rgba(255, 255, 102,0.24)';
// infoDiv.style.color = '#FF0000';
// infoDiv.style.color = '#663399'; // purple
// Add creation date if the element exists
if (creationDateElement) {
let creationDate = creationDateElement.textContent.trim();
creationDate = creationDate.split(" ").slice(1)
creationDate[1] = creationDate[1].slice(0, 3)
let final_string = creationDate.join(" ")
infoDiv.textContent = `Page created: ` + final_string
}
// Add page views if the element exists, place it under the creation date
if (pageViewsElement) {
const pageViews = pageViewsElement.textContent.trim();
const pageViewsText = document.createElement('div');
// pageViewsText.textContent = `Page views: ${pageViews}`;
let spaces = " "
let spaces2 = spaces.repeat(2)
pageViewsText.textContent = `Pageviews (30 days): ${pageViews}`
infoDiv.appendChild(pageViewsText);
}
const wordDiv = document.createElement("div")
let wordCount = getWordCount()
let short_medium_long = getWordCountLabel(wordCount)
// wordDiv.textContent = "Word count: " + wordCount + " (" + short_medium_long + ")"
// infoDiv.appendChild(wordDiv)
// Append the div to the body or content area of the article
document.body.appendChild(infoDiv);
})
.catch(error => {
console.error('Error fetching page info:', error);
});
}
mw.loader.load('/w/index.php?title=User:Panamitsu/script/Watchlist User Mute.js&action=raw&ctype=text/javascript&username=AlyInWikiWonderland')
// ---------------------------------------------------
// var highlightWikipediaLinks = function($content) {
// mw.hook('wikipage.content').add($content => {
// function editDistance(s, t) {
// const m = s.length, n = t.length;
// const dp = Array(m + 1).fill(null).map(() => Array(n + 1).fill(0));
// for (let i = 0; i <= m; i++) dp[i][0] = i;
// for (let j = 0; j <= n; j++) dp[0][j] = j;
// for (let i = 1; i <= m; i++) {
// for (let j = 1; j <= n; j++) {
// if (s[i - 1].toLowerCase() === t[j - 1].toLowerCase()) {
// dp[i][j] = dp[i - 1][j - 1];
// }
// else {
// dp[i][j] = Math.min(dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + 1);
// }
// }
// }
// return dp[m][n];
// }
// $content.find('a[href*="wikipedia.org/wiki/"]').each(function () {
// var $link = $(this);
// var linkText = $link.text().trim();
// if (linkText.split(/\s+/).length < 2) return; // Only multiword links
// try {
// var url = new URL($link.attr('href'), window.location.origin);
// var pageName = decodeURIComponent(url.pathname.split('/').pop().replace(/_/g, ' '));
// var distance = editDistance(linkText, pageName);
// var threshold = Math.floor(Math.min(linkText.length, pageName.length) * 0.35);
// if (distance > threshold) {
// // $link.css('color', 'green');
// $link.css({
// 'background-color': "#90EE0",
// 'padding': '2px 4px',
// 'border-radius': '2.5px'
// })
// }
// } catch (e) {
// console.error(e);
// }
// });
// });
// Apply script when the page content is updated
// mw.hook('wikipage.content').add(highlightWikipediaLinks);
/**
document.addEventListener("DOMContentLoaded", function() {
var pageViewElement = document.querySelector('span:contains("page views in the last 30 days")');
if (pageViewElement) {
// Add a class to style it
pageViewElement.classList.add('pageviews');
pageViewElement.classList.add('infoDiv');
}
});
*/