2

我正在编写这个小书签(它应该从 youtube 视频的页面启动,但如果从不同的页面启动它仍然应该显示错误消息):

http://www.summarify.com/ytlyrics/bookmarklet/

它仍在进行中,但同时在 Mozilla/Chrome 中它运行良好,在 Internet Explorer 中它没有做任何事情,甚至调试器也没有显示任何东西,就像我根本没有触发小书签一样

这是书签代码:

<a href="javascript:(function(){var localpath = 'http://www.summarify.com/ytlyrics/';   ;if(window.myBookmarklet!==undefined){myBookmarklet();}else{document.body.appendChild(document.createElement('script')).src=localpath + 'bookmarklet/bookmarklet.js';}})();">MostraYoutubeLyrics</a>

这是外部javascript:

(function(){

    var localpath = 'http://www.summarify.com/ytlyrics/';   

    /*prima esecuzione*/
    if(window.myBookmarklet===undefined) {



        //carico il css esterno
        var fileref=document.createElement("link")
        fileref.setAttribute("rel", "stylesheet")
        fileref.setAttribute("type", "text/css")
        fileref.setAttribute("href", localpath + "bookmarklet/bookmarklet.css");

        document.getElementsByTagName("head")[0].appendChild(fileref);

        //devo caricare jquery o c'è già nella pagina?
        //da togliere se su youtube c'è già

        // the minimum version of jQuery we want
        var v = "1.9.1";

        // check prior inclusion and version
        if (window.jQuery === undefined || window.jQuery.fn.jquery < v) {
            var done = false;
            var script = document.createElement("script");
            script.src = "http://ajax.googleapis.com/ajax/libs/jquery/" + v + "/jquery.min.js";
            script.onload = script.onreadystatechange = function(){
                if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
                    done = true;
                    initialization();
                }
            };

            document.getElementsByTagName("head")[0].appendChild(script);

        } 
        else {      
            alert("init senza loading jquery")
            initialization();

        }
    }
    /*else { /*esecuzioni successive alla prima 

        fetchContentBookMarklet();

    }*/

    function initialization() {

        var script = document.createElement("script");
        script.src = "http://yui.yahooapis.com/3.8.0/build/yui/yui-min.js";                 
        document.getElementsByTagName("head")[0].appendChild(script);


        /*var script2 = document.createElement("script");
        script2.src = "http://code.jquery.com/ui/1.10.3/jquery-ui.js";                  
        document.getElementsByTagName("head")[0].appendChild(script2);

        script2.onload = function() { */


            /*inizializzazione grafica */
            var newDiv = $('<div id="bookmarklet_yt_container" class="bookmarklet_yt">');
            $('body').append(newDiv);

//          $( "#bookmarklet_yt_container" ).draggable();

            var header_bookmarklet_div = "<h1>YoutubePlugin <span id='bookmarklet_yt_button'>[ close ]</span></h1>";
            header_bookmarklet_div += "<div id='bookmarklet_yt_content'></div>";
            header_bookmarklet_div +="<div class=\"small\"><a href=\"http://www.summarify.com/ytlyricsbookmarklet\" target=\"_blank\">Credits</a></div>";


                $('#bookmarklet_yt_container').html(header_bookmarklet_div);


                $('#bookmarklet_yt_button').click(function() { 


                      $("#bookmarklet_yt_container").hide();


                });

            fetchContentBookMarklet();


        //}

    }

    function fetchContentBookMarklet() {
        (window.myBookmarklet = function() {

            $("#bookmarklet_yt_container").show();
            $('#bookmarklet_yt_content').html("loading...");

            var stringa_title = document.title;

            /*tentativo di separare con una regex artista da titolo */

            var youtube_details = stringa_title.split("-");

            var artist = youtube_details[0];
            var title = youtube_details[1];


                var script = document.createElement("script");
                script.src = "http://lyrics.wikia.com/api.php?fmt=json&artist=" + encodeURIComponent(artist) +"&song=" + encodeURIComponent(title);
                script.onload = function() {



                    var full_lyrics = "";


                    if(false)
                        $('#bookmarklet_yt_content').html("not found. so something");
                    else {

                        YUI().use('node', 'event', 'yql', function(Y) {

                        var yql_query = "select * from html where url='" + song.url +"'";
                        yql_query += " and xpath=\"//div[@class='lyricbox']\"";

                        Y.YQL(yql_query, function(response) {

                            var message_header = "<p>Lyrics for <strong>" + title + "</strong> played by <strong>" +artist +"</strong></p>";

                          if(response.query.results){

                            $('#bookmarklet_yt_content').html(message_header + "<br/>" +response.query.results.div.p.content.split(' \n ').join('<br />'));
                      } else{



                        $('#bookmarklet_yt_content').html(message_header + "not found");

                          }



                        });

                    });     


                    }






                }
                document.getElementsByTagName("head")[0].appendChild(script);




        })();
    }

})();

我在 Internet 上做了一些研究,但是关于 Bookmarklet 在 IE 上的工作方式与在其他常见浏览器上的工作方式不同的讨论并不多

4

0 回答 0