调用博主最近登录时间
生活中的HYGGE
Selenium破解学习通倍速限制

Selenium破解学习通倍速限制

hygge
2022-06-18 / 2 评论 / 914 阅读 / 正在检测是否收录...

前言

学习通的某些课程会有限制播放速度的功能,不仅播放器没有倍速的播放选项,甚至你通过代码修改播放器的速度也会被监听从而被重置播放器的速度。
l4j8aj2u.png

js修改

原先尝试过setInterval设置定时器不断的去修改播放器速度,先不说优雅与否,反正是没有用的,每次修改速度,视频都会被暂停,速度也被重置。

后面去油猴找了一个插件参考,扒下来了这段破解倍速的代码:

破解完之后,再去执行$('video')[0].playbackRate = 16,就发现不会被重置倍速了。

应用在Selenium

效果:
l4j983bx.png
原理就是注入上一节提到的Js

# chrome.execute_cdp_cmd会在所有页面加载前进行执行,先于页面自带的Js
# 这段压缩过的Js里有判断Url是否为视频页面的逻辑
chrome.execute_cdp_cmd('Page.addScriptToEvaluateOnNewDocument', {
            'source': 'function hack(){if(typeof videojs!=="undefined"&&typeof Ext!=="undefined"){Ext.define("ans.VideoJs",{override:"ans.VideoJs",constructor:function(b){b=b||{};const e=this;e.addEvents(["seekstart"]);e.mixins.observable.constructor.call(e,b);const c=videojs(b.videojs,e.params2VideoOpt(b.params),function(){});Ext.fly(b.videojs).on("contextmenu",function(f){f.preventDefault()});Ext.fly(b.videojs).on("keydown",function(f){if(f.keyCode===32||f.keyCode===37||f.keyCode===39||f.keyCode===107){f.preventDefault()}});if(c.videoJsResolutionSwitcher){c.on("resolutionchange",function(){const g=c.currentResolution();const f=g.sources?g.sources[0].res:false;Ext.setCookie("resolution",f)})}},})}}if(window.location.href.indexOf("/ananas/modules/video")>-1){try{hack();window.document.addEventListener("readystatechange",hack);window.addEventListener("load",hack)}catch(e){console.error(e.message)}};'})

注意:chrome.execute_script("xxx")的执行是在页面的Js都加载完毕时才会执行,所以使用这个来执行脚本 此处并不适用。

参考

1.Selenium: How to Inject/execute a Javascript in to a Page before loading/executing any other scripts of the page? : https://stackoverflow.com/questions/31354352/selenium-how-to-inject-execute-a-javascript-in-to-a-page-before-loading-executi
2.OCS网课助手: https://github.com/ocsjs/ocsjs

0

评论 (2)

取消
  1. 头像
    作者小弟
      Windows 10 x64 Edition Windows 10 x64 Edition  /  Google Chrome 69.0.3947.100 Google Chrome 69.0.3947.100

    作者老大 V3怎么不能用了

    回复
  2. 头像
    kzkt
      Windows 10 x64 Edition Windows 10 x64 Edition  /  LBrowser 8.0.1.4031 LBrowser 8.0.1.4031

    作者老大,超星tool怎么不能用了

    回复