Greasy Fork

Greasy Fork is available in English.

Douyu斗鱼 主播开播提醒 (新)

手动打开我的关注页面并放置在后台(https://www.douyu.com/directory/myFollow) 有主播开播时自动发送通知提醒

当前为 2019-09-26 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Douyu斗鱼 主播开播提醒 (新)
// @namespace    http://tampermonkey.net/
// @version      2.0.3
// @description  手动打开我的关注页面并放置在后台(https://www.douyu.com/directory/myFollow)  有主播开播时自动发送通知提醒
// @author       hlc1209, P
// @match        https://www.douyu.com/directory/myFollow
// @grant GM_xmlhttpRequest
// @grant GM_openInTab
// @grant GM_notification
// ==/UserScript==

var baseURL = "https://douyu.com"
var save={}
shim_GM_notification ()


/*--- Cross-browser Shim code follows:
Source: https://stackoverflow.com/questions/36779883/userscript-notifications-work-on-chrome-but-not-firefox
*/
function shim_GM_notification () {
    if (typeof GM_notification === "function") {
        return;
    }
    window.GM_notification = function (ntcOptions) {
        checkPermission ();

        function checkPermission () {
            if (Notification.permission === "granted") {
                fireNotice ();
            }
            else if (Notification.permission === "denied") {
                console.log ("User has denied notifications for this page/site!");
                return;
            }
            else {
                Notification.requestPermission ( function (permission) {
                    console.log ("New permission: ", permission);
                    checkPermission ();
                } );
            }
        }

        function fireNotice () {
            if ( ! ntcOptions.title) {
                console.log ("Title is required for notification");
                return;
            }
            if (ntcOptions.text && !ntcOptions.body) {
                ntcOptions.body = ntcOptions.text;
            }
            var ntfctn = new Notification (ntcOptions.title, ntcOptions);

            if (ntcOptions.onclick) {
                ntfctn.onclick = ntcOptions.onclick;
            }
            if (ntcOptions.timeout) {
                setTimeout ( function() {
                    ntfctn.close ();
                }, ntcOptions.timeout);
            }
        }
    }
}

function append_notify(res){
    var status;
    for(var each in res.data.list){
        status=res.data.list[each]["show_status"]
        console.log("!!!!");
        console.log (baseURL+res.data.list[each]["url"]);
        if (!(each in save)){
            save[each] = status;
            continue
        }else if (save[each]==status){
            continue
        }
        save[each]=status
        console.log("!!!!");
        console.log(res.data.list[each]["nickname"]);
        if (status==1){
            var notificationDetails = function(){
                var tempUrl = res.data.list[each]["url"]
                return {
                    text:       '点击通知快速传送',
                    title:      res.data.list[each]["nickname"]+'开播了',
                    image:      res.data.list[each]["avatar_small"],
                    //timeout:    60000,
                    onclick:    function () {
                        console.log ("Notice clicked.");
                        GM_openInTab(baseURL+tempUrl, false);
                        //window.focus ();
                    }
                }
            }()
            GM_notification (notificationDetails)
        }
    }
    console.log ('Follow rooms check is successful');
}

function check(){
    console.log ('Interval Check Running.');
    GM_xmlhttpRequest({
        method: 'GET',
        url: `https://www.douyu.com/wgapi/livenc/liveweb/follow/list?sort=0&cid1=0`,
        onload: response => {
            var res=JSON.parse(response.responseText)
            append_notify(res)
        }
    });
}

check()
function notifyTitle(s){
    GM_notification ({
        text:       "斗鱼开播提醒",
        title:      s,
        timeout:    1800,
        image: "https://img.douyucdn.cn/data/yuba/admin/2018/08/13/201808131555573522222945055.jpg?i=31805464339f469e0d3f992e565e261803",
        onclick:    function () {
                        console.log ("Notice clicked.");
                        GM_openInTab("https://www.douyu.com", false);
                        //window.focus ();
                    }
    })
}
notifyTitle('斗鱼开播提醒启动了')
//window.onbeforeunload = function(event){notifyTitle('开播提醒已退出')}
//window.onunload = function(event) {notifyTitle('斗鱼开播提醒已退出')}
window.setInterval(check,10000)