Greasy Fork

Greasy Fork is available in English.

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