简体   繁体   English

加载网页后,我想更改此页面中的任何链接

[英]When a web page is loaded I want to change any link in this page

As I mentioned in the title, I'm looking for any script or extension that will be able to do this. 正如标题中所述,我正在寻找能够执行此操作的任何脚本或扩展。

In my country, imgur has been blocked and I don't want to use VPN, I am using 0imgur.com to view any images. 在我的国家/地区,imgur被禁止,并且我不想使用VPN,我使用0imgur.com来查看任何图像。 But it doesn't work on webpages. 但这不适用于网页。 So When a webpage is loaded, I want that it changes this URLs automatically. 因此,当加载网页时,我希望它自动更改此URL。 Like this: 像这样:

  • Page loads: 页面加载:
    页面加载
  • And
  • If it exits, an extension changes all " imgur.com/{image-id} " urls to " 0imgur.com/{image-id} ": 如果退出,则扩展名会将所有“ imgur.com/{image-id}”URL更改为“ 0imgur.com/{image-id}”:
    如果退出,则扩展名会将所有“ imgur.com/{image-id}”网址更改为“ 0imgur.com/{image-id}”

I have solved my problem. 我已经解决了我的问题。 Thank you for all answers and comments. 感谢您的所有回答和评论。

    $(document).ready(function() {
        $('img').each(function() {
            var $img = $(this);
            var imgsrc = $img.attr('src');
            var imgalt = $img.attr('alt');
            var newresult = imgsrc.split(".");
            newresult[1] = "0"+newresult[1];
            var finalUrl = newresult.join(".");
            console.log(finalUrl); 
            $img.attr('src',finalUrl);
            $img.attr('alt',imgalt);
        });
    });

I have combined codes what you give in the answers. 我将您在答案中给出的代码组合在一起。

And I have added this code to my bookmarks as javascript. 而且我已将此代码以javascript的形式添加到了我的书签中。

javascript:(

    <!-- codes -- >
    <!-- codes -- >

)()

The function below would enable you achieve that 以下功能可让您实现

let replaceUrl = ()=>{
 let imgElements = Array.from(document.getElementsByTagName("img"))
 if ( imgElements.length  > 0 ){
   imgElements.each(elem){
     elem.src = elem.src.replace("imgur", "Oimgur")
   }
 }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM