| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 694 人关注过本帖
标题:一个脚本的修改
取消只看楼主 加入收藏
nm85
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2009-8-25
收藏
 问题点数:0 回复次数:0 
一个脚本的修改
先说一下,我不懂js,只是一个普通用户,由于个人原因需要经常在youtube上面大量下载视频,为了方便下载了一个greasemonkey(firefox的一个插件)脚本,可以在youtube页面上显示下载链接,如图

" border="0" />

自己想修改这个脚本让他能显示3gp的连接,以及在下载链接处显示视频标题而不是类似于“[OK]....”
这样就能用flashget的“智能命名”功能一键获得视频名称并下载,不用再选中,复制,粘贴视频名称了,可以节省大量时间
经过几个小时摸索,3gp的问题解决了,显示标题的问题实在没可能……

所以我想请问各位如何在下载链接处显示视频标题而不是类似于“[OK]....”的文字???
比如图中那个视频网址是
http://www.
标题是
Justin Timberlake In-Studio Introduction

如果这个实现起来比较困难,直接显示网页的标题也行,即网页源代码中的<title>部分,YouTube - Justin Timberlake In-Studio Introduction

您的几分钟,或许能让我节省几十个小时。谢谢各位了!!!



原始代码如下
程序代码:
// ==UserScript==
// @name           YouTube HD Suite
// @namespace      http:// @description    Always watching or downloading the highest quality format (HD or MP4) in YouTube Page
// @include        http://*.*
// @include        http://*
// ==/UserScript==

(function() {

    var w = (typeof(unsafeWindow) != 'undefined') ? unsafeWindow : window;
    var d = w.document;
    var l = w.location;
    var s = w.swfArgs;

    /**
     * Redirect Higher Quality URL
     */
    function redirect() {
        var map = decodeURIComponent(s['fmt_url_map']);
        if ( map.indexOf('22|') > -1 ) {
            l.replace(l.href + '&fmt=22');
        }
        else if ( map.indexOf('35|') > -1 ) {
            l.replace(l.href + '&fmt=35');
        }
        else {
            l.replace(l.href + '&fmt=18');
        }
    }
    
    /**
     * create Menu
     */
    function createMenu() {
        if ( !d.getElementById('masthead-nav-main') ) return;
    
        var a = d.createElement('a');
        a.setAttribute('onmouseover','document.getElementById(\'suite_menu\').style.display=\'block\';');
        a.setAttribute('onmouseout','document.getElementById(\'suite_menu\').style.display=\'none\';');
        a.setAttribute('id','suite_button');
        a.style.color = '#F00';
        a.style.display = 'inline-block';
        a.innerHTML = 'Suite';
        d.getElementById('masthead-nav-main').appendChild(a);

        // menu position
        var menuW = a.offsetWidth;
        var menuH = a.offsetHeight;
        var menuT = 0, menuL = 0;
        do {
            menuT += a.offsetTop  || 0;
            menuL += a.offsetLeft || 0;
            a = a.offsetParent;
        } while (a);
        //w.console.log(menuW+'/'+menuH+'/'+menuT+'/'+menuL);

        var div = d.createElement('div');
        div.setAttribute('id','suite_menu');
        div.setAttribute('onmouseover','this.style.display=\'block\';');
        div.setAttribute('onmouseout','this.style.display=\'none\';');
        div.style.display = 'none';
        div.style.margin = 0;
        div.style.padding = '7px';
        div.style.background = '#EEE';
        div.style.border = '3px solid #999';
        div.style.position = 'absolute';
        div.style.top    = (menuT+menuH)+'px';
        div.style.left   = (menuL)+'px';
        div.style.zIndex = '99';
        div.innerHTML
            = '<b>YouTube HD Suite</b> | '
            + '<a href="javascript:visualize();">[ Visualize ]</a>';
        d.getElementsByTagName('body')[0].appendChild(div);
    }
    
    /**
     * create XmlHttpRequest
     */
    function createXHR() {
        if ( w.ActiveXObject ) {
            try {
                return new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    return new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e2) {
                    return null;
                }
            }
        } else if ( w.XMLHttpRequest ) {
            return new XMLHttpRequest();
        } else {
            return null;
        }
    }

    /**
     * check URL
     */
    function checkURL(video_id) {
        var url = '';
        if ( video_id.match(/.+==$/) ) {
            url = 'http://'+l.host+'/cthru?key='+video_id;
        } else {
            url = 'http://'+l.host+'/watch' + '?v='+video_id;
        }
        var XHR = createXHR();
        XHR.open( 'GET', url, true );
        XHR.onreadystatechange = function() { 
            if (XHR.readyState==4) {
                if ( match = XHR.responseText.match(/var swfArgs = ({.*})/) ) {
                    var json = eval('('+RegExp.$1+')');
                    var map = decodeURIComponent(json['fmt_url_map']);
                    var s = d.getElementsByTagName('strong');
                    for ( var i=0; i<s.length; i++ ) {
                        if ( !s[i].innerHTML && s[i].getAttribute('class') == json['video_id'] ) {
                            link = d.createElement('a');
                            link.style.color   = '#fff';
                            link.style.font    = 'bold 10px/10px Arial';
                            link.style.padding = '1px';
                            if ( map.indexOf('22|') > -1 ) {
                                link.style.backgroundColor = '#f00';
                                link.href      = '/get_video?fmt=22&video_id='+json['video_id']+'&t='+json['t'];
                                link.innerHTML = 'HD';
                                if ( s[i].nextSibling.href && !s[i].nextSibling.href.match(/#$/) ) {
                                    s[i].nextSibling.href += "&fmt=22";
                                }
                            }
                            else if ( map.indexOf('35|') > -1 ) {
                                link.style.backgroundColor = '#6f6';
                                link.href      = '/get_video?fmt=35&video_id='+json['video_id']+'&t='+json['t'];
                                link.innerHTML = 'HQ';
                                if ( s[i].nextSibling.href && !s[i].nextSibling.href.match(/#$/) ) {
                                    s[i].nextSibling.href += "&fmt=35";
                                }
                            }
                            else {
                                link.style.backgroundColor = '#666';
                                link.href      = '/get_video?fmt=18&video_id='+json['video_id']+'&t='+json['t'];
                                link.innerHTML = 'SD';
                                if ( s[i].nextSibling.href && !s[i].nextSibling.href.match(/#$/) ) {
                                    s[i].nextSibling.href += "&fmt=18";
                                }
                            }
                            s[i].appendChild(link);
                        }
                    }
                }
            }
        }
        XHR.send('');
    }

    /**
     * Add HD or MP4 on each links in YouTube List Page
     */
    w.visualize = function() {
        var a = d.getElementsByTagName('a');
        for ( var i=0; i<a.length; i++ ) {
            match = '';
            if ( a[i].innerHTML.match(/<img/i) )             continue; // Skip Image Link
            if ( a[i].getAttribute('vid') )                  continue; // Skip checked Link
            if ( a[i].getAttribute('class') == 'yt-button' ) continue; // Skip Button Link
            // functional links
            if ( a[i].href.match(/#$/) ) {
                if ( a[i].getAttribute('onclick') &&
                     ( a[i].getAttribute('onclick').match(/^onPlayVideos\(\['([a-zA-Z0-9_-]*)'\]\)/) ||
                       a[i].getAttribute('onclick').match(/^onPlayVideos\('\/watch\?v=([a-zA-Z0-9_-]*)'\)/) )
                ) {
                    match = RegExp.$1;
                    a[i].setAttribute('vid',1);
                    strong = d.createElement('strong');
                    strong.setAttribute('class',match);
                    a[i].parentNode.insertBefore(strong, a[i]);
                    a[i].style.display = 'inline';
                } else {
                    continue;
                }
            }
            // normal 'watch' and 'play list'
            else if ( a[i].href.match(/watch\?v=([a-zA-Z0-9_-]*)/) || a[i].href.match(/view_play_list\?.+&v=([a-zA-Z0-9_-]*)/) ) {
                match = RegExp.$1;
                a[i].setAttribute('vid',1);
                strong = d.createElement('strong');
                strong.setAttribute('class',match);
                a[i].parentNode.insertBefore(strong, a[i]);
            }
            // new channel page
            else if ( !a[i].href && a[i].getAttribute('onclick') && a[i].getAttribute('onclick').match(/playnav.playVideo\(\'.+\',\'[0-9]\',\'([a-zA-Z0-9_-]*)\'\);/) ) {
                match = RegExp.$1;
                a[i].setAttribute('vid',1);
                strong = d.createElement('strong');
                strong.setAttribute('class',match);
                a[i].parentNode.insertBefore(strong, a[i]);
            }

        }
        
        var s = d.getElementsByTagName('strong');
        
        var c = '';
        for ( var i=0; i<s.length; i++ ) {
            if ( !s[i].innerHTML && s[i].getAttribute('class') && c.indexOf(s[i].getAttribute('class')) < 0 ) {
                c += ' ' + s[i].getAttribute('class');
                checkURL( s[i].getAttribute('class') );
            }
        }
    }
    
    /**
     * check HD(fmt=22)
     */
    function checkHD() {
        var url = 'http://'+l.host+'/watch' + '?v='+s['video_id'];
        var XHR = createXHR();
        XHR.open( 'GET', url, true );
        XHR.onreadystatechange = function() { 
            if (XHR.readyState==4) {
                if ( match = XHR.responseText.match(/var swfArgs = ({.*})/) ) {
                    var block = d.getElementById('check_fmt_22');
                    block.innerHTML = '';
                    var json = eval('('+RegExp.$1+')');
                    var map = decodeURIComponent(json['fmt_url_map']);
                    if ( map.indexOf('22|') > -1 ) {
                        block.innerHTML
                            += '<a href="'+makeDownloadURL(22)+'">[OK] DL fmt=22 ( HD /MP4/H.264/AAC)</a>';
                    } else {
                        block.innerHTML
                            += '[NG] DL fmt=22 ( HD /MP4/H.264/AAC)';
                    }
                }
            }
        }
        XHR.send('');
    }

    /**
     * check HQ(fmt=35)
     */
    function checkHQ() {
        var url = 'http://'+l.host+'/watch' + '?fmt=35&v='+s['video_id'];
        var XHR = createXHR();
        XHR.open( 'GET', url, true );
        XHR.onreadystatechange = function() { 
            if (XHR.readyState==4) {
                if ( match = XHR.responseText.match(/var swfArgs = ({.*})/) ) {
                    var block = d.getElementById('check_fmt_35');
                    block.innerHTML = '';
                    var json = eval('('+RegExp.$1+')');
                    var map = decodeURIComponent(json['fmt_url_map']);
                    if ( map.indexOf('35|') > -1 ) {
                        block.innerHTML
                            += '<a href="'+makeDownloadURL(35)+'">[OK] DL fmt=35 ( HQ /FLV/H.264/AAC)</a>';
                    } else {
                        block.innerHTML
                            += '[NG] DL fmt=35 ( HQ /FLV/H.264/AAC)';
                    }
                }
            }
        }
        XHR.send('');
    }

    /**
     * Make Download URL
     */
    function makeDownloadURL(num) {
        var u = 'http://'+l.host+'/get_video' + '?video_id='+s['video_id'] + '&t=' + s['t'];
        if ( num ) {
            u += '&fmt='+num;
        }
        return u;
    }

    /**
     * Add Customized Embed Link
     */
    function showCopyLink() {
        var map = decodeURIComponent(s['fmt_url_map']);
        if( map.indexOf('22|') > -1 ) {
            i = 22;
            m = 'High Definition';
        }
        else if( map.indexOf('35|') > -1 ) {
            i = 35;
            m = 'High Quality FLV';
        } else {
            i = 18;
            m = 'for iPod';
        }
        url_command
            = 'prompt('
            + '\'Copy & Past the '+m+' URL\','
            + 'document.getElementById(\'watch-url-field\').value+\'&fmt='+i+'\''
            + ');'
            + 'void(0);';
        embed_command
            = 'prompt('
            + '\'Copy & Past the '+m+' embed tag\','
            + 'document.getElementById(\'embed_code\').value.replace(/(http:\\/\\/[a-zA-Z0_-]*\\.youtube\\.com\\/[-_.a-zA-Z0-9\\/?&=%]+)/g,\'$1&ap=%252526fmt%253D'+i+'\')'
            + ');'
            + 'void(0);';
        // Create Links Block
        d.getElementById('watch-url-div').innerHTML
            += '<div id="URL-YT-video" style="text-align:right;padding-right:30px;">'
            +  '<a href="javascript:'+url_command+'">[ Highest-Quality-URL ]</a>'
            +  '</div>';
        d.getElementById('watch-embed-div').innerHTML
            += '<div id="EMBED-YT-video" style="text-align:right;padding-right:30px;">'
            +  '<a href="javascript:'+embed_command+'">[ Highest-Quality-Embed ]</a>'
            +  '</div>';
    }
    
    /**
     * Add HD or MP4 Download Links
     */
    function showDownloadLinks() {
        if( !d.getElementById('YHS-DL-div') ) {
            // Create Links Block
            d.getElementById('watch-embed-div').innerHTML
                += '<div id="YHS-DL-div">'
                +  '<div id="check_fmt_22">checking fmt=22</div>'
                +  '<div id="check_fmt_35">checking fmt=35</div>'
                +  '<div><a href="'+makeDownloadURL(18)+'">[OK] DL fmt=18 ( iPod /MP4/H.264/AAC)</a></div>'
                +  '<div><a href="'+makeDownloadURL()+'">[OK] DL normal ( LQ /FLV/H.263/MP3)</a></div>'
                +  '</div>';
            checkHD();
            checkHQ();
        }
    }

    /* add eventLister for cross browser */
    function _AddEventListener(e, type, fn) {
        if (e.addEventListener) {
            e.addEventListener(type, fn, false);
        }
        else {
            e.attachEvent('on' + type, function() {
                fn(window.event);
            });
        }
    }

    /**
     * Controller
     */
    // Watching Page
    if ( l.pathname.match(/\/watch/) ) {
        // always watch in Highest Quality
        if ( !l.search.match(/fmt=[0-9]*/) ) {
            redirect();
        } else {
            showCopyLink();
            showDownloadLinks();
            createMenu();
            w.visualize();
        }
    }
    // Other Page (Top, Browse, seache, ...)
    else {
        // for Auto Pager
        var scrollHeight = d.documentElement.scrollHeight;
        _AddEventListener(
            w,
            "scroll",
            function(e){
                if(d.documentElement.scrollHeight - scrollHeight > 100){
                    scrollHeight = d.documentElement.scrollHeight;
                    w.visualize();
                }
            }
        );
        createMenu();
        w.visualize();
    }

})();
搜索更多相关主题的帖子: 脚本 修改 Greasemonkey 
2009-08-25 17:51
快速回复:一个脚本的修改
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.040158 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved