NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name xsstudy学习脚本 // @namespace http://tampermonkey.net/ // @version 0.3 // @description try to take over the world! // @author You // @match http://www.xsstudy.gov.cn/nbstudy/* // @grant none // @require https://code.jquery.com/jquery-latest.js // ==/UserScript== /* 更新日志 v0.1 首版 v0.2 加入进度显示(百分比)优化代码 v0.3 进度条显示优化 */ (function() { window.intervalId = 0; window.learnLessonId = 0; function Lesson(id,node){ this.id = id; this.node =node; this.title = getCourseTitle(id); //题目 this.lastTime = getsTime(id)*60; //已获学时(分钟) this.duration = getCourseRlen(id); //时长(分钟) //this.duration =this.node.getElementsByTagName("script")[0].innerHTML.slice(9,-1); // 从 <script>min2hour(99.0)</script>之类的网页元素中获取时长 //进度条设定 this.progress = document.createElement('td'); if (this.duration > 0){ this.progress.innerHTML = (this.lastTime/this.duration*100).toFixed(2) + "%"; } else{ this.progress.innerHTML = '<td>0.00%</td>'; } this.progress.id = "pro" + this.id; this.node.appendChild(this.progress); //播放按钮设定 this.palyButton = document.createElement('td'); this.node.appendChild(this.palyButton); this.palyButton.innerHTML = '<button>▶</button>'; this.palyButton.id = "button" + this.id; var _this = this; this.palyButton.onclick = function(){ //如果有视频在播放中, if (window.learnLessonId !== 0){ //判断点击对象是否正在播放,如果是,则暂停,如果不是则暂停正在播放视频,开始播放新视频 if (_this.id === window.learnLessonId){ this.innerHTML = '<button>▶</button>'; clearInterval(window.intervalId); window.learnLessonId = 0; } else{ var button = document.getElementById("button" + learnLessonId ); button.innerHTML = '<button>▶</button>'; this.innerHTML = '<button>||</button>'; window.learnLessonId = _this.id; } } else{ //如果未播放任何视频,点击一下则开始 this.innerHTML = '<button>||</button>'; window.learnLessonId = _this.id; window.intervalId = setInterval(function (){ $.ajax({ type: "POST", url: '/nbstudy/player.ww?rid=0&cid='+ learnLessonId + '&classid=WX&lastPlayTime=0&'+Math.round(Math.random()*999999999), data: '', success: function(msg){ if(msg.indexOf("success")<0){ console.log("计时错误,请稍后(1小时)再学"); } else{ var label = document.getElementById("pro" + learnLessonId ); _this.lastTime++; label.innerHTML = ((_this.lastTime/_this.duration)*100).toFixed(2) + "%"; console.log("正常学习课程ID号" + learnLessonId); console.log("已持续" +_this.lastTime + "分钟"); console.log("总时长" +_this.duration + "分钟"); } }}); },60000); } }; } function main(){ var a = $('[id^=js_exetend]'); var lesson = []; for (var i = 0; i< a.length; i++){ var node = a[i].parentNode.parentNode.parentNode; var classId = a[i].id.slice(11); lesson[i] = new Lesson(classId,node); } } main(); })();