Gebruiker:Freestyle/vector.js: verschil tussen versies
Naar navigatie springen
Naar zoeken springen
(update userscript) |
(terug naar vorige - update werkt niet 🥹) Label: Ongedaan maken |
||
Regel 1: | Regel 1: | ||
− | // Script op basis van | + | // Script op basis van Wikipedia (en) User:Enterprisey/watchlist-notice.js |
+ | // Dit script geeft een melding op de plek van de volglijst-link van de laatst geüpdatete pagina uit de volglijst. een rood sterretje linkt naar de diff van die wijziging en geeft ook extra informatie als de muis erboven is. | ||
+ | // Indien gewenst kan ook één pagina extra in de gaten gehouden worden (de string pageToWatch), met een opvallende melding op de plek van de SiteNotice als deze bovenaan de volglijst komt. | ||
+ | |||
// Specifieke pagina om in de gaten te houden (moet wel op de volglijst staan): | // Specifieke pagina om in de gaten te houden (moet wel op de volglijst staan): | ||
const pageToWatch = ""; | const pageToWatch = ""; | ||
− | const meldingMinuten = 120 | + | const meldingMinuten = 120 // minuten waarbinnen een edit moet zijn gedaan om nog een melding te geven. |
const currentPageName = mw.config.get("wgPageName").replace(/_/g, ' '); | const currentPageName = mw.config.get("wgPageName").replace(/_/g, ' '); | ||
// Volglijst update-notice tonen aan of uit? | // Volglijst update-notice tonen aan of uit? | ||
const volglijstNotice = true; | const volglijstNotice = true; | ||
− | var showPTWNotice = false; | + | var showPTWNotice = false; |
− | |||
mw.loader.using("mediawiki.util", function () { | mw.loader.using("mediawiki.util", function () { | ||
− | var showNotice = function (bewerking | + | var showNotice = function (bewerking) { |
− | // Stick a notice after the notification count | + | // Stick a "Watchlist update!" notice after the notification count |
$("#pt-notifications-notice").after( | $("#pt-notifications-notice").after( | ||
$("<li>") | $("<li>") | ||
Regel 17: | Regel 19: | ||
.text(bewerking.title + " geüpdatet") | .text(bewerking.title + " geüpdatet") | ||
.css({ | .css({ | ||
− | "background-color | + | "background-color": "#3385ff", |
color: "white", | color: "white", | ||
"border-radius": "2px", | "border-radius": "2px", | ||
Regel 25: | Regel 27: | ||
transition: "background-color 0.5s", | transition: "background-color 0.5s", | ||
}) | }) | ||
− | .attr("href", "/wiki/Special: | + | .attr("href", "/wiki/Special:Watchlist") |
− | .mouseover( | + | .mouseover(updateNotice) |
) | ) | ||
− | .attr("id", | + | .attr("id", "watchlist-update-notice") |
); | ); | ||
− | |||
var commentString = bewerking.comment.replace("/* ", ""); | var commentString = bewerking.comment.replace("/* ", ""); | ||
− | var bewerkingArray = commentString.split(' */'); | + | var bewerkingArray = commentString.split (' */'); |
− | var tooltip = | + | var tooltip = '➝ ' + bewerkingArray[0]; |
− | if (bewerkingArray[1] | + | if (bewerkingArray[1]) { |
− | tooltip += ': ' + bewerkingArray[1]; | + | tooltip += ': ' + bewerkingArray[1]; |
} | } | ||
− | |||
var kop = bewerkingArray[0]; | var kop = bewerkingArray[0]; | ||
− | if (kop.substr(0, 22) == 'Nieuw kopje aangemaakt') { | + | if (kop.substr (0, 22) == 'Nieuw kopje aangemaakt') { |
kop = bewerkingArray[0].substr(24, bewerkingArray[0].length); | kop = bewerkingArray[0].substr(24, bewerkingArray[0].length); | ||
} | } | ||
− | |||
− | |||
$("#pt-mytalk").before( | $("#pt-mytalk").before( | ||
$("<li>") | $("<li>") | ||
Regel 50: | Regel 48: | ||
.text("*") | .text("*") | ||
.css({ | .css({ | ||
− | color | + | color: "#555555", |
"border-radius": "2px", | "border-radius": "2px", | ||
padding: "0.25em 0.45em 0.2em", | padding: "0.25em 0.45em 0.2em", | ||
cursor: "pointer", | cursor: "pointer", | ||
"font-weight": "bold", | "font-weight": "bold", | ||
+ | transition: "background-color 0.5s", | ||
}) | }) | ||
.attr( | .attr( | ||
Regel 60: | Regel 59: | ||
"https://wikikids.nl/index.php?title=" + | "https://wikikids.nl/index.php?title=" + | ||
encodeURI(bewerking.title.replace(/ /g,"_")) + | encodeURI(bewerking.title.replace(/ /g,"_")) + | ||
+ | "&curid=" + | ||
+ | bewerking.pageid + | ||
"&diff=" + | "&diff=" + | ||
− | bewerking.revid + | + | bewerking.revid + "&volglijstmelder=true" |
− | |||
) | ) | ||
) | ) | ||
− | .attr("id", | + | .attr("id", "watchlist-update-diff") |
.attr( | .attr( | ||
"title", | "title", | ||
− | bewerking.type + " door " + bewerking.user + " (" + tooltip + ")" | + | bewerking.type + |
− | + | " door " + | |
+ | bewerking.user + | ||
+ | " (" + tooltip + | ||
+ | ")") | ||
); | ); | ||
− | |||
− | |||
$("#pt-mytalk").before( | $("#pt-mytalk").before( | ||
$("<li>") | $("<li>") | ||
Regel 79: | Regel 80: | ||
.text("→") | .text("→") | ||
.css({ | .css({ | ||
− | color | + | color: "#555555", |
"border-radius": "2px", | "border-radius": "2px", | ||
padding: "0.25em 0.45em 0.2em", | padding: "0.25em 0.45em 0.2em", | ||
cursor: "pointer", | cursor: "pointer", | ||
"font-weight": "bold", | "font-weight": "bold", | ||
+ | transition: "background-color 0.5s", | ||
}) | }) | ||
.attr( | .attr( | ||
"href", | "href", | ||
"https://wikikids.nl/index.php?title=" + | "https://wikikids.nl/index.php?title=" + | ||
− | encodeURI(bewerking.title.replace(/ /g,"_")) + | + | encodeURI(bewerking.title.replace(/ /g,"_")) + "#" + kop.replace(/ /g,"_") |
− | |||
) | ) | ||
) | ) | ||
− | .attr("id", | + | .attr("id", "watchlist-update-link") |
− | .attr("title", | + | .attr( |
+ | "title", tooltip) | ||
); | ); | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
}; | }; | ||
Regel 116: | Regel 102: | ||
// Lighten the background color so the user knows we're updating | // Lighten the background color so the user knows we're updating | ||
$("#watchlist-update-notice a").css("background-color", "#7bff7b"); | $("#watchlist-update-notice a").css("background-color", "#7bff7b"); | ||
− | |||
− | |||
− | |||
// Update the notice | // Update the notice | ||
Regel 125: | Regel 108: | ||
aantalEdits = 5; | aantalEdits = 5; | ||
} | } | ||
− | |||
$.getJSON(mw.util.wikiScript("api"), { | $.getJSON(mw.util.wikiScript("api"), { | ||
format: "json", | format: "json", | ||
Regel 145: | Regel 127: | ||
document.getElementById("siteNotice").innerHTML = | document.getElementById("siteNotice").innerHTML = | ||
'<div style="width:100%; margin: 0 auto; padding:.5em; background-color:#ffb84d;">De pagina <strong><a href="' + | '<div style="width:100%; margin: 0 auto; padding:.5em; background-color:#ffb84d;">De pagina <strong><a href="' + | ||
− | "https://wikikids.nl | + | "https://wikikids.nl/" + |
encodeURI(pageToWatch.replace(/ /g,"_")) + | encodeURI(pageToWatch.replace(/ /g,"_")) + | ||
'">' + | '">' + | ||
Regel 172: | Regel 154: | ||
} else { | } else { | ||
// No new watchlist diffs to read, so hide notice, diff and link | // No new watchlist diffs to read, so hide notice, diff and link | ||
− | $("#watchlist-update-notice | + | $("#watchlist-update-notice").remove(); |
+ | $("#watchlist-update-diff").remove(); | ||
+ | $("#watchlist-update-link").remove(); | ||
if (pageToWatch === currentPageName) { | if (pageToWatch === currentPageName) { | ||
$("#siteNotice").remove(); | $("#siteNotice").remove(); | ||
showPTWNotice = false; | showPTWNotice = false; | ||
} | } | ||
− | |||
− | |||
} | } | ||
}); | }); |
Huidige versie van 17 feb 2025 om 10:27
// Script op basis van Wikipedia (en) User:Enterprisey/watchlist-notice.js
// Dit script geeft een melding op de plek van de volglijst-link van de laatst geüpdatete pagina uit de volglijst. een rood sterretje linkt naar de diff van die wijziging en geeft ook extra informatie als de muis erboven is.
// Indien gewenst kan ook één pagina extra in de gaten gehouden worden (de string pageToWatch), met een opvallende melding op de plek van de SiteNotice als deze bovenaan de volglijst komt.
// Specifieke pagina om in de gaten te houden (moet wel op de volglijst staan):
const pageToWatch = "";
const meldingMinuten = 120 // minuten waarbinnen een edit moet zijn gedaan om nog een melding te geven.
const currentPageName = mw.config.get("wgPageName").replace(/_/g, ' ');
// Volglijst update-notice tonen aan of uit?
const volglijstNotice = true;
var showPTWNotice = false;
mw.loader.using("mediawiki.util", function () {
var showNotice = function (bewerking) {
// Stick a "Watchlist update!" notice after the notification count
$("#pt-notifications-notice").after(
$("<li>")
.append(
$("<a>")
.text(bewerking.title + " geüpdatet")
.css({
"background-color": "#3385ff",
color: "white",
"border-radius": "2px",
padding: "0.25em 0.45em 0.2em",
cursor: "pointer",
"font-weight": "bold",
transition: "background-color 0.5s",
})
.attr("href", "/wiki/Special:Watchlist")
.mouseover(updateNotice)
)
.attr("id", "watchlist-update-notice")
);
var commentString = bewerking.comment.replace("/* ", "");
var bewerkingArray = commentString.split (' */');
var tooltip = '➝ ' + bewerkingArray[0];
if (bewerkingArray[1]) {
tooltip += ': ' + bewerkingArray[1];
}
var kop = bewerkingArray[0];
if (kop.substr (0, 22) == 'Nieuw kopje aangemaakt') {
kop = bewerkingArray[0].substr(24, bewerkingArray[0].length);
}
$("#pt-mytalk").before(
$("<li>")
.append(
$("<a>")
.text("*")
.css({
color: "#555555",
"border-radius": "2px",
padding: "0.25em 0.45em 0.2em",
cursor: "pointer",
"font-weight": "bold",
transition: "background-color 0.5s",
})
.attr(
"href",
"https://wikikids.nl/index.php?title=" +
encodeURI(bewerking.title.replace(/ /g,"_")) +
"&curid=" +
bewerking.pageid +
"&diff=" +
bewerking.revid + "&volglijstmelder=true"
)
)
.attr("id", "watchlist-update-diff")
.attr(
"title",
bewerking.type +
" door " +
bewerking.user +
" (" + tooltip +
")")
);
$("#pt-mytalk").before(
$("<li>")
.append(
$("<a>")
.text("→")
.css({
color: "#555555",
"border-radius": "2px",
padding: "0.25em 0.45em 0.2em",
cursor: "pointer",
"font-weight": "bold",
transition: "background-color 0.5s",
})
.attr(
"href",
"https://wikikids.nl/index.php?title=" +
encodeURI(bewerking.title.replace(/ /g,"_")) + "#" + kop.replace(/ /g,"_")
)
)
.attr("id", "watchlist-update-link")
.attr(
"title", tooltip)
);
};
var updateNotice = function () {
// Lighten the background color so the user knows we're updating
$("#watchlist-update-notice a").css("background-color", "#7bff7b");
// Update the notice
var aantalEdits = 1;
if (pageToWatch) {
aantalEdits = 5;
}
$.getJSON(mw.util.wikiScript("api"), {
format: "json",
action: "query",
list: "watchlist",
wlprop: "comment|title|user|timestamp",
wlshow: "unread",
wllimit: aantalEdits,
}).done(function (data) {
if (!data.query) return;
if (data.query.watchlist.length) {
// There are new watchlist diffs to read, so show notice
var minuten = Math.round((Date.now() - Date.parse(data.query.watchlist[0].timestamp)) / 60000);
if (
data.query.watchlist[0].title == pageToWatch &&
data.query.watchlist[0].user !== "Nlwikibots" && minuten <= meldingMinuten
) {
showPTWNotice = true;
document.getElementById("siteNotice").innerHTML =
'<div style="width:100%; margin: 0 auto; padding:.5em; background-color:#ffb84d;">De pagina <strong><a href="' +
"https://wikikids.nl/" +
encodeURI(pageToWatch.replace(/ /g,"_")) +
'">' +
pageToWatch +
'</a></strong> is onlangs gewijzigd door <a href = "https://wikikids.nl/Overleg_gebruiker:' +
encodeURI(data.query.watchlist[0].user) +
'">' +
data.query.watchlist[0].user +
'</a>. (<a href="https://wikikids.nl/index.php?title=' +
encodeURI(pageToWatch.replace(/ /g,"_")) +
"&curid=" +
data.query.watchlist[0].pageid +
"&diff=" +
data.query.watchlist[0].revid +
'">diff</a>)</div>';
}
if (!$("#watchlist-update-notice").length) {
// That is, if it isn't shown already
if (volglijstNotice) {
showNotice(data.query.watchlist[0]);
}
} else {
// There's already a notice, so change background
$("#watchlist-update-notice a").css("background-color", "#3385ff");
}
} else {
// No new watchlist diffs to read, so hide notice, diff and link
$("#watchlist-update-notice").remove();
$("#watchlist-update-diff").remove();
$("#watchlist-update-link").remove();
if (pageToWatch === currentPageName) {
$("#siteNotice").remove();
showPTWNotice = false;
}
}
});
};
$(document).ready(function () {
updateNotice();
window.setInterval(updateNotice, 120000);
});
});