技巧阳光网络课堂助手

Posted hsy-2019

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了技巧阳光网络课堂助手相关的知识,希望对你有一定的参考价值。

这是一个辅助阳光网络课堂的油猴脚本,目前最新的版本是 v1.1,已经实现的功能有:

  1. 实时显示在线人数和在线管理员名单;
  2. 聊天区显示消息发送的时间;
  3. 增加高级输入框,可以发送带换行的消息、发送图片以及对指定用户私聊。

使用方法:

  1. 打开油猴官网,选择你使用的浏览器对应的版本下载并安装;
  2. 点击油猴并选择「添加新脚本...」,在弹出的页面把下面的代码复制进去并保存;
  3. 重新打开阳光网络课堂直播间,脚本将会运行。

代码:

// ==UserScript==
// @name         阳光网络课堂助手
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  一些实用或不实用的小东西
// @author       yurzhang
// @include      https://view.csslcloud.net/api/view/index*
// @grant        none
// ==/UserScript==

var userList = new Array();

(function() {
    ‘use strict‘;
    window.on_cc_live_chat_msgs = function on_cc_live_chat_msgs(datas) {
        var cmhtml = ‘‘
        var barrageList = []
        var chats = datas
        $.each(datas, function (index, data) {
            if (!isWithGroup(data)) { return; }
            var barrageInfo = $.trim(data.msg);
            var reg = new RegExp(/[img_http(s)?://(.*?)]/g);
            if (reg.test(barrageInfo)) {
                //barrageInfo = ‘‘;
            } else {
                if (data.status === ‘0‘)
                    barrageList.push(barrageInfo);
            } cmHtml += Template.chatMsg({
                admin: data.userrole == ‘publisher‘ || data.userrole == ‘teacher‘ || data.userrole == ‘host‘,
                name: ‘[‘ + data.time + ‘] ‘ + data.username,
                content: showEm(data.msg),
                id: data.userid,
                chatId: data.chatId,
                status: data.status,
                isFromMe: Viewer.isMe(data.userid)
            });
        });
        if ($(‘#barrage‘).val() == 1)
            $.DW.barrageList(JSON.stringify({barrageInfo: barrageList}));
        $(‘#chat-list‘).append(cmHtml);
        var rc = $(‘#chat-list‘).children().length - 500 + datas.length;
        if (rc > 0)
            $(‘#chat-list> li:lt(‘ + rc + ‘)‘).remove();
        var uid = $(‘.select-current‘).attr(‘id‘);
        if (uid != ‘all‘ && $(‘.viewall‘).hasClass(‘viewall-active‘)) {
            $(‘#chat-list li‘).hide();
            $(‘#chat-list li[uid="‘ + uid + ‘"]‘).show();
            $(‘.c-chat‘).hide();
            $(‘.pchat span‘).hide();
            $(‘.pchat .name-from‘).show();
            $(‘.name-from‘).removeClass(‘name-tip‘);
        } chatScroll();
    }
    var tmp=document.createElement(‘span‘);
    tmp.id="count";
    $(".lmb-r-tools")[0].append("在线人数:");
    $(".lmb-r-tools")[0].append(tmp);
    $(".lmb-r-tools")[0].append("人 | 在线管理员:");
    tmp=document.createElement(‘span‘);
    tmp.id="adm";
    $(".lmb-r-tools")[0].append(tmp);
    var opts = {
        roomId: $(‘#roomId‘).val(),
        viewer: { sessionId: $.cookie(‘sessionid‘) },
        chat: {
            host: $(‘#chatHost‘).val(),
            spareHost: $(‘#backupChatHost‘).val()
        }
    };
    var params = {
        sessionid: opts.viewer.sessionId,
        platform: 1,
        terminal: 0
    };
    if (window.location.protocol === ‘https:‘)
        params.secure = true;
    var host = opts.chat.host;
    var spareHost = opts.chat.spareHost;
    var socket = io.connect(SocketUtils.getConnectURI(host, opts.roomId), { query: params });
    new SocketSentinel(socket, SocketUtils.getConnectURI(spareHost, opts.roomId));
    socket.on(‘room_teachers‘, function (data) {
        data=JSON.parse(data);
        var qwq=‘‘;
        for(var i=0;i!=data.teachers.length;++i)
            qwq+=data.teachers[i].name+‘(‘+data.teachers[i].ip+‘) ‘;
        if(qwq==‘‘) qwq=‘无‘
        var nw=$(‘#adm‘)[0];
        nw.innerHTML=qwq;
    });
    socket.on(‘chat_message‘, function (data) {
        data=JSON.parse(data);
        userList[data.userid]=data.username;
    });
    var rlblk = document.createElement(‘div‘);
    rlblk.setAttribute(‘style‘,‘display:none;‘);
    rlblk.innerHTML=‘<form><table><tr><td><textarea wrap="virtual" style="width:400px;height:200px;resize:none;" required></textarea></td></tr><tr><td>发送对象(留空对所有人发送):<input type="text" id="tous" style="width:190px;"></td></tr><tr><td><div style="text-align:center"><button type="button" onclick="sd()">发送文本</button><span style="display:inline-block;width:60px;"></span><button type="button" onclick="sdpc()">发送图片</button></div></td></tr></table></form>‘;
    var hr = document.createElement(‘div‘);
    hr.setAttribute(‘id‘,‘here‘);
    $(‘body‘).append(hr);
    var chat_btn = document.createElement(‘a‘);
    chat_btn.setAttribute(‘id‘,‘clk‘);
    chat_btn.innerHTML=‘[高级输入框]‘;
    chat_btn.onclick = function() {
        hr.append(createdialog(418,340,rlblk,"高级输入框",true));
    }
    $(‘.chat-title‘)[0].children[0].append(chat_btn);
    window.sd = function() {
        if($(‘#tous‘).val()==‘‘) $.DW.sendChat($(‘textarea‘).val());
        else {
            var ton;
            if(userList[$(‘#tous‘).val()]!==undefined)
                ton=userList[$(‘#tous‘).val()]
            else ton=‘未知用户‘;
            $.DW.sendPrivateChat($(‘textarea‘).val(),0,$(‘#tous‘).val(),ton);
        }
        $(‘textarea‘).val(‘‘);
    }
    window.sdpc = function() {
        if($(‘#tous‘).val()==‘‘) $.DW.sendChat(‘[img_‘+$(‘textarea‘).val()+‘]‘);
        else {
            var ton;
            if(userList[$(‘#tous‘).val()]!==undefined)
                ton=userList[$(‘#tous‘).val()]
            else ton=‘未知用户‘;
            $.DW.sendPrivateChat(‘[img_‘+$(‘textarea‘).val()+‘]‘,‘‘,$(‘#tous‘).val(),ton);
        }
        $(‘textarea‘).val(‘‘);
    }
})();

var opblk = false;
function createdialog(width, height, bodycontent, title, removeable) {
    if(opblk) {
        alert(‘你已经打开了高级输入框!‘);
        return;
    } opblk = true;
    var dialog = document.createElement("div");
    var dialogtitlebar= document.createElement("div");
    var dialogbody = document.createElement("div");
    var dialogtitle = document.createElement("span");
    var dialogclose = document.createElement("span");
    var closeaction = document.createElement("button");
    dialog.id = "yurzhang";
    dialogtitle.innerHTML = title;
    dialogtitlebar.appendChild(dialogtitle);
    dialogtitlebar.appendChild(dialogclose);
    dialogclose.appendChild(closeaction);
    if(bodycontent!=null) {
        bodycontent.style.display = "block";
        dialogbody.appendChild(bodycontent);
    } dialog.appendChild(dialogtitlebar);
    dialog.appendChild(dialogbody);
    var templeft,temptop,tempheight;
    var dialogcssText,dialogbodycssText;
    templeft = (document.body.clientWidth-width)/2;
    temptop = (document.body.clientHeight-height)/2;
    tempheight= height-30;
    dialogcssText= "z-index:666;position:absolute;background:#65c294;padding:1px;border:4px;top:"+temptop+"px;left:"+templeft+"px;height:"+height+"px;width:"+width+"px;";
    dialogbodycssText = "width:100%;background:#ffffff;"+"height:" + tempheight + "px;";
    dialog.style.cssText = dialogcssText;
    dialogtitlebar.style.cssText = "height:30px;width:100%;cursor:move;";
    dialogbody.style.cssText  = dialogbodycssText;
    dialogtitle.style.cssText = "font-size:16px;float:left;display:block;margin:4px;line-height:20px;";
    dialogclose.style.cssText  = "float:right;display:block;margin:4px;line-height:20px;";
    closeaction.style.cssText = "background-color:red;height:20px;width:24px;border-width:1px;cursor:pointer;";
    var dialogleft = parseInt(dialog.style.left);
    var dialogtop = parseInt(dialog.style.top);
    var ismousedown = false;
    closeaction.onclick = function() {
        opblk = false;
        dialog.parentNode.removeChild(dialog);
    }
    if(removeable == true) {
        var ismousedown = false;
        var dialogleft,dialogtop;
        var downX,downY;
        dialogleft = parseInt(dialog.style.left);
        dialogtop = parseInt(dialog.style.top);
        dialogtitlebar.onmousedown = function(e) {
            ismousedown = true;
            downX = e.clientX;
            downY = e.clientY;
        }
        document.onmousemove = function(e) {
            if(ismousedown){
                dialog.style.top = e.clientY - downY + dialogtop + "px";
                dialog.style.left = e.clientX - downX + dialogleft + "px";
            }
        }
        document.onmouseup = function() {
            dialogleft = parseInt(dialog.style.left);
            dialogtop = parseInt(dialog.style.top);
            ismousedown = false;
        }
    } return dialog;
}

以上是关于技巧阳光网络课堂助手的主要内容,如果未能解决你的问题,请参考以下文章

java 阳光偏好片段第2部分

Android课程---Android Studio使用小技巧:提取方法代码片段

VS2015使用技巧 打开代码片段C#部分

26个jQuery代码片段使用技巧

vc++2010设置和c#一样的代码段,vs2010 两下tab设置

VS中添加自定义代码片段——偷懒小技巧