User:Evad37/livenotifications/sandbox.js

(function{function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})({1:[function(require,module,exports){ "use strict";

var _App = _interopRequireDefault(require("./modules/App"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

Promise.all([// Resource loader modules mw.loader.using(['mediawiki.util', 'mediawiki.api', 'mediawiki.Title']), // Page ready $.ready]).then(function {  (0, _App["default"]); });

},{"./modules/App":2}],2:[function(require,module,exports){ "use strict";

Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0;

var _util = require("./util");

var _spinner = _interopRequireDefault(require("./spinner"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

var App = function App { var api = new mw.Api({   ajax: {      headers: {        "Api-User-Agent": "livenotifications/1.0.0" + " ( https://en.wikipedia.org/wiki/User:Evad37/livenotifications )"      }    }  }); var config = mw.config.get(["wgServer"]); var waitTimeMilliseconds = 1000 * 60; var lastCheckedTimestamp = new Date; // Main function for retreiving and displaying notifications

var mainloop = function mainloop { // Only make the request if the window/tab is active (focused) if (document.hasFocus) { return api.get({       "action": "query",        "format": "json",        "formatversion": "2",        "curtimestamp": 1,        "meta": "notifications",        "notfilter": "!read",        "notformat": "model",        "notlimit": "20"      }).then(function (response) {        // Find notifications which are new since the last request        var notifications = (response && response.query && response.query.notifications && response.query.notifications.list || []).filter(function (notification) { return lastCheckedTimestamp < new Date(notification.timestamp.utciso8601); }).forEach(function (notification) { var iconFulllUrl = "https:" + config.wgServer + notification["*"].iconUrl; var readableDate = notification.timestamp.utciso8601.replace("T", " ").replace(/:\d\dZ/, " (UTC)"); var messageDiv = (0, _util.makeElement)("div", null, [(0, _util.makeElement)("span", { height: "30px", style: "float:right; margin:-0.2em -0.2em 0.2em 0.5em" }, "X"), (0, _util.makeElement)("a", { href: notification["*"].links.primary.url, title: notification["*"].links.primary.label, target: "_blank", style: "display:block" }, [(0, _util.makeElement)("img", {           src: iconFulllUrl,            height: "30px",            style: "display:block; float:left; margin:0 0.5em 22em -0.5em; color:#666; font-size:88%"          }), (0, _util.parseHtml)(notification["*"].header), (0, _util.makeElement)("span", {            style: "display: block; color: #666; font-size:88%"          }, readableDate)].flatMap(function (x) {            return x;          }) // Flattening in case parseHtml returns an array )]);         mw.notify(messageDiv, {            autoHide: false          }); }); // Update the last checked timestamp (for the next request)

lastCheckedTimestamp = new Date(response.curtimestamp); })["catch"](function (error, details) { return console.log("[livenotifications] error", {         error: error,          details: details        }); });   }  };

window.setInterval(function {    var loop = mainloop;

if (loop) { _spinner["default"].start;

loop.then(function {        return _spinner["default"].stop;      }); } }, waitTimeMilliseconds); };

var _default = App; exports["default"] = _default;

},{"./spinner":3,"./util":4}],3:[function(require,module,exports){ "use strict";

Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0;

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

var Spinner = /*#__PURE__*/function { function Spinner { _classCallCheck(this, Spinner);

this.badges = document.querySelectorAll(".mw-echo-notifications-badge"); this.minDuration = 3000; // milliseconds }

_createClass(Spinner, [{   key: "start",    value: function start {      this.startTime = new Date;      this.badges.forEach(function (el) { return el.setAttribute("style", "background-image:url(https://upload.wikimedia.org/wikipedia/commons/thumb/7/7a/Ajax_loader_metal_512.gif/20px-Ajax_loader_metal_512.gif)"); });   }  }, {    key: "stop",    value: function stop {      var _this = this;

var timeUsed = new Date - this.startTime; var remainingTime = Math.max(0, this.minDuration - timeUsed); window.setTimeout(function {        return _this.badges.forEach(function (el) { return el.removeAttribute("style"); });     }, remainingTime); } }]);

return Spinner; };

var spinner = new Spinner; var _default = spinner; exports["default"] = _default;

},{}],4:[function(require,module,exports){ "use strict";

Object.defineProperty(exports, "__esModule", { value: true }); exports.parseHtml = exports.makeElement = void 0;

/** * * @param {string} tagName * @param {object} [attributes] * @param {Node|string|Node[]|string[]} [contents] * @returns {HTMLElement} */ var makeElement = function makeElement(tagName, attributes, contents) { var el = document.createElement(tagName);

if (attributes) { for (var prop in attributes) { el.setAttribute(prop, attributes[prop]); } }

if (contents) { (Array.isArray(contents) ? contents : [contents]).forEach(function (content) {     var node = content && content.nodeType ? content : document.createTextNode(content);      el.appendChild(node);    }); }

return el; }; /** * @param {string} htmlString * @return {Node|Node[]} Node or Nodes parsed from HTML */

exports.makeElement = makeElement;

var parseHtml = function parseHtml(htmlString) { var div = document.createElement("div"); div.innerHTML = htmlString; var children = Array.from(div.childNodes); return children.length === 1 ? children[0] : children; };

exports.parseHtml = parseHtml;

},{}]},{},[1]) //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJsaXZlbm90aWZpY2F0aW9ucy1zcmMvaW5kZXguanMiLCJsaXZlbm90aWZpY2F0aW9ucy1zcmMvbW9kdWxlcy9BcHAuanMiLCJsaXZlbm90aWZpY2F0aW9ucy1zcmMvbW9kdWxlcy9zcGlubmVyLmpzIiwibGl2ZW5vdGlmaWNhdGlvbnMtc3JjL21vZHVsZXMvdXRpbC5qcyJdLCJuYW1lcyI6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