„Benutzer:SSCreader/common.js“ – Versionsunterschied
Erscheinungsbild
Inhalt gelöscht Inhalt hinzugefügt
AZ: Die Seite wurde neu angelegt: var s="asd" console.log("s: "+s) |
KKeine Bearbeitungszusammenfassung |
||
Zeile 1: | Zeile 1: | ||
var pageTitle = mw.config.get('wgPageName'); |
|||
var s="asd" |
|||
console.log("s: "+s) |
|||
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 "fn failed" |
|||
} |
|||
function getWordCount() { |
|||
const text = document.body.innerText || ''; |
|||
let words = text.trim().split(/\s+/).filter(Boolean); |
|||
let ref_idx = words.lastIndexOf("Referencias[editar") |
|||
console.log("ref_idx: " + ref_idx) |
|||
console.log(words) |
|||
words = words.slice(0, ref_idx) |
|||
return words.length; |
|||
} |
|||
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 = '2.25cm'; |
|||
infoDiv.style.right = '5%'; |
|||
infoDiv.style.fontSize = '14px'; |
|||
infoDiv.style.fontWeight = '600'; |
|||
infoDiv.style.lineHeight = '1.6'; |
|||
infoDiv.style.padding = '12px 16px'; |
|||
infoDiv.style.color = '#fefefe'; // near white text |
|||
// infoDiv.style.backgroundColor = '#111'; // style 1,deep black |
|||
infoDiv.style.backgroundColor = 'rgba(17, 17, 17, 0.6' // style 2 |
|||
// infoDiv.style.backgroundColor = "#ffe0f0" // light pink |
|||
// infoDiv.style.border = '2px solid #22c55e'; // style 1,vivid green |
|||
infoDiv.style.border = '1.5px solid #22c55e'; //style 2 |
|||
infoDiv.style.borderRadius = '12px'; |
|||
// infoDiv.style.boxShadow = '0 4px 14px rgba(34, 197, 94, 0.65)';//style 1 |
|||
infoDiv.style.boxShadow = '0 0 10px rgba(34, 197, 94, 0.3)'; // style 2 |
|||
// infoDiv.style.boxShadow = '0 0 10px rgba(34, 197, 94, 0.65)'; |
|||
infoDiv.style.zIndex = '9999'; |
|||
infoDiv.style.maxWidth = '320px'; |
|||
/** |
|||
infoDiv.style.position = 'absolute'; |
|||
infoDiv.style.top = '2.25cm'; |
|||
infoDiv.style.right = '5%'; |
|||
infoDiv.style.fontSize = 'small'; |
|||
infoDiv.style.color = 'green' |
|||
infoDiv.style.lineHeight = '1.4'; |
|||
infoDiv.style.padding = '9px 12px'; |
|||
**/ |
|||
// infoDiv.style.color = 'red'; |
|||
// 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.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); |
|||
} |
|||
const wordDiv = document.createElement("div") |
|||
let wordCount = getWordCount() |
|||
let short_medium_long = getWordCountLabel(wordCount) |
|||
//wordDiv.textContent = "Words: " + wordCount + " (" + short_medium_long + ")" |
|||
//infoDiv.appendChild(wordDiv) |
|||
//wordDiv.textContent += " (" + short_medium_long + ")" |
|||
// infoDiv.textContent = "Words: " + wordCount |
|||
// infoDiv.textContent = "Words: " + wordCount |
|||
document.body.appendChild(infoDiv); |
|||
}) |
Aktuelle Version vom 12. Juli 2025, 05:18 Uhr
var pageTitle = mw.config.get('wgPageName');
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 "fn failed"
}
function getWordCount() {
const text = document.body.innerText || '';
let words = text.trim().split(/\s+/).filter(Boolean);
let ref_idx = words.lastIndexOf("Referencias[editar")
console.log("ref_idx: " + ref_idx)
console.log(words)
words = words.slice(0, ref_idx)
return words.length;
}
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 = '2.25cm';
infoDiv.style.right = '5%';
infoDiv.style.fontSize = '14px';
infoDiv.style.fontWeight = '600';
infoDiv.style.lineHeight = '1.6';
infoDiv.style.padding = '12px 16px';
infoDiv.style.color = '#fefefe'; // near white text
// infoDiv.style.backgroundColor = '#111'; // style 1,deep black
infoDiv.style.backgroundColor = 'rgba(17, 17, 17, 0.6' // style 2
// infoDiv.style.backgroundColor = "#ffe0f0" // light pink
// infoDiv.style.border = '2px solid #22c55e'; // style 1,vivid green
infoDiv.style.border = '1.5px solid #22c55e'; //style 2
infoDiv.style.borderRadius = '12px';
// infoDiv.style.boxShadow = '0 4px 14px rgba(34, 197, 94, 0.65)';//style 1
infoDiv.style.boxShadow = '0 0 10px rgba(34, 197, 94, 0.3)'; // style 2
// infoDiv.style.boxShadow = '0 0 10px rgba(34, 197, 94, 0.65)';
infoDiv.style.zIndex = '9999';
infoDiv.style.maxWidth = '320px';
/**
infoDiv.style.position = 'absolute';
infoDiv.style.top = '2.25cm';
infoDiv.style.right = '5%';
infoDiv.style.fontSize = 'small';
infoDiv.style.color = 'green'
infoDiv.style.lineHeight = '1.4';
infoDiv.style.padding = '9px 12px';
**/
// infoDiv.style.color = 'red';
// 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.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);
}
const wordDiv = document.createElement("div")
let wordCount = getWordCount()
let short_medium_long = getWordCountLabel(wordCount)
//wordDiv.textContent = "Words: " + wordCount + " (" + short_medium_long + ")"
//infoDiv.appendChild(wordDiv)
//wordDiv.textContent += " (" + short_medium_long + ")"
// infoDiv.textContent = "Words: " + wordCount
// infoDiv.textContent = "Words: " + wordCount
document.body.appendChild(infoDiv);
})