HF Replacer

Replace a word by another

Від 18.06.2015. Дивіться остання версія.

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 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.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

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        HF Replacer
// @namespace   HF
// @description Replace a word by another
// @include     http://www.hackforums.net/*
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js
// @version     1
// @grant       GM_getValue
// @grant       GM_setValue
// @grant       GM_deleteValue
// ==/UserScript==

var customText = GM_getValue('customText', '');
var send = GM_getValue('send', 'false');

function saveSettings() {
  if (document.getElementById('charCount').innerHTML >= 25) { 
    GM_setValue('customText', document.getElementById('valueTextReplacer').value)
    if (document.getElementById('checkSendAuto').checked) {
      GM_setValue('send', true);
    } else {
      GM_setValue('send', false);
    }
    document.getElementById('submitReplacer').innerHTML = "Changes saved";
  } else { alert('You don\'t have more than 25 characters. Please correct and submit again.'); }
}
exportFunction(saveSettings, unsafeWindow, {defineAs: "saveSettings"});

function insertText() {
  var prevMessage = document.getElementById("message").value;
  document.getElementById('message').value = prevMessage + customText;
  if (send) { document.getElementById('quick_reply_submit').click() }
}
exportFunction(insertText, unsafeWindow, {defineAs: "insertText"});

if (document.URL.indexOf("usercp.php") >= 0) {
  var settingsHTML = "<table class='tborder' cellspacing='1' cellpadding='4' border='0'><tbody><tr><td class='thead' colspan='2'><strong> HF Replacer : Settings</strong></td></tr><tr><td class='trow1'>Text : <input type='text' id='valueTextReplacer' value='" + customText + "'></input>(<span id='charCount'></span>/25) <input id='checkSendAuto' type='checkbox'><label for='checkSendAuto'>Send automatically the message ?</label></input> <button class='button' onclick='saveSettings()'><span id='submitReplacer'>Save</span></button></td></tr></table><br />";
  $('.quick_keys > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2) > br:nth-child(2)').after(settingsHTML);
  document.getElementById('charCount').innerHTML = $('#valueTextReplacer').val().length;
  $('#valueTextReplacer').on('keyup', function() {
    document.getElementById('charCount').innerHTML = $('#valueTextReplacer').val().length;
  });
  if (send) { document.getElementById('checkSendAuto').setAttribute('checked', 'checked'); }
}

if (document.URL.indexOf("showthread.php") >= 0) {
  var bLocation = document.querySelectorAll('#quickreply_e > tr:nth-child(2) > td:nth-child(1)');
  var button = document.createElement('a');
  button.appendChild(document.createTextNode('Custom Text'));
  button.setAttribute('title', 'Custom Text');
  button.setAttribute('onClick', 'insertText()');
  button.setAttribute('class', 'button');
  bLocation[0].appendChild(button);
}