• 播放MMS 的 Greasemonkey 脚本


    本来打算写成 Firefox 的扩展,奈何一直拖延,毕竟需要学习的东西太多。之前有用过基于 Greasemokey 的自动化订火车票脚本,一直都想学习一下。

    其实,脚本并不复杂,主要包含HTML内容过滤和URL处理。


    1 提取mms链接,需要用 XPATH 定位到 PARAM 元素,包含 URL 属性。

    网页中的代码示例

    <OBJECT id=nstv codeBase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701standby=Loading type=application/x-oleobject height=60 width=300 classid=CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6 components... Player Media? Windows Microsoft?><PARAM NAME="URL" VALUE="mms://media.chinabroadcast.cn/eng/music/morning/2012/1123a.wma"><PARAM NAME="rate" VALUE="1"><PARAM NAME="balance" VALUE="0"><PARAM NAME="currentPosition" VALUE="0"><PARAM NAME="defaultFrame" VALUE=""><PARAM NAME="playCount" VALUE="1"><PARAM NAME="autoStart" VALUE="0"><PARAM NAME="currentMarker" VALUE="0"><PARAM NAME="invokeURLs" VALUE="-1"><PARAM NAME="baseURL" VALUE=""><PARAM NAME="volume" VALUE="50"><PARAM NAME="mute" VALUE="0"><PARAM NAME="uiMode" VALUE="full"><PARAM NAME="stretchToFit" VALUE="0"><PARAM NAME="windowlessVideo" VALUE="0"><PARAM NAME="enabled" VALUE="-1"><PARAM NAME="enableContextMenu" VALUE="0"><PARAM NAME="fullScreen" VALUE="0"><PARAM NAME="SAMIStyle" VALUE=""><PARAM NAME="SAMILang" VALUE=""><PARAM NAME="SAMIFilename" VALUE=""><PARAM NAME="captioningID" VALUE=""><PARAM NAME="enableErrorDialogs" VALUE="0"><PARAM NAME="_cx" VALUE="7938"><PARAM NAME="_cy" VALUE="1588"></OBJECT>
    

    提取代码如下

    var allLinks, thisLink;
    allLinks = document.evaluate(
    	'//PARAM[@NAME="URL"]',
    	document,
    	null,
    	XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
    	null);
    if (allLinks.snapshotLength > 0) {
    //for (var i = 0; i < allLinks.snapshotLength; i++) {
    	thisLink = allLinks.snapshotItem(0);
    	//alert(thisLink.getAttribute('VALUE'));
    	window.open(thisLink.getAttribute('VALUE'), '_self');
    //}
    }
    

    2 可以添加弹出播放的按钮

    var myHaxMenu = document.createElement("div");
    myHaxMenu.innerHTML = '<style type="text/css">'
    +'<!--'
    +'#myhaxlayer #table1 a {'
    +'text-decoration: none !important;'
    +'color: #000000 !important;'
    +'font-family: Verdana, Arial, Helvetica, sans-serif !important;'
    +'font-size: 10px !important;'
    +'font-weight: bold !important;'
    +'font-style: normal !important;'
    +'}'
    +'#myhaxlayer #table1 a:hover {'
    +'text-decoration: none !important;'
    +'color: #0000FF !important;'
    +'font-family: Verdana, Arial, Helvetica, sans-serif !important;'
    +'font-size: 10px !important;'
    +'font-weight: bold !important;'
    +'font-style: normal !important;'
    +'}'
    +'#myhaxlayer #table1 {'
    +'background-color: #CCCCCC !important;'
    +'}'
    +'textarea.CommentBox {'
    +'150px;'
    +'height:50px;'
    +'padding:5px;'
    +'color:FFFFFF;'
    +'font-size:8pt;'
    +'font-family:Verdana;'
    +'border-color:959385;'
    +'border-style:solid;'
    +'background-color:333333;'
    +'}'
    +'input.SubmitButton {'
    +'150px;'
    +'padding:0px;'
    +'background-color:d5d2c2;'
    +'border-color:a6a498;'
    +'border-style:solid;'
    +'border-1;'
    +'}'
    +'-->'
    +'</style>'
    +'<script>'
    +'function open_mms(seg) {'
    +'  window.open(seg);'
    +'}'
    +'</script>'
    +'<div style="position: fixed;  200px; height: 100px; z-index: 100; right; top: 0pt; left: 0pt" id="myhaxlayer">'
    +'<table border="0" width="100%" id="table1" bgcolor="#C0C0C0">'
    +'<tr><td><p align="left">'
    +'<input type="button" value="Part 1" onclick="window.open(\'' + allLinks.snapshotItem(0).getAttribute('VALUE') + '\', \'_self\')" />'
    +'<input type="button" value="Part 2" onclick="window.open(\'' + allLinks.snapshotItem(1).getAttribute('VALUE') + '\', \'_self\')" />'
    +'<input type="button" value="Part 3" onclick="window.open(\'' + allLinks.snapshotItem(2).getAttribute('VALUE') + '\', \'_self\')" />'
    +'</td></tr></table></div>'
    document.body.insertBefore(myHaxMenu, document.body.firstChild);
    

     不过后来 easyfm 网页又添加了弹出播放按钮,不用再进行处理了。

  • 相关阅读:
    积分第一中值定理
    History of mathematics(19th century)
    使用多项式解决矩阵问题
    菊与刀
    Mathematics during the Scientific Revolution(18th century)
    摄动
    Cauchy中值定理
    Leetcode3---Longest Substring Without Repeating Characters
    Leetcode2---Add Two Numbers
    矩形覆盖
  • 原文地址:https://www.cnblogs.com/huys03/p/2743871.html
Copyright © 2020-2023  润新知