Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/429.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Greasemonkey将链接、图像替换为图像?_Javascript_Html_Firefox_Hyperlink_Greasemonkey - Fatal编程技术网

Javascript 使用Greasemonkey将链接、图像替换为图像?

Javascript 使用Greasemonkey将链接、图像替换为图像?,javascript,html,firefox,hyperlink,greasemonkey,Javascript,Html,Firefox,Hyperlink,Greasemonkey,我是Greasemonkey的新手,我想用 我在网上搜索,找到了类似的东西。 但是,我编辑的代码: <a target="_blank" href="http://url.com/pic.gif">http://url.com/pic.gif</a> var i,x=document.evaluate( '//*[@target=“_blank”][@href=“=”]”, 文件, 无效的 XPathResult.UNORDERED\节点\快照\类型, 无效的 );

我是Greasemonkey的新手,我想用


我在网上搜索,找到了类似的东西。
但是,我编辑的代码:

<a target="_blank" href="http://url.com/pic.gif">http://url.com/pic.gif</a>
var i,x=document.evaluate(
'//*[@target=“_blank”][@href=“=”]”,
文件,
无效的
XPathResult.UNORDERED\节点\快照\类型,
无效的
);
对于(i=0;i
似乎不起作用


请告知我应该如何创建此脚本。

替换图像链接并不难。但是,我建议您保留链接,但在其中显示图片。这样,如果出现问题,您就可以点击查看。例如,大多数链接图像都位于死区

其他链接的图像看起来只是指向图像,或者可能会因“热链接”而被阻止

为了使代码健壮和简单,我们使用和

下面是一个完整的工作脚本,它将有效负载图像链接从以下位置断开:

/==UserScript==
//@name\u图像去链接器
//@包括http://forums.hardwarezone.com.sg/*
//@需要http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
//@需要https://gist.github.com/raw/2625891/waitForKeyElements.js
//@grant GM_addStyle
//==/UserScript==
var imageExtensions=[“gif”、“png”、“jpg”、“jpeg”];
var imgExtRegex=new RegExp(
“\\”(“+imageExtensions.join(“|”)+“)$”,“i”
);
/*--调整每个站点的CSS路径,以仅查找可以访问的链接
你关心的图像链接。
*/
//--forums.hardwarezone.com.sg
WaitForkEyements(“td.page div>a”,脱钩图像);
函数去链接图像(jNode){
var imgUrl=jNode.attr(“href”);
if(imgExtRegex.test(imgUrl)){
//--找到图像链接。请替换内容。
jNode.html(
''
);
}
}
GM_addStyle(“\
img.gmDeLinked{\
边框:1px固体石灰\
最大宽度:90vw\
}                                           \
" );

替换图像链接并不难。但是,我建议您保留链接,但在其中显示图片。这样,如果出现问题,您就可以点击查看。例如,大多数链接图像都位于死区

其他链接的图像看起来只是指向图像,或者可能会因“热链接”而被阻止

为了使代码健壮和简单,我们使用和

下面是一个完整的工作脚本,它将有效负载图像链接从以下位置断开:

/==UserScript==
//@name\u图像去链接器
//@包括http://forums.hardwarezone.com.sg/*
//@需要http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
//@需要https://gist.github.com/raw/2625891/waitForKeyElements.js
//@grant GM_addStyle
//==/UserScript==
var imageExtensions=[“gif”、“png”、“jpg”、“jpeg”];
var imgExtRegex=new RegExp(
“\\”(“+imageExtensions.join(“|”)+“)$”,“i”
);
/*--调整每个站点的CSS路径,以仅查找可以访问的链接
你关心的图像链接。
*/
//--forums.hardwarezone.com.sg
WaitForkEyements(“td.page div>a”,脱钩图像);
函数去链接图像(jNode){
var imgUrl=jNode.attr(“href”);
if(imgExtRegex.test(imgUrl)){
//--找到图像链接。请替换内容。
jNode.html(
''
);
}
}
GM_addStyle(“\
img.gmDeLinked{\
边框:1px固体石灰\
最大宽度:90vw\
}                                           \
" );

您可以完全按照使用常规html和javascript的方式进行操作。我不知道如何更改。您需要付出更多的努力。至少给我们当前的HTML代码段和所需的HTML代码段。指向目标页面的链接也会非常有用。例如,此页面显示所有带有图像的超链接,我检查了它使用的源代码,例如url.com/pic.gif">http://www.url.com/pic.gif . 我想用img src来代替它。我试着从网上进行研究,并设法找到类似的东西。我编辑的代码如下,似乎不起作用:var i,x=document.evaluate('/*[@target=“\u blank”][@href=“=”]”,document,null,XPathResult.UNORDERED\u NODE\u SNAPSHOT\u TYPE,null);对于(i=0;ihttp://www.url.com/pic.gif . 我想用img src来代替它。我试着从网上进行研究,并设法找到类似的东西。我编辑的代码如下,似乎不起作用:var i,x=document.evaluate('/*[@target=“\u blank”][@href=“=”]”,document,null,XPathResult.UNORDERED\u NODE\u SNAPSHOT\u TYPE,null);对于(i=0;i<img src="http://url.com/pic.gif">
var i, x = document.evaluate (
    '//*[@target="_blank"][@href="="]',
    document,
    null,
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
    null
);
for (i = 0; i < x.snapshotLength; i++)
    x.snapshotItem(i).setAttribute("href", "img src");
// ==UserScript==
// @name    _Image delinker
// @include http://forums.hardwarezone.com.sg/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant   GM_addStyle
// ==/UserScript==

var imageExtensions = ["gif", "png", "jpg", "jpeg"];
var imgExtRegex     = new RegExp(
    '\\.(' + imageExtensions.join ('|') + ')$', 'i'
);

/*-- Tune the CSS path, for each site, to only find links that can be
    the image links you care about.
*/
//-- For forums.hardwarezone.com.sg
waitForKeyElements ("td.page div > a", delinkImage);

function delinkImage (jNode) {
    var imgUrl  = jNode.attr ("href");

    if (imgExtRegex.test (imgUrl) ) {
        //-- Found an image link.  Replace contents.
        jNode.html (
            '<img src="' + imgUrl
            + '" class="gmDeLinked" alt="GM replaced image">'
        );
    }
}

GM_addStyle ( "                                 \
    img.gmDeLinked {                            \
        border:             1px solid lime;     \
        max-width:          90vw;               \
    }                                           \
" );