Item Guide Image URL Fixer

fix old broken item image URLs

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==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;
}