Gebruiker:Freestyle/vector.js: verschil tussen versies

Uit Wikikids
Naar navigatie springen Naar zoeken springen
(links aangepast naar wikikids server 🙄)
(update userscript)
Regel 1: Regel 1:
// Script op basis van Wikipedia (en) User:Enterprisey/watchlist-notice.js
+
// Script op basis van [[: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 // minuten waarbinnen een edit moet zijn gedaan om nog een melding te geven.
+
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, isAnonymous = false) {
     // Stick a "Watchlist update!" notice after the notification count
+
     // Stick a notice after the notification count
 
     $("#pt-notifications-notice").after(
 
     $("#pt-notifications-notice").after(
 
       $("<li>")
 
       $("<li>")
Regel 19: Regel 17:
 
             .text(bewerking.title + " geüpdatet")
 
             .text(bewerking.title + " geüpdatet")
 
             .css({
 
             .css({
               "background-color": "#3385ff",
+
               "background-color": isAnonymous ? "#bb3333" : "#3385ff",
 
               color: "white",
 
               color: "white",
 
               "border-radius": "2px",
 
               "border-radius": "2px",
Regel 27: Regel 25:
 
               transition: "background-color 0.5s",
 
               transition: "background-color 0.5s",
 
             })
 
             })
             .attr("href", "/wiki/Special:Watchlist")
+
             .attr("href", "/wiki/Special:" + (isAnonymous ? "RecentChanges" : "Watchlist"))
             .mouseover(updateNotice)
+
             .mouseover(isAnonymous ? null : updateNotice)
 
         )
 
         )
         .attr("id", "watchlist-update-notice")
+
         .attr("id", isAnonymous ? "anon-update-notice" : "watchlist-update-notice")
 
     );
 
     );
 +
 
     var commentString = bewerking.comment.replace("/* ", "");
 
     var commentString = bewerking.comment.replace("/* ", "");
     var bewerkingArray = commentString.split (' */');
+
     var bewerkingArray = commentString.split(' */');
     var tooltip = '➝ ' + bewerkingArray[0];
+
     var tooltip = isAnonymous ? '' : ('➝ ' + bewerkingArray[0]);
     if (bewerkingArray[1]) {
+
     if (bewerkingArray[1] && !isAnonymous) {
       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);
 
     }
 
     }
 +
 +
    // Add diff link (*)
 
     $("#pt-mytalk").before(
 
     $("#pt-mytalk").before(
 
       $("<li>")
 
       $("<li>")
Regel 48: Regel 50:
 
             .text("*")
 
             .text("*")
 
             .css({
 
             .css({
               color: "#555555",
+
               color: isAnonymous ? "#bb3333" : "#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 59: Regel 60:
 
               "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 + "&volglijstmelder=true"
+
                 bewerking.revid +
 +
                (isAnonymous ? "" : "&volglijstmelder=true")
 
             )
 
             )
 
         )
 
         )
         .attr("id", "watchlist-update-diff")
+
         .attr("id", isAnonymous ? "anon-update-diff" : "watchlist-update-diff")
 
         .attr(
 
         .attr(
 
           "title",
 
           "title",
           bewerking.type +
+
           bewerking.type + " door " + bewerking.user + " (" + tooltip + ")"
            " door " +
+
        )
            bewerking.user +
 
            " (" + tooltip +
 
            ")")
 
 
     );
 
     );
 +
 +
    // Add section link (→)
 
     $("#pt-mytalk").before(
 
     $("#pt-mytalk").before(
 
       $("<li>")
 
       $("<li>")
Regel 80: Regel 79:
 
             .text("→")
 
             .text("→")
 
             .css({
 
             .css({
               color: "#555555",
+
               color: isAnonymous ? "#bb3333" : "#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,"_")) + "#" + kop.replace(/ /g,"_")  
+
                 encodeURI(bewerking.title.replace(/ /g,"_")) +  
 +
                (kop ? "#" + kop.replace(/ /g,"_") : "")
 
             )
 
             )
 
         )
 
         )
         .attr("id", "watchlist-update-link")
+
         .attr("id", isAnonymous ? "anon-update-link" : "watchlist-update-link")
         .attr(
+
         .attr("title", isAnonymous ? "" : tooltip)
          "title", tooltip)
 
 
     );
 
     );
 +
  };
 +
 +
  var checkRecentAnonymousEdits = function() {
 +
    $.getJSON(mw.util.wikiScript("api"), {
 +
      format: "json",
 +
      action: "query",
 +
      list: "recentchanges",
 +
      rcprop: "title|ids|timestamp|comment|user",
 +
      rcanon: true,
 +
      rclimit: 1
 +
    }).done(function(data) {
 +
      if (!data.query || !data.query.recentchanges.length) return;
 +
     
 +
      const anonEdit = data.query.recentchanges[0];
 +
      showNotice(anonEdit, true);
 +
    });
 
   };
 
   };
  
Regel 102: Regel 116:
 
     // 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");
 +
 +
    // Remove any existing anonymous edit notifications
 +
    $("#anon-update-notice, #anon-update-diff, #anon-update-link").remove();
  
 
     // Update the notice
 
     // Update the notice
Regel 108: Regel 125:
 
       aantalEdits = 5;
 
       aantalEdits = 5;
 
     }
 
     }
 +
   
 
     $.getJSON(mw.util.wikiScript("api"), {
 
     $.getJSON(mw.util.wikiScript("api"), {
 
       format: "json",
 
       format: "json",
Regel 127: Regel 145:
 
           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/wiki/" +
 
             encodeURI(pageToWatch.replace(/ /g,"_")) +
 
             encodeURI(pageToWatch.replace(/ /g,"_")) +
 
             '">' +
 
             '">' +
Regel 154: Regel 172:
 
       } 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").remove();
+
         $("#watchlist-update-notice, #watchlist-update-diff, #watchlist-update-link").remove();
        $("#watchlist-update-diff").remove();
 
        $("#watchlist-update-link").remove();
 
 
         if (pageToWatch === currentPageName) {
 
         if (pageToWatch === currentPageName) {
 
           $("#siteNotice").remove();
 
           $("#siteNotice").remove();
 
           showPTWNotice = false;
 
           showPTWNotice = false;
 
         }
 
         }
 +
        // Check for anonymous edits when there are no watchlist updates
 +
        checkRecentAnonymousEdits();
 
       }
 
       }
 
     });
 
     });

Versie van 17 feb 2025 10:22

// Script op basis van [[:en:User:Enterprisey/watchlist-notice.js]] 
// 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, isAnonymous = false) {
    // Stick a notice after the notification count
    $("#pt-notifications-notice").after(
      $("<li>")
        .append(
          $("<a>")
            .text(bewerking.title + " geüpdatet")
            .css({
              "background-color": isAnonymous ? "#bb3333" : "#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:" + (isAnonymous ? "RecentChanges" : "Watchlist"))
            .mouseover(isAnonymous ? null : updateNotice)
        )
        .attr("id", isAnonymous ? "anon-update-notice" : "watchlist-update-notice")
    );

    var commentString = bewerking.comment.replace("/* ", "");
    var bewerkingArray = commentString.split(' */');
    var tooltip = isAnonymous ? '' : ('➝ ' + bewerkingArray[0]);
    if (bewerkingArray[1] && !isAnonymous) {
      tooltip += ': ' + bewerkingArray[1];
    }
    
    var kop = bewerkingArray[0];
    if (kop.substr(0, 22) == 'Nieuw kopje aangemaakt') {
      kop = bewerkingArray[0].substr(24, bewerkingArray[0].length);
    }

    // Add diff link (*)
    $("#pt-mytalk").before(
      $("<li>")
        .append(
          $("<a>")
            .text("*")
            .css({
              color: isAnonymous ? "#bb3333" : "#555555",
              "border-radius": "2px",
              padding: "0.25em 0.45em 0.2em",
              cursor: "pointer",
              "font-weight": "bold",
            })
            .attr(
              "href",
              "https://wikikids.nl/index.php?title=" +
                encodeURI(bewerking.title.replace(/ /g,"_")) +
                "&diff=" +
                bewerking.revid +
                (isAnonymous ? "" : "&volglijstmelder=true")
            )
        )
        .attr("id", isAnonymous ? "anon-update-diff" : "watchlist-update-diff")
        .attr(
          "title",
          bewerking.type + " door " + bewerking.user + " (" + tooltip + ")"
        )
    );

    // Add section link (→)
    $("#pt-mytalk").before(
      $("<li>")
        .append(
          $("<a>")
            .text("→")
            .css({
              color: isAnonymous ? "#bb3333" : "#555555",
              "border-radius": "2px",
              padding: "0.25em 0.45em 0.2em",
              cursor: "pointer",
              "font-weight": "bold",
            })
            .attr(
              "href",
              "https://wikikids.nl/index.php?title=" + 
                encodeURI(bewerking.title.replace(/ /g,"_")) + 
                (kop ? "#" + kop.replace(/ /g,"_") : "")
            )
        )
        .attr("id", isAnonymous ? "anon-update-link" : "watchlist-update-link")
        .attr("title", isAnonymous ? "" : tooltip)
    );
  };

  var checkRecentAnonymousEdits = function() {
    $.getJSON(mw.util.wikiScript("api"), {
      format: "json",
      action: "query",
      list: "recentchanges",
      rcprop: "title|ids|timestamp|comment|user",
      rcanon: true,
      rclimit: 1
    }).done(function(data) {
      if (!data.query || !data.query.recentchanges.length) return;
      
      const anonEdit = data.query.recentchanges[0];
      showNotice(anonEdit, true);
    });
  };

  var updateNotice = function () {
    // Lighten the background color so the user knows we're updating
    $("#watchlist-update-notice a").css("background-color", "#7bff7b");

    // Remove any existing anonymous edit notifications
    $("#anon-update-notice, #anon-update-diff, #anon-update-link").remove();

    // 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/wiki/" +
            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, #watchlist-update-diff, #watchlist-update-link").remove();
        if (pageToWatch === currentPageName) {
          $("#siteNotice").remove();
          showPTWNotice = false;
        }
        // Check for anonymous edits when there are no watchlist updates
        checkRecentAnonymousEdits();
      }
    });
  };

  $(document).ready(function () {
    updateNotice();
    window.setInterval(updateNotice, 120000);
  });
});
Afkomstig van Wikikids , de interactieve Nederlandstalige Internet-encyclopedie voor en door kinderen. "https://wikikids.nl/index.php?title=Gebruiker:Freestyle/vector.js&oldid=920375"