HF Replacer

Replace a word by another

От 18.06.2015. Виж последната версия.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да инсталирате разширение, като например Tampermonkey .

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

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