图片链接转换

错误图片链接转换

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         图片链接转换
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  错误图片链接转换
// @author       You
// @match         http*://hggard.com/*
// @connect      hggard.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    let imgs = document.getElementsByTagName('img');
    for(var img of imgs ){
        if(/static\.gmgard\.com/.test(img.src)){
            img.src = img.src.replace(/static\.gmgard\.com/,'static.hggard.com') ;
        }

        if(img.attributes['data-src'] && /static\.gmgard\.com/.test(img.attributes['data-src'].nodeValue)){
            img.attributes['data-src'].nodeValue = img.attributes['data-src'].nodeValue.replace(/static\.gmgard\.com/,'static.hggard.com') ;
        }
    }

    let alink = document.getElementsByTagName('a');
    for(var link of alink ){
        if(/static\.gmgard\.com/.test(link.href) && link.hasAttribute('data-img-href')){
            link.href = link.href.replace(/static\.gmgard\.com/,'static.hggard.com') ;
        }
    }


    // Your code here...
})();