Item Guide Image URL Fixer

fix old broken item image URLs

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name     Item Guide Image URL Fixer
// @description fix old broken item image URLs
// @version  1.0.0
// @match		 https://www.gaiaonline.com/forum/compose/entry/new/*
// @match		 https://www.gaiaonline.com/forum/compose/entry/*_*/
// @grant    none
// @namespace https://greasyfork.org/users/2263
// ==/UserScript==

var oldDomain = /gaia.hs.llnwd.net\/e1/g;
var curDomain = 'graphics.gaiaonline.com';
var buttons = document.querySelector('.form_buttons');
var button = document.createElement('button');
button.type = 'button';
button.className = 'cta-button-sm';
button.innerHTML = '<span>Fix broken item image URLs</span>';
button.addEventListener('click', urlFixer);
buttons.insertBefore(document.createTextNode("\n"), buttons.children[0]);
buttons.insertBefore(button, buttons.childNodes[0]);

function urlFixer(evt) {
  var textarea = document.querySelector('#message');
  var text = textarea.value;
  
  var count = (text.match(oldDomain) || []).length;
  text = text.replace(oldDomain, curDomain);
  
  alert(`Replaced: ${count} domains`)
  
  textarea.value = text;
}