2009-12-05 96 views
0

我正在尝试编写一个小书签,允许我在访问页面之前查看页面上所有链接的Web Of Trust (WOT)评分。虽然WOT提供了他们自己的书签,但它并不是非常有用,因为您在查看评分前需要先访问该页面。这将在SeaMonkey上使用,所以我也不能只安装WOT扩展。WOT书签

WOT有一个Javascript API,它允许您激活它所包含的任何页面上的评级,所以我使用它作为基础。但是,它似乎永远不能像书签一样正常工作。这里有一个尝试让代码尽可能接近API的尝试。我只修改了wotinject函数,以便它可以在小书签中工作并添加超时,以便在jQuery之前不会加载评分小部件。

var wotprotocol = (document.location.protocol == "https:") ? "https://" : "http://"; 
var wotbase = wotprotocol + "api.mywot.com/widgets"; 
var wotinject = function(src) { 
    document.body.appendChild(document.createElement("script")).src = wotbase + "/" + src + ".js"; 
}; 
var wotjquery = typeof(jQuery) != "undefined"; 
if (!wotjquery) { 
    wotinject("jquery"); 
} 
void(window.setTimeout(wotinject, 200, "ratingwidget")); 

我可以看到在状态栏中加载的API,但它什么也没有做。有什么办法可以使这个工作?

+0

您是否考虑过创建一个黄油猴插件?您可以始终加载它,并可以使用跨站点xhr,这可能对您有所帮助 – mkoryak 2010-03-18 20:04:01

回答

-1

我不确定这是否回答您的问题,但我在加载jQuery的生产中使用了小书签。此代码适用于我:

load = function() { 
    load.getScript("http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"); 
    // do stuff when jQuery finishes loading. 
    load.tryReady(0); 
} 
load.getScript = function(filename) { 
    var fileref = document.createElement('script'); 
    fileref.setAttribute("type","text/javascript"); 
    fileref.setAttribute("src", filename); 
    if (typeof fileref!="undefined") 
     document.getElementsByTagName("head")[0].appendChild(fileref); 
} 
load.tryReady = function(time_elapsed) { 
    /* Continually polls for jQuery library. */ 
    if (typeof $ == "undefined") { 
     if (time_elapsed <= 5000) { 
      setTimeout("load.tryReady(" + (time_elapsed + 200) + ")", 200); 
     } else { 
      alert("Timed out while loading jQuery."); 
     } 
    } else { 
     /************ JQUERY IS NOW LOADED, PUT CODE HERE ****************/ 
    } 
} 
load();