osc_tweets_never_miss

osc首页动弹提醒

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name        osc_tweets_never_miss
// @namespace   http://www.oschina.net/
// @description osc首页动弹提醒
// @include     http://www.oschina.net/
// @version     1.3
// @grant       none
// ==/UserScript==
function notifyTweets(title, body, icon)
{
  // Let's check if the browser supports notifications
  var options =
  {
    body: body,
    icon: icon
  };
  if (!('Notification' in window))
  {
    alert('当前浏览器不支持桌面通知!!');
  } 
  else if (Notification.permission === 'granted')
  {
    // If it's okay let's create a notification
    createNotify(title, options);
  } 
  else if (Notification.permission !== 'denied')
  {
    Notification.requestPermission(function (permission)
    {
      // If the user is okay, let's create a notification
      if (permission === 'granted')
      {
        createNotify(title, options);
      }
    });
  }
}
function createNotify(title, options)
{
  var notification = new Notification(title, options);
  notification.onclick = function (event)
  {
    event.preventDefault();
    notification.close();
  };
}
$(document).on('DOMNodeInserted', '.TopTweets li', function (e)
{
  var user = $(e.target).find('.user a').text();
  var body = $(e.target).find('.log').text();
  var icon = $(e.target).find('.SmallPortrait').attr('src');
  notifyTweets(user, body, icon);
});