WOT 书签

发布于 2024-08-14 05:19:39 字数 948 浏览 8 评论 0原文

我正在尝试编写一个小书签,以便查看 Web Of Trust (WOT) 的评级在访问页面上的所有链接之前。虽然 WOT 提供了自己的书签,但它不是很有用,因为您需要先访问该页面才能查看评级。这将在 SeaMonkey 上使用,所以我也不能只安装 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,但它根本没有执行任何操作。有什么办法可以让它发挥作用吗?

I'm trying to write a bookmarklet that will allow me to view the Web Of Trust (WOT) ratings for all the links on a page before visiting them. While WOT provides their own bookmarklet, it is not very useful since you need to visit the page first before viewing the rating. This will be used on SeaMonkey, so I can't just install the WOT extension, either.

WOT has a Javascript API that allows you to activate the ratings on any page it is included in, so I am using that as a base. However, it never seems to work correctly as a bookmarklet. Here's one attempt where I tried to keep the code as close to the API as possible. I only modified the wotinject function so that it would work in a bookmarklet and added a timeout so that the rating widget wouldn't be loaded before 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"));

I can see the APIs being loaded in the status bar, but it doesn't do anything at all. Is there any way to get this working?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独﹏钓一江月 2024-08-21 05:19:39

我不确定这是否能回答您的问题,但我在生产中使用了一个加载 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();

I'm not sure if this answers your question, but I use a bookmarklet in production that loads jQuery. This code works fine for me:

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文