How to replace image links with img src url in Greasemonkey

丶灬走出姿态 提交于 2019-12-02 05:17:41
Amjad Masad

img tags cant have href, however you can append them into an anchor tag with href attribute:

for(var iImage=0;iImage<document.images.length;iImage++){
    var imageUrl = document.images[iImage].src;

    if (imageUrl.indexOf("thumbnails") != -1) {
        imageUrl = imageUrl.replace("thumbnails","images");
        document.images[iImage].outerHTML = '<a href ="' +
                              + imageUrl + '" >' 
                              + document.images[iImage].outerHTML + '</a>';

    }
}

Psuedo-code:

var thumblinks=new Array();
for(x=0;x<links.length;x++){
    if(links[x].href.test('thumbnails'))thumblinks[thunblinks.length]=links[x];
}
for(x=0;x<thumblinks.length;x++){
    thumblinks[x].href=thumblinks[x].firstChild.src;
}

Does this work?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!