我如何制作一个类似GreaseMonkey的脚本,在下三分之一显示不同的页面

How can I craft a GreaseMonkey-like script to show a different page in the lower-third?

本文关键字:脚本 三分之一 显示 GreaseMonkey 何制作 一个      更新时间:2023-09-26

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

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

  • 我想加载到iFrame类型的东西中的URL(在下三分之一)总是View Amazon Product Page所指向的
  • 因此,我希望代码查看页面,并找到链接指向的位置
  • 我希望iFrame类型的东西在下三分之一。(可以是下四分之一,下五分之一……我不是字面意思……!)

如果你能帮我集思广益,我将非常感激。

可选读数

它不是GreaseMonkey,但你可以假设它是

这是Fluid.app上的Greasekit(它很旧,但我只能使用它)。你可能根本不需要知道,因为它与Greasekit非常相似。所以,为了这个问题的目的,你可以假装它是

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

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

我试图回答

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页面的结构,代码看起来是这样的:

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"
    } );
}

警告:

只有在至少满足以下条件之一的情况下,这才会起作用:

  • iframe是同一个域
  • iframed网站并不禁止跨来源框架。(www.amazon.co.uk禁止此类取景。)
  • 您使用的浏览器不遵守跨原点限制。Firefox尊重它,我不知道Fluid是否尊重它