HF Replacer

Replace a word by another

2015-06-18 기준 버전입니다. 최신 버전을 확인하세요.

이 스크립트를 설치하려면 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);
}