Gab.ai Mentions Notifications

Additional notifications count just for mentions.

目前為 2016-11-14 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Gab.ai Mentions Notifications
// @namespace    https://www.ekkooff.com/
// @version      0.2
// @description  Additional notifications count just for mentions.
// @author       Kevin Roberts (@echo)
// @match        https://gab.ai/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    window.addEventListener('load',function() {
      var mentions = $('<span id="notificationmentions" style="background:#5a2;left:120px;" class="hidden">0</span>');
      $('.notification-count').append(mentions);

      var reset = function() {
          mentions.text('0');
          mentions.addClass('hidden');
      };

      var oldXHR = window.XMLHttpRequest;
      function newXHR() {
          var realXHR = new oldXHR();
          realXHR.addEventListener("readystatechange", function() {
              if(realXHR.readyState==4 && realXHR.status==200){
                  if(realXHR.responseURL.startsWith('https://gab.ai/api/notifications')) {
                      reset();
                  }
              }
          }, false);
          return realXHR;
      }
      window.XMLHttpRequest = newXHR;

      Pusher.instances[0].bind_all(function(eventName,data) {
        if(data.message && data.message.endsWith("mentioned you in a post.")) {
          var count = parseInt(mentions.text());
          count++;
          mentions.text(count);
          mentions.removeClass('hidden');
        }
      });
    },false);
})();