如何制作类似GreaseMonkey的脚本以在下三分之一中显示不同的页面? [英] How can I craft a GreaseMonkey-like script to show a different page in the lower-third?

查看:148
本文介绍了如何制作类似GreaseMonkey的脚本以在下三分之一中显示不同的页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你看看这个页面,底部有很多空白区域。

If you take a look at this page, there's a lot of white space in the bottom.

我希望使用 Greasemonkey-like 脚本该页面利用了一些空白区域并在那里加载另一个页面(使用类似iFrame的东西)。

I wish to use Greasemonkey-like script on that page, that utilises some of that white space and loads another page there (using something like an iFrame).


  • 我希望在iFrame-type-thing(下三分之一)中加载的URL总是查看亚马逊产品页面指向。

  • 因此,我希望代码能够查看页面,并找到该链接所指向的位置。 (因为这是变化的一点)

  • 我希望iFrame类型的东西在下三分之一。 (它可能是较低的季度,较低的第五......我不是字面意思..!)

  • The URL that I want to be loaded in that iFrame-type-thing (in the lower third) is always whatever View Amazon Product Page is pointing to.
  • So, I want the code to look at the page, and find where that link points to. (As this is the bit that varies)
  • I want the iFrame-type thing to be in the lower-third. (It can be the lower quarter, lower fifth.. I don’t mean that literally..!)

我会<强烈>非常感激如果你能帮助我集思广益。

I would be very grateful if you could help me brainstorm this.

这是适用于 Fluid的Greasekit。应用(这是非常古老的,但我只能使用它)。您可能甚至不需要知道它,因为它与Greasekit非常相似。因此,出于这个问题的目的,你可以假装它。

This is for Greasekit on Fluid.app (which is very old, but I am restricted to using it). You probably don’t even need to know that as it’s very similar to Greasekit. So, for the purposes of this question, you can just pretend it is.

唯一的区别是你不必这样做:

The only difference is you don’t have to to do this bit:

//==UserScript==
//@name        _Displaying an iframe type thing in the lower third
//@include     https://dl.dropboxusercontent.com/u/5546881/*
//@grant       none
// ==/UserScript==



我的回答尝试



My attempt at answer

var findlink  = document.getElementsByTagName('a');
for (var i = 0;i="View Amazon Product Page" ; i++ ) {
link result = findlink.getAttribute('href')

}

$(document.body).append (
'<iframe src=+ link + >'
);


推荐答案


  • 因为你有jQuery可用,使用jQuery选择器获取产品链接。

  • 然后添加iFrame但给它一个id。

  • 使用CSS定位和调整大小。

  • 根据你链接的Dropbox页面的结构,代码看起来像这样:

    The code would look like this, based on the structure of the Dropbox page you linked:

    var prodLinks = $("td.product_description a:contains('View Amazon Product Page')");
    if (prodLinks.length) {
        var iframeSrc = prodLinks[0].href;
        $("body").append ('<iframe id="gmIframe" src="' + iframeSrc + '"></iframe>');
    
        $("#gmIframe").css ( {
            "position":     "absolute",
            "bottom":       "1em",
            "left":         "2em",
            "height":       "30%",
            "width":        "94%",
            "z-index":      "17",
            "background":   "#00FF00"
        } );
    }
    






    警告:



    这仅在满足以下条件中的至少一个条件时才有效:


    Warning:

    This will only work if at least one of the following conditions are met:


    • iframe是同一个域。

    • iframed网站并不禁止跨域框架。 ( www.amazon.co.uk 确实禁止此类框架。)

    • 您使用的浏览器不符合跨性别限制。 Firefox很荣幸,我不知道Fluid是否会这样做。

    • The iframe is same domain.
    • The iframed website doesn't forbid cross-origin framing. (www.amazon.co.uk does forbid such framing.)
    • You are using a browser that doesn't honor the cross-origin restriction. Firefox honors it, I don't know if Fluid does or not.

    这篇关于如何制作类似GreaseMonkey的脚本以在下三分之一中显示不同的页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆